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
wxiaoguang
marked this pull request as draft
July 12, 2026 03:05
wxiaoguang
marked this pull request as ready for review
July 12, 2026 03:34
wxiaoguang
force-pushed
the
fix-turnstile-proxy
branch
from
July 12, 2026 03:40
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
bircni
enabled auto-merge (squash)
July 12, 2026 10:56
wxiaoguang
added a commit
that referenced
this pull request
Jul 12, 2026
zjjhot
added a commit
to zjjhot/gitea
that referenced
this pull request
Jul 13, 2026
* 'main' of https://github.com/go-gitea/gitea: fix: various security fixes (go-gitea#38406) fix(util): reject invalid characters between time-estimate units (go-gitea#38416) feat(actions): implement adaptive auto-refresh for workflow runs list (go-gitea#38329) fix(turnstile): route CAPTCHA verification through the configured proxy (go-gitea#38412) fix: represent a deleted assignee team as a Ghost team (go-gitea#38413) [skip ci] Updated translations via Crowdin fix: refresh pull request merge box when the commit status is pending (go-gitea#38410) chore: remove Yarden Shoham from maintainers (go-gitea#38407) fix: actions task state concurrent update (go-gitea#38405) fix(actions): keep workflow run trailing on one row with long branch names (go-gitea#38382) fix(pull): re-evaluate review official flag on target branch change (go-gitea#38319) fix(web): use locale-aware date formatting for contribution calendar tooltips (go-gitea#38398) fix(security): harden access checks and migration validation (go-gitea#38324) fix: enforce public-only token scope and harden push options / locale parsing (go-gitea#38323) fix: co-author detection (go-gitea#38392) fix(api): stop leaking private repo metadata after access revocation (go-gitea#38321) fix(lfs): require proof of possession for cross-repo objects (go-gitea#38322) fix: incorrect co-author detection on commit page (go-gitea#38386)
zjjhot
added a commit
to zjjhot/gitea
that referenced
this pull request
Jul 13, 2026
* main: fix: various security fixes (go-gitea#38406) fix(util): reject invalid characters between time-estimate units (go-gitea#38416) feat(actions): implement adaptive auto-refresh for workflow runs list (go-gitea#38329) fix(turnstile): route CAPTCHA verification through the configured proxy (go-gitea#38412) fix: represent a deleted assignee team as a Ghost team (go-gitea#38413) [skip ci] Updated translations via Crowdin fix: refresh pull request merge box when the commit status is pending (go-gitea#38410) chore: remove Yarden Shoham from maintainers (go-gitea#38407) fix: actions task state concurrent update (go-gitea#38405) fix(actions): keep workflow run trailing on one row with long branch names (go-gitea#38382) fix(pull): re-evaluate review official flag on target branch change (go-gitea#38319) fix(web): use locale-aware date formatting for contribution calendar tooltips (go-gitea#38398) fix(security): harden access checks and migration validation (go-gitea#38324) fix: enforce public-only token scope and harden push options / locale parsing (go-gitea#38323) fix: co-author detection (go-gitea#38392) fix(api): stop leaking private repo metadata after access revocation (go-gitea#38321) fix(lfs): require proof of possession for cross-repo objects (go-gitea#38322) fix: incorrect co-author detection on commit page (go-gitea#38386)
zeekay
pushed a commit
to hanzoai/git
that referenced
this pull request
Jul 26, 2026
…xy (go-gitea#38412) Fixes go-gitea#38217 ## Problem Turnstile CAPTCHA verification uses `http.DefaultClient`, so the request to `challenges.cloudflare.com` bypasses 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: ```go func httpClient() *http.Client { return &http.Client{ Transport: &http.Transport{ Proxy: proxy.Proxy(), }, } } ``` The client is built per call (rather than a package-level var) because `proxy.Proxy()` reads `setting.Proxy` when 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`). --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
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).