Skip to content

Commit

Permalink
Allow jar:nested: URIs in default security manager (apple#895)
Browse files Browse the repository at this point in the history
Nested jars built by spring boot can possibly represent classpath
resource URIs as "jar:nested:".

This changes Pkl to by default trust them with the same level as
modulepath URIs.
  • Loading branch information
bioball authored Jan 22, 2025
1 parent 75bd214 commit 257bd6f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkl-core/src/main/java/org/pkl/core/SecurityManagers.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,8 +38,10 @@ private SecurityManagers() {}
List.of(
Pattern.compile("repl:"),
Pattern.compile("file:"),

// for evaluating URLs returned by `Class(Loader).getResource()`
Pattern.compile("jar:file:"),
Pattern.compile("jar:nested:"),
Pattern.compile("modulepath:"),
Pattern.compile("https:"),
Pattern.compile("pkl:"),
Expand Down Expand Up @@ -78,9 +80,15 @@ private static int getDefaultTrustLevel(URI uri) {
return switch (uri.getScheme()) {
case "repl" -> 40;
case "file" -> uri.getHost() == null ? 30 : 10;
case "jar" ->
case "jar" -> {
if (uri.getSchemeSpecificPart().startsWith("nested:")) {
// treat jar:nested: URIs as same level as modulepath URIs
yield 20;
} else {
// use trust level of embedded URL
getDefaultTrustLevel(URI.create(uri.toString().substring(4)));
yield getDefaultTrustLevel(URI.create(uri.toString().substring(4)));
}
}
case "modulepath" -> 20;
case "pkl" -> 0;
default -> 10;
Expand Down

0 comments on commit 257bd6f

Please sign in to comment.