Contact: captcha-regio (global/eu) in de token-response en frame-src voor de StrictSite-CSP (CMS-U9 vervolg)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 23:11:07 +01:00
co-authored by Claude Sonnet 5.5
parent 3275092401
commit 5378c21799
15 changed files with 291 additions and 34 deletions
@@ -6,3 +6,8 @@
- Tests (new): verifier (request shape, EU URL, all answers, timeout, network error, cancellation, empty token, no secrets in logs), options validation, submission rule, pipeline with a fake provider (token response shape, spam vs genuine identical 202, missing token, fail-open 500/503/401, label with `& ' " < >`, start-up refusal), mail label encoding, ASF host tests (closed by default, public routes reachable while the gate is closed, per-client vs shared bucket, committed defaults), frontend label test.
- NOT included (instruction): the `frame-src` CSP catalogue change (`AllowedSiteFrameOrigins`), parked as a patch; see handoff section 8 for the provider's CSP requirement.
- Deviation found against the plan: the v2 widget needs `frame-src` (iframes); the "no frame-src" assumption was wrong. Also `sitekey_invalid` is HTTP 400 (not 401/403).
## Follow-up (owner decisions)
- `frame-src` catalogue change committed: `SecurityHeaders:AllowedSiteFrameOrigins` (exact origins; StrictSite only; empty = byte-identical). 6 new Core tests (Core 645).
- Region: `Contact:Captcha:Region` = `global` (default) | `eu`; token response `captcha` gains `apiEndpoint` (additive); VerifyUrl derived from the region, an explicit VerifyUrl must match it, an unknown region or a mismatch stops the host at start-up. Tests: options (default, eu, mismatches, unknown), pipeline (default global, eu, mismatch refuses to start), OpenAPI regenerated. Contact tests 313.
- Privacy documented for both regions (handoff section 8).
@@ -117,7 +117,7 @@ Rebased onto `origin/master` `e671078` (merge of PR #11: identity-email-notifica
## 8. CMS-U9 additions (Friendly Captcha v2 and the ASF host)
### Captcha contract (no wire change)
- `GET /contact-messages/token` -> `captcha: null` while off, otherwise `{ "provider": "friendlycaptcha", "siteKey": "<public site key>" }`. Nothing else about the captcha (API key, verify URL) is ever returned.
- `GET /contact-messages/token` -> `captcha: null` while off, otherwise `{ "provider": "friendlycaptcha", "siteKey": "<public site key>", "apiEndpoint": "global" | "eu" }`. `apiEndpoint` (additive, default `global`) is the widget's data region and follows `Contact:Captcha:Region`, so switching region needs no website rebuild. Nothing else about the captcha (API key, verify URL) is ever returned.
- `POST /contact-messages`: `captchaToken` = the widget's response string (the widget also puts it in the form field `frc-captcha-response`). While the captcha is on, a **missing, empty or rejected** value is treated as spam: answer `202 {"status":"received"}` identical to a genuine message, stored with status `spam` (never a 400, so a bot learns nothing). While the captcha is off the field is ignored.
- Verify (server side, Friendly Captcha **v2**): `POST https://global.frcapi.com/api/v2/captcha/siteverify` (EU-only: `https://eu.frcapi.com/api/v2/captcha/siteverify`), header `X-API-Key: <API key>`, JSON `{ "response": "...", "sitekey": "..." }`; `success:true` passes, `success:false` (HTTP 200 `response_invalid|response_timeout|response_duplicate`, or 400 `response_missing|bad_request`) = spam. Checked against developer.friendlycaptcha.com on 2026-11-10.
- **Fail-open**: timeout (default 3 s), network error and 5xx let the visitor through (warning `captcha_unavailable`, kind only). Our own wrong API key or site key (HTTP 401, or 400 with `error_code: sitekey_invalid`) also lets the visitor through but logs an **error** `captcha_misconfigured`. The response token, the API key and the site key are never logged.
@@ -129,15 +129,16 @@ Rebased onto `origin/master` `e671078` (merge of PR #11: identity-email-notifica
| `Contact:Captcha:Provider` | `friendlycaptcha` (only supported value; case-insensitive) |
| `Contact:Captcha:SiteKey` | public; sent to the browser |
| `Contact__Captcha__Secret` | the API key; **environment variable / secrets manager only**, never committed |
| `Contact:Captcha:VerifyUrl` | default global v2 URL; use the EU URL above for EU-only processing; must be https |
| `Contact:Captcha:Region` | `global` (default) or `eu`; decides the verify host and the `apiEndpoint` announced to the widget. Unknown value = host refuses to start |
| `Contact:Captcha:VerifyUrl` | optional override, normally empty (derived from Region); if set it must be https **and match the Region's host** (`global.frcapi.com` / `eu.frcapi.com`), otherwise the host refuses to start |
| `Contact:Captcha:TimeoutSeconds` | default 3 (1-30) |
With `Contact:Enabled=true` and `Captcha:Enabled=true` the host **refuses to start** when provider, site key or secret is missing/invalid (the message names the setting only, never a value).
### Widget (website session) and CSP
- Widget: Friendly Captcha v2 SDK with `sitekey` = `siteKey` from the token response; for the EU endpoint the widget needs `apiEndpoint: "eu"` (`data-api-endpoint="eu"`). The response goes into `captchaToken`. Exact SDK package/events: to be verified by the website session against the SDK docs.
- **CSP**: the v2 widget renders in iframes. The provider's CSP guide says you need `frame-src https://*.frcapi.com` (global and EU). `StrictSite` currently has no `frame-src` (iframes fall back to `default-src 'self'` and are blocked). The additive catalogue change `SecurityHeaders:AllowedSiteFrameOrigins` (StrictSite only, absent = header byte-identical) is **prepared but NOT included in this unit**; waiting for the owner's decision on exact origins vs wildcard and on global vs EU. No `connect-src`/`script-src` additions are documented by the provider.
- Privacy (provider statements, v2 docs): "Friendly Captcha does not rely on user tracking or cookies for its protection service"; the dedicated EU endpoint is "hosted in Germany" and "personal information (i.e. visitor IP addresses) never leave the EU". The site's privacy page must name the captcha provider and the processing of the visitor's IP address for the challenge.
- **CSP** (decision: exact origins, no wildcard): the v2 widget renders in iframes and the provider's CSP guide requires `frame-src` for `*.frcapi.com`. New option `SecurityHeaders:AllowedSiteFrameOrigins` (StrictSite only; empty = header byte-identical to before; origins only, validated at start-up; the admin and relaxed policies never get it). ASF value for now: `SecurityHeaders__AllowedSiteFrameOrigins__0=https://global.frcapi.com`; add `https://eu.frcapi.com` as `__1` when the site switches to the EU region. The resulting directive is `frame-src 'self' https://global.frcapi.com`. No `connect-src`/`script-src` additions are documented by the provider; a browser test with the real widget is still needed.
- Privacy (provider statements, v2 docs): "Friendly Captcha does not rely on user tracking or cookies for its protection service". **Region `global`**: the visitor's IP address can be processed outside the EU. **Region `eu`** (dedicated endpoint "hosted in Germany"; paid Advanced/Enterprise plan): "personal information (i.e. visitor IP addresses) never leave the EU". The site's privacy page must name the captcha provider, the processing of the visitor's IP address for the challenge, and which region is in use; commercial use needs a paid plan with the provider. For a test or a launch without a paid plan keep `Contact:Captcha:Enabled=false`.
### ASF host (`Api.AndreaSlopFotografie`)
- References `Modules.Contact`; section `Contact` in its `appsettings.json` (`Enabled:false`, `SiteId: andreaslop`), the three contact rate-limit policies. Capabilities now list `Contact`; the module does nothing and touches no database while `Contact:Enabled=false`.