You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This pull request adds invisible hCaptcha support to the chat widget and
strengthens security around trusted proxy handling and rate limiting.
The most important changes include server- and client-side hCaptcha
integration, improved trusted proxy CIDR configuration for forwarded
headers, and several security and code quality improvements.
**hCaptcha Integration:**
* Added invisible hCaptcha validation to chat endpoints in
`ChatController`, including a new `IsCaptchaValidAsync` method,
dependency injection of `ICaptchaService` and options, and logging for
captcha failures and service outages. The endpoints now require a valid
hCaptcha token when configured, failing open only if the hCaptcha
service is unavailable.
[[1]](diffhunk://#diff-4a94a1b44a0792e8b86260b0a32f20ffa07e3df954a2686e75fd2f2e439d61c3R4-R9)
[[2]](diffhunk://#diff-4a94a1b44a0792e8b86260b0a32f20ffa07e3df954a2686e75fd2f2e439d61c3R22-R64)
[[3]](diffhunk://#diff-4a94a1b44a0792e8b86260b0a32f20ffa07e3df954a2686e75fd2f2e439d61c3R76-R78)
[[4]](diffhunk://#diff-4a94a1b44a0792e8b86260b0a32f20ffa07e3df954a2686e75fd2f2e439d61c3R129-R135)
[[5]](diffhunk://#diff-4a94a1b44a0792e8b86260b0a32f20ffa07e3df954a2686e75fd2f2e439d61c3R233-R238)
* Updated `ChatMessageRequest` to require and document the
`CaptchaResponse` field, with validation and a larger maximum length.
* Passed the hCaptcha site key from server to client via
`_Layout.cshtml`, and rendered the invisible widget container and legal
disclosure in the chat UI only when captcha is enabled.
[[1]](diffhunk://#diff-99124c9dc22814eb65ae9a3d958e2657465c737eb30cbdeb58316c2adeef74c0R9-R13)
[[2]](diffhunk://#diff-99124c9dc22814eb65ae9a3d958e2657465c737eb30cbdeb58316c2adeef74c0R197)
[[3]](diffhunk://#diff-a3f79adcd2637b729b61fe3c2d59b4dc5b693f3603862fc546b993b65487cfa4R14)
[[4]](diffhunk://#diff-a3f79adcd2637b729b61fe3c2d59b4dc5b693f3603862fc546b993b65487cfa4R27-R38)
[[5]](diffhunk://#diff-a3f79adcd2637b729b61fe3c2d59b4dc5b693f3603862fc546b993b65487cfa4R205-R211)
* Implemented client-side hCaptcha integration in `chat-module.js`,
including widget initialization, token retrieval with timeout and error
handling, and reset logic.
**Trusted Proxy and Rate Limiting Security:**
* Enhanced trusted proxy CIDR configuration for forwarded headers in
`Program.cs`, including parsing from configuration, warnings for
missing/invalid configuration, and detailed comments about the security
implications of not setting this value.
[[1]](diffhunk://#diff-18732233c16eb367b49fa9d7a6f04dcffb924031136727c74868735c15885102L115-R133)
[[2]](diffhunk://#diff-18732233c16eb367b49fa9d7a6f04dcffb924031136727c74868735c15885102R442-R451)
[[3]](diffhunk://#diff-e47670b0d9a1e97097e60cb20a1dbf08655ba40a8196819edf43617bb0390973R5-R7)
[[4]](diffhunk://#diff-18732233c16eb367b49fa9d7a6f04dcffb924031136727c74868735c15885102R638-R640)
* Updated rate limiter partitioning to consistently use
`ClaimTypes.NameIdentifier` for user partition keys, improving stability
and reducing risk of key conflation.
[[1]](diffhunk://#diff-18732233c16eb367b49fa9d7a6f04dcffb924031136727c74868735c15885102L311-R325)
[[2]](diffhunk://#diff-18732233c16eb367b49fa9d7a6f04dcffb924031136727c74868735c15885102L329-R343)
[[3]](diffhunk://#diff-841708f0e87c8eb4799aabe8afab12259bdb8ac1baaad89a240b48bf4de5cd93L29-R29)
[[4]](diffhunk://#diff-844f40bab2fc81e7d7bbca30e8fdb1a9e954586ea54660ffadee57b6eb548f72L24)
**Other Improvements:**
* Removed the unused `requiresCaptcha` field from the rate limit error
response.
* Changed sitemap validation exception handling to only catch
`InvalidOperationException`, making error handling more precise.
These changes collectively add robust human verification to the chat
feature, improve rate limiting and IP spoofing protections, and enhance
code maintainability.
awaitResponse.WriteAsJsonAsync(new{error="Human verification is temporarily unavailable. Please try again later.",errorCode="captcha_unavailable"},cancellationToken);
0 commit comments