Skip to content

Commit 0df0776

Browse files
committed
Revert "simplify toRealPath"
This reverts commit 8cc0a71.
1 parent 8cc0a71 commit 0df0776

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/api/ElasticsearchEntitlementChecker.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.entitlement.runtime.policy.PolicyManager;
1515

1616
import java.io.File;
17+
import java.io.IOException;
1718
import java.io.InputStream;
1819
import java.io.PrintStream;
1920
import java.io.PrintWriter;
@@ -1374,8 +1375,21 @@ public void checkType(Class<?> callerClass, FileStore that) {
13741375

13751376
@Override
13761377
public void checkPathToRealPath(Class<?> callerClass, Path that, LinkOption... options) {
1377-
// We deliberately don't check read permissions on the returned read path if following links.
1378-
// While this allows for an "exists" check on the real target, any file operation still require adequate read permissions.
1378+
if (EntitlementChecker.class.isAssignableFrom(callerClass)) {
1379+
return;
1380+
}
1381+
1382+
boolean followLinks = true;
1383+
for (LinkOption option : options) {
1384+
if (option == LinkOption.NOFOLLOW_LINKS) {
1385+
followLinks = false;
1386+
}
1387+
}
1388+
if (followLinks) {
1389+
try {
1390+
policyManager.checkFileRead(callerClass, that.toRealPath());
1391+
} catch (IOException e) {}
1392+
}
13791393
policyManager.checkFileRead(callerClass, that);
13801394
}
13811395

0 commit comments

Comments
 (0)