-
Notifications
You must be signed in to change notification settings - Fork 6k
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
base: master
Are you sure you want to change the base?
Conversation
…eader in some cases after JDK-8344190
👋 Welcome back jpai! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
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.
@@ -621,8 +621,9 @@ private void writeRequests() throws IOException { | |||
if (port != -1 && port != url.getDefaultPort()) { | |||
host += ":" + String.valueOf(port); | |||
} | |||
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()
.
@@ -57,6 +57,7 @@ | |||
*/ | |||
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.
Can I please get a review for this change which addresses a regression that was introduced in
HttpURLConnection
in 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 theHost
header to set in the request. By default, the application cannot set aHost
header to a different value. However the JDK allows a system property to be enabled to allow applications to explicitly set aHost
request header when issuing the request.Due to an oversight in the change that was done in https://bugs.openjdk.org/browse/JDK-8344190, the
Host
header 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
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25844/head:pull/25844
$ git checkout pull/25844
Update a local copy of the PR:
$ git checkout pull/25844
$ git pull https://git.openjdk.org/jdk.git pull/25844/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25844
View PR using the GUI difftool:
$ git pr show -t 25844
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25844.diff
Using Webrev
Link to Webrev Comment