Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6826789

SecureClassLoader should not use CodeSource URLs as HashMap keys

    Details

    • Subcomponent:
    • Resolved In Build:
      b70
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Backports

        Description

        SecureClassLoader.getProtectionDomain uses HashMap<CodeSource> to cache protection domains to speed up their construction. CodeSource.hashCode() uses URL.hashcode() and CodeSource.equals() uses URL.equals().
        However, these URL may cause DNS lookups which are expensive if everything is cached.

        We should avoid them, e.g. by using URI.

          Issue Links

            Activity

            Hide
            mullan Sean Mullan added a comment -
            BT2:EVALUATION

            This is difficult to fix without breaking compatibility. For example, the following two CodeSource URLs could be equal after name resolution:

            http://xxx.yyy.foo.com
            http://xxx.yyy

            Changing this could break a bunch of stuff as these CodeSources would now be placed into separate ProtectionDomains.

            It's possible we may be able to look at this from a different angle, and only do name resolution if a CodeSource is granted something other than AllPermission or the default sandbox permissions, or whenever policy processing is enabled in Plugin (usePolicy=true). But I need to think about it some more.
            Show
            mullan Sean Mullan added a comment - BT2:EVALUATION This is difficult to fix without breaking compatibility. For example, the following two CodeSource URLs could be equal after name resolution: http://xxx.yyy.foo.com http://xxx.yyy Changing this could break a bunch of stuff as these CodeSources would now be placed into separate ProtectionDomains. It's possible we may be able to look at this from a different angle, and only do name resolution if a CodeSource is granted something other than AllPermission or the default sandbox permissions, or whenever policy processing is enabled in Plugin (usePolicy=true). But I need to think about it some more.
            Hide
            mullan Sean Mullan added a comment -
            Changing to an enhancement, since this is a performance enhancement.
            Show
            mullan Sean Mullan added a comment - Changing to an enhancement, since this is a performance enhancement.
            Hide
            mullan Sean Mullan added a comment - - edited
            It turns out that fixing this is straightforward by converting the URL to a String (using sun.net.util.URLUtil.urlNoFragString) and using that as a key to the HashMap. It does mean that URLs that are equivalent after name resolution may be placed in separate ProtectionDomains, but it is not a compatibility or security issue because the URLs will later be canonicalized (and resolved through the name service) by the Policy provider implementation before granting permissions.
            Show
            mullan Sean Mullan added a comment - - edited It turns out that fixing this is straightforward by converting the URL to a String (using sun.net.util.URLUtil.urlNoFragString) and using that as a key to the HashMap. It does mean that URLs that are equivalent after name resolution may be placed in separate ProtectionDomains, but it is not a compatibility or security issue because the URLs will later be canonicalized (and resolved through the name service) by the Policy provider implementation before granting permissions.
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/f36fd9bd1dcd
            User: mullan
            Date: 2015-06-12 16:52:05 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/f36fd9bd1dcd User: mullan Date: 2015-06-12 16:52:05 +0000
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/f36fd9bd1dcd
            User: lana
            Date: 2015-06-20 18:08:09 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/f36fd9bd1dcd User: lana Date: 2015-06-20 18:08:09 +0000

              People

              • Assignee:
                mullan Sean Mullan
                Reporter:
                igor Igor Nekrestyanov (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: