fix(turnstile): route CAPTCHA verification through the configured proxy#38412
Merged
Conversation
Turnstile verification used http.DefaultClient, so the request to challenges.cloudflare.com bypassed Gitea's configured HTTP proxy, unlike other outbound clients (e.g. the update checker). In environments where egress is only allowed through the proxy, verification failed. Build the client with proxy.Proxy() as the transport proxy, the same way the update checker does, so Turnstile honors the proxy settings.
delvh
approved these changes
Jul 11, 2026
lunny
approved these changes
Jul 12, 2026
wxiaoguang
reviewed
Jul 12, 2026
3ab62a1 to
1fa5c9d
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Turnstile CAPTCHA server-side verification HTTP client to honor Gitea’s configured outbound proxy settings, addressing deployments where egress is only allowed via proxy.
Changes:
- Route Turnstile verification HTTP requests through
proxy.Proxy()instead ofhttp.DefaultClient. - Introduce a resettable
util.OnceValue[T]helper to lazily initialize and cache a value. - Add unit tests validating the Turnstile HTTP client’s proxy behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| modules/util/sync.go | Adds a resettable, lazy “once value” helper used to cache initialized values. |
| modules/util/sync_test.go | Adds unit tests for util.OnceValue behavior (repeat calls, panic caching, reset). |
| modules/turnstile/turnstile.go | Switches Turnstile verification to use an HTTP client that applies Gitea proxy configuration. |
| modules/turnstile/turnstile_test.go | Adds a test ensuring the Turnstile HTTP client honors the configured proxy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wxiaoguang
approved these changes
Jul 12, 2026
bircni
approved these changes
Jul 12, 2026
wxiaoguang
added a commit
that referenced
this pull request
Jul 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #38217
Problem
Turnstile CAPTCHA verification uses
http.DefaultClient, so the request tochallenges.cloudflare.combypasses Gitea's configured HTTP proxy — unlike other outbound HTTP clients such as the update checker (modules/updatechecker/update_checker.go) and migrations. In deployments where egress is only permitted through the configured proxy, verification fails.Fix
Build the client with
proxy.Proxy()as the transport proxy, mirroring the update checker:The client is built per call (rather than a package-level var) because
proxy.Proxy()readssetting.Proxywhen invoked; building it at request time ensures it reflects the loaded settings. When no proxy is configured, behavior is unchanged (proxy.Proxy()returns a no-op /http.ProxyFromEnvironment).