Skip to content

fix(turnstile): route CAPTCHA verification through the configured proxy#38412

Merged
bircni merged 4 commits into
go-gitea:mainfrom
singhlovepreet9:fix-turnstile-proxy
Jul 12, 2026
Merged

fix(turnstile): route CAPTCHA verification through the configured proxy#38412
bircni merged 4 commits into
go-gitea:mainfrom
singhlovepreet9:fix-turnstile-proxy

Conversation

@singhlovepreet9

@singhlovepreet9 singhlovepreet9 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #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:

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).

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.
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 11, 2026
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jul 11, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jul 12, 2026
Comment thread modules/turnstile/turnstile_test.go Outdated
@wxiaoguang wxiaoguang added the backport/v1.27 This PR should be backported to Gitea 1.27 label Jul 12, 2026
@wxiaoguang wxiaoguang marked this pull request as draft July 12, 2026 03:05
@wxiaoguang wxiaoguang marked this pull request as ready for review July 12, 2026 03:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 of http.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.

Comment thread modules/turnstile/turnstile.go Outdated
Comment thread modules/turnstile/turnstile.go
Comment thread modules/util/sync.go Outdated
Comment thread modules/turnstile/turnstile_test.go
Comment thread modules/turnstile/turnstile_test.go
@bircni bircni enabled auto-merge (squash) July 12, 2026 10:56
@bircni bircni added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jul 12, 2026
@bircni bircni merged commit 65c5a5f into go-gitea:main Jul 12, 2026
24 of 26 checks passed
@GiteaBot GiteaBot added this to the 28.0.0 milestone Jul 12, 2026
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jul 12, 2026
@GiteaBot GiteaBot added the backport/done All backports for this PR have been created label Jul 12, 2026
@wxiaoguang wxiaoguang mentioned this pull request Jul 12, 2026
wxiaoguang added a commit that referenced this pull request Jul 12, 2026
…xy (#38412) (#38420)

Backport #38412

Fixes #38217

Co-authored-by: Lovepreet Singh <lovepreet.singh61182@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/done All backports for this PR have been created backport/v1.27 This PR should be backported to Gitea 1.27 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not using HTTP proxy for Turnstile challenge

7 participants