Skip to content

Conversation

hugodutka
Copy link
Collaborator

@hugodutka hugodutka commented Aug 9, 2025

Summary:

  • Adds --use-x-forwarded-host CLI flag and ServerConfig.UseXForwardedHost.
  • When enabled, hostAuthorizationMiddleware prefers X-Forwarded-Host (first value, before comma), extracts hostname via url.Parse and matches against AllowedHosts (case-insensitive, ignoring port). Falls back to r.Host if header is absent.
  • Adds tests covering enabled/disabled behavior, port in header, IPv6 literal, and comma-separated header values.
  • CLI tests updated to assert default false, env var (AGENTAPI_USE_X_FORWARDED_HOST) parsing, and CLI override precedence.
  • README: documents the new flag and env var with guidance on trusted proxy usage.

Notes:

  • Semantics mirror Django’s USE_X_FORWARDED_HOST gating, but limited to Host selection only.
  • No behavior change when the flag is false (default).

Testing:

  • go test ./... passes locally.

blink-so-v1 bot and others added 4 commits August 9, 2025 08:11
…n\nAdds --use-x-forwarded-host CLI flag and ServerConfig.UseXForwardedHost.\nWhen enabled, the middleware prefers X-Forwarded-Host (first value, before comma),\nparses and matches hostname ignoring port. Includes tests for enabled/disabled,\nports, IPv6, and comma-separated cases.\n\nCo-authored-by: hugodutka <[email protected]>
…st\n\nExtend CLI tests to cover default false, env var AGENTAPI_USE_X_FORWARDED_HOST,\nand CLI overrides env precedence.\n\nCo-authored-by: hugodutka <[email protected]>
…when to enable, behavior (first value, comma-trimming, hostname-only, IPv6),\nand security considerations (trusted proxy).\n\nCo-authored-by: hugodutka <[email protected]>
@bpmct bpmct merged commit d1fb1b0 into hugodutka/allowed-hosts Aug 12, 2025
2 checks passed
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