|
18 | 18 | import org.apache.tika.parser.ParserDecorator; |
19 | 19 | import org.elasticsearch.SpecialPermission; |
20 | 20 | import org.elasticsearch.bootstrap.FilePermissionUtils; |
| 21 | +import org.elasticsearch.core.Booleans; |
21 | 22 | import org.elasticsearch.core.PathUtils; |
22 | 23 | import org.elasticsearch.core.SuppressForbidden; |
23 | 24 | import org.elasticsearch.jdk.JarHell; |
| 25 | +import org.elasticsearch.jdk.RuntimeVersionFeature; |
24 | 26 |
|
25 | 27 | import java.io.ByteArrayInputStream; |
26 | 28 | import java.io.IOException; |
@@ -122,15 +124,22 @@ static String parse(final byte content[], final Metadata metadata, final int lim |
122 | 124 |
|
123 | 125 | // apply additional containment for parsers, this is intersected with the current permissions |
124 | 126 | // its hairy, but worth it so we don't have some XML flaw reading random crap from the FS |
125 | | - private static final AccessControlContext RESTRICTED_CONTEXT = new AccessControlContext( |
126 | | - new ProtectionDomain[] { new ProtectionDomain(null, getRestrictedPermissions()) } |
127 | | - ); |
| 127 | + private static final AccessControlContext RESTRICTED_CONTEXT = isUsingSecurityManager() |
| 128 | + ? new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, getRestrictedPermissions()) }) |
| 129 | + : null; |
| 130 | + |
| 131 | + private static boolean isUsingSecurityManager() { |
| 132 | + boolean entitlementsEnabled = Booleans.parseBoolean(System.getProperty("es.entitlements.enabled"), false) |
| 133 | + || RuntimeVersionFeature.isSecurityManagerAvailable() == false; |
| 134 | + return entitlementsEnabled == false; |
| 135 | + } |
128 | 136 |
|
129 | 137 | // compute some minimal permissions for parsers. they only get r/w access to the java temp directory, |
130 | 138 | // the ability to load some resources from JARs, and read sysprops |
131 | 139 | @SuppressForbidden(reason = "adds access to tmp directory") |
132 | 140 | static PermissionCollection getRestrictedPermissions() { |
133 | 141 | Permissions perms = new Permissions(); |
| 142 | + |
134 | 143 | // property/env access needed for parsing |
135 | 144 | perms.add(new PropertyPermission("*", "read")); |
136 | 145 | perms.add(new RuntimePermission("getenv.TIKA_CONFIG")); |
|
0 commit comments