Skip to content

8378500: Restrict IP literals from being allowed in javax.net.ssl.SNIHostName#30747

Open
vy wants to merge 2 commits intoopenjdk:masterfrom
vy:sni
Open

8378500: Restrict IP literals from being allowed in javax.net.ssl.SNIHostName#30747
vy wants to merge 2 commits intoopenjdk:masterfrom
vy:sni

Conversation

@vy
Copy link
Copy Markdown
Contributor

@vy vy commented Apr 15, 2026

Per RFC 6066 "3. Server Name Indication", disallow IP literals in SNIHostName::new.

While the following two call-sites could be simplified by removing IP literal checks, I've refrained from doing so because delegating some of the checks to an exception catching mechanism would impact the performance:

sun.security.ssl.Utilities::rawToSNIHostName
sun.net.www.protocol.https.HttpsClient::afterConnect


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires CSR request JDK-8382318 to be approved

Issues

  • JDK-8378500: Restrict IP literals from being allowed in javax.net.ssl.SNIHostName (Bug - P3)
  • JDK-8382318: Restrict IP literals from being allowed in javax.net.ssl.SNIHostName (CSR)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30747/head:pull/30747
$ git checkout pull/30747

Update a local copy of the PR:
$ git checkout pull/30747
$ git pull https://git.openjdk.org/jdk.git pull/30747/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30747

View PR using the GUI difftool:
$ git pr show -t 30747

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30747.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Apr 15, 2026

👋 Welcome back vyazici! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 15, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk Bot added security security-dev@openjdk.org net net-dev@openjdk.org labels Apr 15, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 15, 2026

@vy The following labels will be automatically applied to this pull request:

  • net
  • security

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk Bot added the rfr Pull request is ready for review label Apr 15, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge Bot commented Apr 15, 2026

Webrevs

@AlanBateman
Copy link
Copy Markdown
Contributor

/csr

@AlanBateman
Copy link
Copy Markdown
Contributor

I've added the "csr" label as I think (and correct me if I have this wrong) that javax.net.ssl.SNIHostName can now fail for cases that it didn't previously fail.

@openjdk openjdk Bot added the csr Pull request needs approved CSR before integration label Apr 15, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 15, 2026

@AlanBateman has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@vy please create a CSR request for issue JDK-8378500 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

@dfuch
Copy link
Copy Markdown
Member

dfuch commented Apr 15, 2026

Yes - a CSR is needed for this change. Thanks for adding the label @AlanBateman.

@vy
Copy link
Copy Markdown
Contributor Author

vy commented Apr 20, 2026

We've decided to leave SNIHostName::new untouched, and introduce a new static factory method with stricter checks. See the CSR discussion for details. I will update the PR in this direction.

@vy vy marked this pull request as draft April 21, 2026 09:00
@vy vy marked this pull request as ready for review April 21, 2026 09:00
@vy
Copy link
Copy Markdown
Contributor Author

vy commented Apr 21, 2026

In b2c40b2,

  • I've added the ofString() static factory method
  • I've updated the SNIHostName(String) ctor specification:
    • I've placed the interesting bits (i.e., what qualifies as an illegal host name) to the top
    • I've moved ASCII/IDN validation story to a dedication subsection
    • I've added an @apiNote to advice users to prefer ofString() instead (this was suggested by @dfuch, IIRC)
  • In the ofString() specification, I've added an @apiNote to advice users to have a catch (IAE) safety net

An alternative direction could be making the new SNIHostName(String hostname, boolean strict) ctor public instead of adding a new static factory method.

Note that this is a draft to have a feeling on the end result — SNIHostName(byte[])/tests/etc. are not adapted yet.

@AlanBateman, @dfuch, @djelinski, would you mind reviewing these changes, please? How shall I proceed?

*
* Users are advised to prefer the {@link #ofString(String) ofString()}
* static factory method over this constructor, since the former performs
* stricter checks.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this will be seen, which makes me wonder if this should go a step further and deprecate the constructors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad you said this, I completely agree with your concern and reasoning. I will do it.

Though this reminded me another question I need some help with: Shall I migrate existing usages of SNIHostName::new to the new static factory methods in this PR? Slim PRs are ideal, but leaving the correction of call-sites to a 2nd PR bears the risk that we might end up having a 3rd PR if the 1st (this) one has any problems.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be compatibility issues with change the existing usages (as they might fail with IAE) so I would keep that separate.

* @spec https://www.rfc-editor.org/info/rfc6066
* RFC 6066: Transport Layer Security (TLS) Extensions: Extension Definitions
*/
public static SNIHostName ofString(String hostname) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ofHostName(String) and ofEncoded(byte) is another choice that would make it clear at the use sites.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had considered how it would look like at the call-site:

SNIHostName.ofHostName(hostName);  // Too verbose/noisy with repetition?

and then thought of:

SNIHostName.ofString(hostName);
SNIHostName.ofBytes(hostName);

But I will leave the decision on naming to those more experienced in this field.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SNIHostName.of(String) and SNIHostName.ofEncoded(byte[]) are other candidates.

* <li>It is empty
* <li>It ends with a trailing dot
* <li>It is not a valid Internationalized Domain Name (IDN)</li>
*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list seems to imply that an SNI hostname must be an IDN. I wonder if it might be better to first state what a valid SNI hostname is (ie a DNS hostname), mentioning IDNs and then later specify the exclusions, including (I presume) a string that starts with "xn--" but which doesn't represent a valid IDN?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

csr Pull request needs approved CSR before integration net net-dev@openjdk.org rfr Pull request is ready for review security security-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

4 participants