-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure Forwarded and X-Forwarded values are the same #44601
base: main
Are you sure you want to change the base?
Ensure Forwarded and X-Forwarded values are the same #44601
Conversation
400109d
to
a46c3b2
Compare
I've figured out how to end it with 400, setting the response status and doing |
extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/ForwardedParser.java
Outdated
Show resolved
Hide resolved
9350107
to
cf7114f
Compare
Will see if I can test this in our infra, we have one use case that our service is served through AWS API GW externally (which we also filter the exposed endpoints), and internally through VPN we hit the service hitting one AWS ALB... so each one adds the header differently, ALB adds the Forwarded, API GW adds X-Forwarded... so need to see in both entry points if this change would be a breaking change and would also render our service somewhat useless if we were to upgrade to a version with this change. |
I don't really have time until Saturday, I'll re-check then, but please don't wait for my review. Thanks |
Thanks @luneo7 If it proves a breaking change that we can add a strict check property that you'd be able to turn off... But the main reason I turned it to draft is that I'm not certain the solution is correct, because right now it will cause a failure if, for ex, I believe only those properties which have been impacted by both headers must be compared. For example, in the previous example, it should be checked that both Is it a correct assumption ? |
cf7114f
to
6afc82d
Compare
I've updated it to make sure that only those properties are checked that are set at both Forwarded and X-Forwarded level, to avoid some forwarded property value being overridden by the x-forwarded one |
Thanks @sberyozkin for addressing this! It makes sense. Honestly, I would fail if the values are not the same (and add a flag to disable this check). |
Hi @cescoffier Yes, it is Right, I can look at adding a property, I'd like to hear from @luneo7 as well when he gets a chance to test it in his setup |
This comment has been minimized.
This comment has been minimized.
@sberyozkin We have related issues about the precedence between the headers. So, I believe we would need a flag to disable the "safe way". See #35751 (which I would consider closed one this is in). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - I would just add the flag as discussed.
6afc82d
to
6e9a414
Compare
Hi @cescoffier @gsmet, I had this feeling when looking at the code, but I was confused by several things, by the #35751 issue, so I've realized only now that So when the user says The original issue, #25077, remains unresolved, while #35751 is basically invalid because So I've moved it to draft again because it actually changes the Comments are welcome, I'll reopen for review once everyone is happy with what is proposed here. |
🎊 PR Preview 1e7e874 has been successfully built and deployed to https://quarkus-pr-main-44601-preview.surge.sh/version/main/guides/
|
@sberyozkin in our case it wouldn't work, just checked... |
And yeah, when we have both headers, |
Thanks @luneo7. I think we need one more property, the precedence enum. |
6e9a414
to
a4d1906
Compare
Now, when both types of forwarded headers are enabled, and no strict control is enabled, the precedence decides which headers make |
This comment has been minimized.
This comment has been minimized.
Status for workflow
|
Fixes #35751
Enabling both
X-Forwarded
andForwarded
for the proxy address forwarding may pose some risks - it is very clearly mentioned in JavaDocs for both theallowForwarded
andallowXforwarded
properties and a warning is logged when both are enabled. This PR adds a hardening check to make sure that if both Forwarded and XForwarded headers are enabled on the proxy address forwarding path, then the header values must match.I've been thinking that if the mismatch happens then an error must be reported and it should be
400
, as opposed to500
. If it is agreed upon then the remaining puzzle for me is where to intercept non-JAX-RSBadClientRequestException
in order to end the request with 401, which I added in this PR, since the forwarded handler delegates toVert.x HttpServerRequest
.Also CC @luneo7