Commit d1c42b6
authored
fix: Replace hCaptcha hostname security check with informational telemetry (#1117)
## Why
The `ExpectedHostname` config in `CaptchaOptions` was being used to
validate the `hostname` field returned by hCaptcha's siteverify API --
failing the captcha if it didn't match. However, [hCaptcha's own
docs](https://docs.hcaptcha.com/#verify-the-user-response-server-side)
explicitly state:
> "the hostname field is derived from the user's browser, and should not
be used for authentication of any kind; it is primarily useful as a
statistical metric. Additionally... the hostname field may be returned
as 'not-provided' rather than the usual value"
This means the check provided false security (browser-controlled,
trivially spoofable) and could silently reject legitimate users under
high traffic when hCaptcha returns `"not-provided"`.
## What changed
- **`CaptchaOptions.cs`**: Removed `ExpectedHostname` property. The
`HCaptcha__ExpectedHostname` environment variable can now be removed
from all deployed environments.
- **`CaptchaService.cs`**: Replaced the hostname mismatch block (which
set `result.Success = false`) with an informational log that fires on
every successful verification. The expected hostname is now derived from
`SiteSettings.BaseUrl` rather than a separate config value.
## Telemetry
Every successful captcha verification now logs:
```
hCaptcha hostname: reported={ReportedHostname}, expected={ExpectedHostname}
```
This enables App Insights / Log Analytics queries to bucket hostname
distributions, for example:
```kql
traces
| where message startswith "hCaptcha hostname"
| extend reported = tostring(customDimensions.ReportedHostname),
expected = tostring(customDimensions.ExpectedHostname)
| summarize count() by reported, expected
```1 parent 670b0f5 commit d1c42b6
2 files changed
Lines changed: 9 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | 29 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | | - | |
| 53 | + | |
53 | 54 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
85 | | - | |
| 84 | + | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
0 commit comments