Skip to content

Conversation

@Michael-Mc-Mahon
Copy link
Member

@Michael-Mc-Mahon Michael-Mc-Mahon commented Mar 6, 2025

Hi,

Enhanced exception messages are designed to hide sensitive information such as hostnames, IP
addresses from exception message strings, unless the enhanced mode for the specific category
has been explicitly enabled. Enhanced exceptions were first introduced in 8204233 in JDK 11 and
updated in 8207846.

This PR aims to increase the coverage of enhanced exception messages in the networking code.
A limited number of exceptions are already hidden (restricted) by default. The new categories and
exceptions in this PR will be restricted on an opt-in basis, ie. the default mode will be enhanced
(while preserving the existing behavior).

The mechanism is controlled by the security/system property "jdk.includeInExceptions" which takes as value
a comma separated list of category names, which identify groups of exceptions where the exception
message may be enhanced. Any category not listed is "restricted" which means that potentially
sensitive information (such as hostnames, IP addresses, user identities) are excluded from the message text.

The changes to the java.security conf file describe the exact changes in terms of the categories now
supported and any changes in behavior.

Thanks,
Michael


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-8354677 to be approved

Issues

  • JDK-8348986: Improve coverage of enhanced exception messages (Enhancement - P3)
  • JDK-8354677: Improve coverage of enhanced exception messages (CSR)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23929

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 6, 2025

👋 Welcome back michaelm! 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

openjdk bot commented Mar 6, 2025

@Michael-Mc-Mahon 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:

8348986: Improve coverage of enhanced exception messages

Reviewed-by: dfuchs

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 10 new commits pushed to the master branch:

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 6, 2025
@openjdk
Copy link

openjdk bot commented Mar 6, 2025

@Michael-Mc-Mahon The following labels will be automatically applied to this pull request:

  • core-libs
  • net
  • nio
  • 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.

@mlbridge
Copy link

mlbridge bot commented Mar 6, 2025

@Michael-Mc-Mahon
Copy link
Member Author

/csr needed

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Mar 6, 2025
@openjdk
Copy link

openjdk bot commented Mar 6, 2025

@Michael-Mc-Mahon has indicated that a compatibility and specification (CSR) request is needed for this pull request.

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

@Michael-Mc-Mahon
Copy link
Member Author

here are a few files with IOException, UnknownHostException and MalformedURLException, which are worth reviewing for Exception that may have been missed

IOEXception:

open/src/java.base/share/classes/sun/net/www/protocol/https/HttpsClient.java Ln 562

open/src/java.base/share/classes/sun/security/x509/IPAddressName.java

open/src/java.base/share/classes/sun/security/x509/URIName.java

open/src/java.base/share/classes/sun/security/x509/RDN.java

open/src/java.base/share/classes/java/util/jar/JarFile.java

UnknownHostException

open/src/java.base/share/classes/sun/nio/ch/SocketAdaptor.java

open/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java

MalformedURLException

open/src/java.base/share/classes/sun/net/www/protocol/https/HttpsURLConnectionImpl.java

open/src/java.base/share/classes/java/net/URL.java — Invalid port

open/src/java.naming/share/classes/com/sun/jndi/ldap/LdapURL.java

open/src/java.naming/share/classes/com/sun/jndi/toolkit/url/Uri.java

open/src/java.rmi/share/classes/java/rmi/Naming.java

Thanks, I will take another look at all these cases and update any that I agree need to be included.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label May 29, 2025
String scheme = uri.getScheme();
if (scheme != null && !scheme.equals("rmi")) {
throw new MalformedURLException("invalid URL scheme: " + str);
throw newMalformedURLException("invalid URL scheme:", str);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
throw newMalformedURLException("invalid URL scheme:", str);
throw new MalformedURLException(formatMsg("invalid URL scheme%s", filterNonSocketInfo(str).prefixWith(": ").replaceWith(": rmi"));

@Michael-Mc-Mahon
Copy link
Member Author

Thanks for the suggestions. I have committed all of them except for two. One, I will modify in another way.

@Michael-Mc-Mahon
Copy link
Member Author

The last change to java.net.HostPortrange (renaming the constructor parameter) has caused a problem. The parameter is hiding a field of the same name. I need to fix that now.

if (index == -1)
throw new MalformedURLException("no !/ found in url spec:" + s);
throw new MalformedURLException(
formatMsg("no !/ found in url spec%s", filterJarName(s).prefixWith(": ")));
Copy link
Contributor

Choose a reason for hiding this comment

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

JMOD files can only be used at compile time and link time. So I think you can drop the changes jmod stream handler.

Comment on lines +1281 to +1282
# names, host names, or port numbers. By default, socket related exceptions
# have this information restricted (meaning the sensitive details are removed).
Copy link
Member

Choose a reason for hiding this comment

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

I found the "By default ..." sentence a little confusing, since other categories are also restricted by default. My initial thought is to just remove this sentence, as reading further will make it more clear that the hostInfoExclSocket category is the only one that is not restricted by default. Alternatively, you could flip the meaning of this sentence and say which exceptions are not restricted by default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair point. I think we can make this clearer with a small addition. I propose to add the following sentence after the one starting "By default ..."

# Exception messages relating to Jar files and exceptions containing user
# identity information are also restricted by default.

Copy link
Member

Choose a reason for hiding this comment

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

I would change "Jar" to "JAR" as I think that is the more common form and used in other places in this file. Looks fine otherwise.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 3, 2025
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jun 3, 2025
Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

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

Thanks for the last updates Michael. I believe we're good now!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 3, 2025
@Michael-Mc-Mahon
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jun 3, 2025

Going to push as commit b6f827e.
Since your change was applied there have been 14 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 3, 2025
@openjdk openjdk bot closed this Jun 3, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 3, 2025
@openjdk
Copy link

openjdk bot commented Jun 3, 2025

@Michael-Mc-Mahon Pushed as commit b6f827e.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

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

Development

Successfully merging this pull request may close these issues.

6 participants