Repository navigation
Merged
Conversation
Add `[auth] TRUSTED_PROXIES` (default `127.0.0.0/8,::1/128`) and ignore the reverse proxy authentication header for requests whose remote address falls outside it. Prevents header spoofing when the Gogs port is reachable directly.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens reverse proxy authentication by only honoring the configured authentication header when the immediate remote address is in a configured trusted proxy allowlist.
Changes:
- Adds parsing and storage for trusted proxy IP/CIDR configuration.
- Gates reverse proxy header authentication on the trusted proxy check.
- Adds unit coverage for proxy address matching and documents the security fix.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
internal/context/auth.go |
Checks request remote address before accepting reverse proxy auth headers. |
internal/context/auth_test.go |
Adds tests for trusted proxy matching behavior. |
internal/conf/conf.go |
Parses configured trusted proxy IPs/CIDRs. |
internal/conf/static.go |
Adds auth config fields for trusted proxy settings. |
internal/conf/testdata/TestInit.golden.ini |
Updates expected config output with the new option. |
conf/app.ini |
Documents the default trusted proxy configuration. |
CHANGELOG.md |
Records the security fix and new configuration option. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Reset Auth.TrustedProxyCIDRs before re-parsing so a second Init call (e.g. through the web installer) does not carry stale CIDRs forward. Also expose the trusted proxy list on /admin/config per the conf convention.
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.
Summary
When
[auth] ENABLE_REVERSE_PROXY_AUTHENTICATIONis enabled, the configured header was previously honored from any client. This adds a new[auth] TRUSTED_PROXY_IPSoption (default127.0.0.0/8,::1/128) and ignores the header for requests whose remote address falls outside of it.Operators who terminate the reverse proxy on a different host should set
TRUSTED_PROXY_IPSto the proxy's address(es). Bare IPs and CIDR ranges are both accepted.Refs: GHSA-w6j9-vw59-27wv
Test plan
task lintgo test ./internal/conf/ ./internal/context/ENABLE_REVERSE_PROXY_AUTHENTICATION=trueand the defaultTRUSTED_PROXY_IPS, a request withX-WEBAUTH-USERfrom an external IP is no longer authenticated; a request from127.0.0.1still is.