-
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
Add forwarded-host-header and forwarded-prefix-header configuration #9809
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/EnvoyHeaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.quarkus.vertx.http; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class EnvoyHeaderTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(ForwardedHandlerInitializer.class) | ||
.addAsResource(new StringAsset("quarkus.http.proxy-address-forwarding=true\n" | ||
+ "quarkus.http.forwarded-prefix-header=X-Envoy-Original-Path\n"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void test() { | ||
RestAssured.given() | ||
.header("X-Envoy-Original-Path", "prefix") | ||
.get("/uri") | ||
.then() | ||
.body(Matchers.equalTo("/prefix/uri")); | ||
} | ||
|
||
@Test | ||
public void testWithEmptyPrefix() { | ||
RestAssured.given() | ||
.header("X-Envoy-Original-Path", "") | ||
.get("/uri") | ||
.then() | ||
.body(Matchers.equalTo("/uri")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...rtx-http/deployment/src/test/java/io/quarkus/vertx/http/ForwardedForPrefixHeaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.quarkus.vertx.http; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class ForwardedForPrefixHeaderTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(ForwardedHandlerInitializer.class) | ||
.addAsResource(new StringAsset("quarkus.http.proxy-address-forwarding=true\n" | ||
+ "quarkus.http.forwarded-prefix-header=X-Forwarded-Prefix\n"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testWithPrefix() { | ||
RestAssured.given() | ||
.header("X-Forwarded-Prefix", "prefix") | ||
.get("/uri") | ||
.then() | ||
.body(Matchers.equalTo("/prefix/uri")); | ||
} | ||
|
||
@Test | ||
public void testWithEmptyPrefix() { | ||
RestAssured.given() | ||
.header("X-Forwarded-Prefix", "") | ||
.get("/uri") | ||
.then() | ||
.body(Matchers.equalTo("/uri")); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...rtx-http/deployment/src/test/java/io/quarkus/vertx/http/ForwardedForServerHeaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.quarkus.vertx.http; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class ForwardedForServerHeaderTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(ForwardedHandlerInitializer.class) | ||
.addAsResource(new StringAsset("quarkus.http.proxy-address-forwarding=true\n" | ||
+ "quarkus.http.forwarded-host-header=X-Forwarded-Server\n"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void test() { | ||
assertThat(RestAssured.get("/forward").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("X-Forwarded-Proto", "https") | ||
.header("X-Forwarded-For", "backend:4444") | ||
.header("X-Forwarded-Server", "somehost") | ||
.get("/forward") | ||
.then() | ||
.body(Matchers.equalTo("https|somehost|backend:4444")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...oyment/src/test/java/io/quarkus/vertx/http/ProxyAddressForwardingDefaultSettingsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.quarkus.vertx.http; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class ProxyAddressForwardingDefaultSettingsTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(ForwardedHandlerInitializer.class) | ||
.addAsResource(new StringAsset("quarkus.http.proxy-address-forwarding=true\n"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testWithHostHeader() { | ||
assertThat(RestAssured.get("/forward").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("X-Forwarded-Proto", "https") | ||
.header("X-Forwarded-For", "backend:4444") | ||
.header("X-Forwarded-Host", "somehost") | ||
.header("X-Forwarded-Prefix", "prefix") | ||
.get("/forward") | ||
.then() | ||
.body(Matchers.equalTo("https|localhost|backend:4444")); | ||
} | ||
|
||
@Test | ||
public void testWithPrefixHeader() { | ||
RestAssured.given() | ||
.header("X-Forwarded-Prefix", "prefix") | ||
.get("/uri") | ||
.then() | ||
.body(Matchers.equalTo("/uri")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This must be optional, both of these need to have a specific configuration option to turn them on.
To give you an idea of why this can cause problems say I have an environment that knows nothing about X-Forwarded-Prefix, but security is done by the front end proxy.
An attacker could send a request to / but with X-Forwarded-Prefix set to /secure. The front end proxy will just see /, and allow it, but then Quarkus will serve up content from /secure.
If you are going to enable these options they can only be turned on in an environment where you know these headers will only be set by a trusted source.
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.
Thanks for the explanation! :-)
For clarification, when you mentioned "both of these", do you mean x-forwarded-host/x-forwarded-server as well?
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.
yes
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.
Can the "quarkus.http.proxy-address-forwarding" config property be enough to prevent those scenarios?
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.
Hmm, I need to do some more research on this. The question is do frontend proxies that send one or more of these always send all of them (or make sure to disallow forwarding them)?
If all the main implementations do this then as this is not really a standard we are probably fine to just use a single switch. If not then maybe even our current configuration is too coarse grained.
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.
@ejba Looks like a switch per header can be the most secure solution based on what you've discussed with @stuartwdouglas and @kraeftbraeu, please follow up with this update.
May be it can make sense to split the PR in 2 parts, the 1st part will only deal with
X-Forwarded-Host
andX-Forwarded-Server
to accelerate it,X-Forwarded-Prefix
related updated can be discussed further as needed in another (draft) PR...Sounds good ?
Cheers, Sergey
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.
@sberyozkin, just two questions:
quarkus.http.proxy-address-forwarding
property?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.
I like the approach with two separate PRs, since it helps separate needs. To be honest I still dont get the security issues with the prefix header. Isnt it set by the reverse proxy? Or is it possible that the reverse proxy just forwards these headers?
So, for the host/server selection two separate switches shall be used with a startup exception when both are set to true?
Or can we stay with the current solution but we extend the documentation (and maybe the startup log) with a hint to this security issue when using this option?
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.
The property
quarkus.http.proxy-address-forwarding
says if the absoluteUri shall be recalculated from forwarded-headers in principle. I'd say that should be kept.When we start the additional properties
quarkus.http.allow-x-forwarded-server
quarkus.http.allow-x-forwarded-host
quarkus.http.allow-x-forwarded-prefix
and the second one is no more enabled by default, backward compatibility is broken.
I'm new to the quarkus project but IMHO broken backward compatibility reduces trust to a software project and should definitely be avoided if possible.
Of course security issues are still important. But in the end the key is the awareness by the quarkus users. And I would prefer to write a good documentation rather than making the configuration a little more complicated to push the user to think about security issues.
@stuartwdouglas what do you think?
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.
Ah I see, #10138 is the new PR.