Skip to content

fix(parsers): validate host headers to prevent injection [C2]#544

Merged
lakhansamani merged 1 commit intomainfrom
fix/c2-host-header-injection
Apr 4, 2026
Merged

fix(parsers): validate host headers to prevent injection [C2]#544
lakhansamani merged 1 commit intomainfrom
fix/c2-host-header-injection

Conversation

@lakhansamani
Copy link
Copy Markdown
Contributor

Summary

  • C2 (Critical): Validates X-Authorizer-URL, X-Forwarded-Proto, X-Forwarded-Host headers to prevent host header injection
  • Prevents OAuth redirect hijacking, JWT issuer spoofing, and poisoned password-reset emails
  • X-Authorizer-URL: only http/https, no userinfo, path/query/fragment stripped
  • X-Forwarded-Host: rejects path separators, query strings, header injection chars
  • Falls back safely to Request.Host then "localhost"

Test plan

  • 23 unit tests for sanitizeAuthorizerURL and sanitizeHost
  • Verify OAuth callbacks still work with legitimate proxy headers
  • Verify direct access (no proxy) still works

GetHost() now sanitizes X-Authorizer-URL, X-Forwarded-Proto, and
X-Forwarded-Host headers to prevent host header injection that could
lead to OAuth redirect hijacking, JWT issuer spoofing, and poisoned
password-reset/verification emails.

- X-Authorizer-URL: parsed as URL, only http/https scheme allowed,
  userinfo rejected, path/query/fragment stripped
- X-Forwarded-Host: rejects values with path separators, query strings,
  fragments, userinfo, or header injection characters
- Falls back to Request.Host then "localhost" if all headers invalid

Fixes: C2 (Critical)
@lakhansamani lakhansamani merged commit de0e47c into main Apr 4, 2026
@lakhansamani lakhansamani deleted the fix/c2-host-header-injection branch April 4, 2026 05:36
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.

1 participant