Skip to content

Recaptcha enterprise - #46

Open
SupraSummus wants to merge 4 commits into
llybin:masterfrom
EE:recaptcha-enterprise
Open

SupraSummus wants to merge 4 commits into
llybin:masterfrom
EE:recaptcha-enterprise

Conversation

@SupraSummus

Copy link
Copy Markdown

#11

SupraSummus and others added 4 commits August 13, 2026 10:12
Closes llybin#11.

Verify tokens by creating an assessment with the reCAPTCHA Enterprise
API instead of the siteverify endpoint. The request is authenticated
with a Google Cloud API key passed in the query string, so no extra
dependency is needed.

- `ReCaptchaEnterpriseField` reuses the score resolution and the secret
  key priority of the other fields, the secret key holds the API key.
- The project id and the site key come from the new settings
  `DRF_RECAPTCHA_ENTERPRISE_PROJECT_ID` and
  `DRF_RECAPTCHA_ENTERPRISE_SITE_KEY` or from the field arguments, the
  endpoint from `DRF_RECAPTCHA_ENTERPRISE_DOMAIN`.
- `action` is optional, checkbox site keys are not bound to an action,
  so the expected action is only sent and checked when it is defined.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019FoKGHdiqxUogdQVtUyAd1
A field was built out of settings, so a project deploying without a
credential could not start at all: `ReCaptchaEnterpriseField` raised
`ImproperlyConfigured` for a blank project id or site key while the
serializer module was still importing, and the system check raised Error
on a blank secret key, which fails every management command that runs
checks, `migrate` in a release phase included. With no id on that
message `SILENCED_SYSTEM_CHECKS` could not reach it either, leaving no
way to deploy without credentials but to feed the settings a placeholder
that verifies nothing, and then keep it out of an HTTP request by hand.

Credentials are read when a field validates instead.

- A deployment missing one starts, and serves everything the captcha
  does not guard. The fields refuse the submissions they protect,
  because the alternative is accepting tokens nobody verified, and log
  which setting is missing while telling the submitter only that their
  token was not checked.
- The check reports the same settings at startup as a warning carrying
  an id. Enterprise's project id and site key had no startup validation
  at all before, only the crash on import; defining either of them is
  what asks for them, even when defined empty, because that is what a
  deployment reading unset environment variables ends up with and the
  case worth reporting.
- Building a field touches no setting, so nothing captures a credential
  before settings finish loading, and `override_settings` reaches a
  field declared at import time.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C7MCFZaqitJWX2XeG3igST
The Ruff workflow installs the latest ruff, which now flags rules the
pinned 0.13.0 dev dependency did not: PLR0917 on the six-argument
submit_enterprise, ISC004 on the implicitly concatenated error strings in
the validator parametrize tables, and Python code blocks inside README.md,
which ruff format now reformats.

submit_enterprise becomes keyword-only rather than carrying another noqa:
every call site already passes keywords, and the function is new in the
unreleased Enterprise work, so nothing external can be calling it
positionally.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0171yDhL8wgvM4sr71n4iFXS
`HTTPError` was caught and logged with `logger.exception` and no body, so every
rejected verification request reported as `HTTP Error 400: Bad Request` and the
reason was discarded at the one point it was still readable — `HTTPError` is a
file object, and nothing downstream can go back for it.

The Enterprise API makes that expensive. It answers a site key belonging to
another project, a project the API key cannot use, and an API nobody enabled with
the same status line, naming the difference only in the body: the first is a bad
paste, the second a key from the wrong project, the third a console setting, and
the alert distinguished none of them.

The submitter's message is unchanged — whose configuration is wrong is not
theirs to know, and a retry may well work.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0181nt4yaQqya1hGzxWnxGDu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants