Skip to content

auth: trust reverse proxy auth header only from configured proxies - #8264

Merged
unknwon merged 12 commits into
gogs:mainfrom
unknwon:GHSA-w6j9-vw59-27wv
May 18, 2026
Merged

unknwon merged 12 commits into
gogs:mainfrom
unknwon:GHSA-w6j9-vw59-27wv

Conversation

@unknwon

@unknwon unknwon commented May 18, 2026 •

Copy link
Copy Markdown
Member

Summary

When [auth] ENABLE_REVERSE_PROXY_AUTHENTICATION is enabled, the configured header was previously honored from any client. This adds a new [auth] TRUSTED_PROXY_IPS option (default 127.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_IPS to the proxy's address(es). Bare IPs and CIDR ranges are both accepted.

Refs: GHSA-w6j9-vw59-27wv

Test plan

  • task lint
  • go test ./internal/conf/ ./internal/context/
  • Manual: with ENABLE_REVERSE_PROXY_AUTHENTICATION=true and the default TRUSTED_PROXY_IPS, a request with X-WEBAUTH-USER from an external IP is no longer authenticated; a request from 127.0.0.1 still is.

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

Comment thread internal/conf/conf.go Resolved
Comment thread internal/conf/static.go Resolved
Comment thread conf/app.ini Resolved
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.
@unknwon unknwon added this to the 0.14.3 milestone May 18, 2026
@unknwon
unknwon merged commit 0089c4c into gogs:main May 18, 2026
8 checks passed
unknwon added a commit that referenced this pull request Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants