Skip to content

Conversation

@MetroMarv
Copy link

Using X-Forwarded-Port seems to be discouraged as it allows spoofing according to the Caddy proxy devs 0:

"For these X-Forwarded-* headers, by default, the proxy will ignore their values from incoming requests, to prevent spoofing."

Instead we should use the X-Forwarded-Proto header to infer the port that the proxy was called at. So https indicates port 443, while http indicates port 80.

Fixes #633

Using `X-Forwarded-Port` seems to be discouraged as it allows spoofing according to the Caddy proxy devs [0]:

"For these X-Forwarded-* headers, by default, the proxy will ignore their values from incoming requests, to prevent spoofing."

Instead we should use the X-Forwarded-Proto header to infer the port that the proxy was called at. So https indicates port 443, while http indicates port 80.

Fixes SAML-Toolkits#633

[0]: https://caddyserver.com/docs/caddyfile/directives/reverse_proxy?utm_source=chatgpt.com#defaults
@pitbulk
Copy link
Contributor

pitbulk commented Oct 27, 2025

Hi @MetroMarv

In this PR, you are assuming that proxies using HTTP_X_FORWARDED_PROTO and not providing HTTP_X_FORWARDED_PORT expect the "default" ports for those protocols to be used.

Nothing in the Forwarded header documentation indicates that this should be the followed behavior.

Applying this change could break environments not expecting the new behavior being introduced, so not merging it until it is clear that should be the behavior to follow.

@MetroMarv
Copy link
Author

As mentioned in the referenced ticket. My knowledge is purely based on ChatGPT. Maybe it doesn't make sense.

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.

php-saml requires X-Forwarded-Port for port determination, though X-Forwarded-Proto is set

2 participants