-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8359709: java.net.HttpURLConnection sends unexpected "Host" request header in some cases after JDK-8344190 #25844
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
Conversation
…eader in some cases after JDK-8344190
|
👋 Welcome back jpai! A progress list of the required criteria for merging this PR into |
|
@jaikiran This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 18 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
| static void beforeAll() throws Exception { | ||
| final InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); | ||
| server = HttpServer.create(addr, 0); | ||
| server.createContext("/", new Handler()); |
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 think it might be a good idea to salt the handler path a bit (e.g., with the class name) to avoid unexpected connections from tests running in parallel.
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.
Hello Volkan, the server handler in this test is implemented to allow more than one request during its lifetime. So any unexpected requests from other processes would still allow this test to be unaffected by those requests. Did I misunderstand your suggestion for registering the handler to a test specific context?
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.
So any unexpected requests from other processes would still allow this test to be unaffected by those requests.
Yes, this test will not be affected, but the other test might. Consider a test running in parallel, unexpectedly connecting to HostHeaderTest's server, and it is
- either not expecting a response at all
- or not expecting the response returned from the
HostHeaderTest's handler
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've updated the PR to register the handler at a test specific context root. Having said that, I wasn't aware we were doing this in our tests.
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.
We had some tests failing randmonly in the past because they got additional connections from other processes running on the same host (some time other tests). So now we tend to add a bit of salt in the path - it makes it easier to figure out that the strange things you see in the logs were not caused by a legit client. Also if you see 404 being returned and you know that your custom handler never returns 404 then it's easier to figure out that you somehow connected to some other server.
| } | ||
| String reqHost = requests.findValue("Host"); | ||
| if (reqHost == null || !reqHost.equalsIgnoreCase(host)) { | ||
| if (requests.findValue("Host") == null) { |
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.
Should we use setIfNotSet here like for "Accept" below?
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.
That seems reasonable. I had a look at the implementation in setIfNotSet() and it matches this current semantic. So I've updated the PR to use setIfNotSet().
| */ | ||
| class HostHeaderTest { | ||
|
|
||
| private static final String SERVER_CTX_ROOT = "/8359709"; |
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.
| private static final String SERVER_CTX_ROOT = "/8359709"; | |
| private static final String SERVER_CTX_ROOT = "/8359709/"; |
Preferably always terminate context roots with /
API Note:
The path should generally, but is not required to, end with '/'. If the path does not end with '/', eg such as with "/foo" then this would match requests with a path of "/foobar" or "/foo/bar".
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.
Good point. I've now updated the PR with this change. Test continues to pass.
|
Thank you all for the reviews. I'll go ahead and integrate this now. |
|
I'm trying to understand how this regression happened. I was looking at the code change for https://bugs.openjdk.org/browse/JDK-8344190 at https://openjdk.github.io/cr/?repo=jdk&pr=22232&range=01#sdiff-4-src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java and I can't see how it happened. The change looks pretty innocuous..? |
Never mind. I see it's explained clearly in the bug report. |
|
Hello Michael, I see that you already found out what caused the regression, but yes it's the |
|
/integrate |
|
Going to push as commit 5726606.
Your commit was automatically rebased without conflicts. |
|
/backport :jdk25 |
|
@jaikiran the backport was successfully created on the branch backport-jaikiran-57266064-jdk25 in my personal fork of openjdk/jdk. To create a pull request with this backport targeting openjdk/jdk:jdk25, just click the following link: The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk: |
Can I please get a review for this change which addresses a regression that was introduced in
HttpURLConnectionin Java 24 when we cleaned up the code by removing the references to SecurityManager APIs.When a HTTP request is issued through
java.net.HttpURLConnection, then the request URL is used to determine theHostheader to set in the request. By default, the application cannot set aHostheader to a different value. However the JDK allows a system property to be enabled to allow applications to explicitly set aHostrequest header when issuing the request.Due to an oversight in the change that was done in https://bugs.openjdk.org/browse/JDK-8344190, the
Hostheader that is set by the application, may not get used for that request causing this regression. Turns out we don't have tests in this area to catch this issue.The commit in this PR fixes the regression and also introduces a new jtreg test which reproduces the issue and verifies the fix.
I've also checked the original change which introduced this regression #22232 to see if there's anything else that needs attention. I haven't stopped anything else.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25844/head:pull/25844$ git checkout pull/25844Update a local copy of the PR:
$ git checkout pull/25844$ git pull https://git.openjdk.org/jdk.git pull/25844/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25844View PR using the GUI difftool:
$ git pr show -t 25844Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25844.diff
Using Webrev
Link to Webrev Comment