Skip to content

Commit

Permalink
Fix regression Together-Java#22
Browse files Browse the repository at this point in the history
The security manager incorrectly assumed executed methods were his and
allowed unfiltered access
  • Loading branch information
I-Al-Istannen committed Feb 16, 2019
1 parent 98f33fc commit 3327c9a
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import java.security.Permission;
import java.util.Arrays;

/**
* The {@link SecurityManager} used to limit JShell's permissions.
*/
public class JshellSecurityManager extends SecurityManager {

@Override
public void checkPermission(Permission perm) {
if (!comesFromBotCode()) {
if (comesFromMe()) {
return;
}

Expand All @@ -27,10 +30,13 @@ private boolean comesFromJshell() {
.anyMatch(aClass -> aClass.getName().contains("REPL"));
}

private boolean comesFromBotCode() {
private boolean comesFromMe() {
return Arrays.stream(getClassContext())
// one frame for this method, one frame for the call to checkPermission
.skip(2)
.anyMatch(aClass -> aClass == getClassContext()[0]);
// see if the security manager appears anywhere else in the context. If so, we initiated
// the call
.anyMatch(aClass -> aClass == getClass());
}

private boolean containsClass(String name) {
Expand Down

0 comments on commit 3327c9a

Please sign in to comment.