Skip to content

Commit 8f00932

Browse files
committed
Merge remote-tracking branch 'origin/master-1.19-lts' into master-1.20-lts
2 parents b27b4a5 + ce8e9bb commit 8f00932

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
As always, don't forget to backup your world before updating!
2+
Requires CyclopsCore version 1.19.0 or higher.
3+
4+
Changes:
5+
* Restrict access to parts of the Java API
6+
They can still be enabled if desired by the server admin.

src/main/java/org/cyclops/integratedscripting/GeneralConfig.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,40 @@ public class GeneralConfig extends DummyConfig {
2222
@ConfigurableProperty(category = "general", comment = "The minimum number of ticks inbetween sending a script change packet from client to server.", minimalValue = 0, configLocation = ModConfig.Type.SERVER)
2323
public static int terminalScriptingClientSyncTickInterval = 20;
2424

25-
@ConfigurableProperty(category = "general", comment = "If new processes can be created from guest languages.", configLocation = ModConfig.Type.SERVER)
25+
@ConfigurableProperty(category = "general", comment = "If new processes can be created from guest languages. Only enable this on private servers and if you know what you are doing.", configLocation = ModConfig.Type.SERVER)
2626
public static boolean graalAllowCreateProcess = false;
27-
@ConfigurableProperty(category = "general", comment = "If new threads can be created from guest languages.", configLocation = ModConfig.Type.SERVER)
27+
@ConfigurableProperty(category = "general", comment = "If new threads can be created from guest languages. Only enable this on private servers and if you know what you are doing.", configLocation = ModConfig.Type.SERVER)
2828
public static boolean graalAllowCreateThread = false;
29-
@ConfigurableProperty(category = "general", comment = "If IO is allowed from guest languages.", configLocation = ModConfig.Type.SERVER)
29+
@ConfigurableProperty(category = "general", comment = "If IO is allowed from guest languages. Only enable this on private servers and if you know what you are doing.", configLocation = ModConfig.Type.SERVER)
3030
public static boolean graalAllowIo = false;
31-
@ConfigurableProperty(category = "general", comment = "If host class loading is allowed from guest languages.", configLocation = ModConfig.Type.SERVER)
31+
@ConfigurableProperty(category = "general", comment = "If host class loading is allowed from guest languages. Only enable this on private servers and if you know what you are doing.", configLocation = ModConfig.Type.SERVER)
3232
public static boolean graalAllowHostClassLoading = false;
33-
@ConfigurableProperty(category = "general", comment = "If experimental options can be used in guest languages.", configLocation = ModConfig.Type.SERVER)
33+
@ConfigurableProperty(category = "general", comment = "If experimental options can be used in guest languages. Only enable this on private servers and if you know what you are doing.", configLocation = ModConfig.Type.SERVER)
3434
public static boolean graalAllowExperimentalOptions = false;
35-
@ConfigurableProperty(category = "general", comment = "If environment variables can be accessed from guest languages.", configLocation = ModConfig.Type.SERVER)
35+
@ConfigurableProperty(category = "general", comment = "If environment variables can be accessed from guest languages. Only enable this on private servers and if you know what you are doing.", configLocation = ModConfig.Type.SERVER)
3636
public static boolean graalAllowEnvironment = false;
37-
@ConfigurableProperty(category = "general", comment = "If the native interface can be accessed from guest languages.", configLocation = ModConfig.Type.SERVER)
37+
@ConfigurableProperty(category = "general", comment = "If the native interface can be accessed from guest languages. Only enable this on private servers and if you know what you are doing.", configLocation = ModConfig.Type.SERVER)
3838
public static boolean graalAllowNative = false;
39+
@ConfigurableProperty(category = "general", comment = "If all Java public constructors should be accessible. Only enable this on private servers and if you know what you are doing.", configLocation = ModConfig.Type.SERVER)
40+
public static boolean graalAllowHostPublicAccess = false;
41+
@ConfigurableProperty(category = "general", comment = "Allow guest languages to implement any Java interface. Only enable this on private servers and if you know what you are doing.", configLocation = ModConfig.Type.SERVER)
42+
public static boolean graalAllowHostAllImplementations = false;
43+
@ConfigurableProperty(category = "general", comment = "Allow guest languages to implement (extend) any Java class. Only enable this on private servers and if you know what you are doing.", configLocation = ModConfig.Type.SERVER)
44+
public static boolean graalAllowHostAllClassImplementations = false;
45+
@ConfigurableProperty(category = "general", comment = "Allows the guest application to access arrays as values with array elements.", configLocation = ModConfig.Type.SERVER)
46+
public static boolean graalAllowHostArrayAccess = true;
47+
@ConfigurableProperty(category = "general", comment = "Allows the guest application to access lists as values with array elements and iterators.", configLocation = ModConfig.Type.SERVER)
48+
public static boolean graalAllowHostListAccess = true;
49+
@ConfigurableProperty(category = "general", comment = "Allows the guest application to access java. nio. ByteBuffers as values with buffer elements.", configLocation = ModConfig.Type.SERVER)
50+
public static boolean graalAllowHostBufferAccess = true;
51+
@ConfigurableProperty(category = "general", comment = "Allows the guest application to access iterables as values with iterators.", configLocation = ModConfig.Type.SERVER)
52+
public static boolean graalAllowHostIterableAccess = true;
53+
@ConfigurableProperty(category = "general", comment = "Allows the guest application to access iterators as iterator values.", configLocation = ModConfig.Type.SERVER)
54+
public static boolean graalAllowHostIteratorAccess = true;
55+
@ConfigurableProperty(category = "general", comment = "Allows the guest application to access map as hash values.", configLocation = ModConfig.Type.SERVER)
56+
public static boolean graalAllowHostMapAccess = true;
57+
@ConfigurableProperty(category = "general", comment = "Allows the guest application to inherit access to allowed methods, i. e. implementations of allowed abstract and interface methods and overrides of allowed concrete methods. Only enable this on private servers and if you know what you are doing.", configLocation = ModConfig.Type.SERVER)
58+
public static boolean graalAllowHostAccessInheritance = false;
3959
@ConfigurableProperty(category = "general", comment = "The maximum number of statements that can be executed in one evaluation. This is to avoid infinite loops or very complex programs. Set to -1 to disable limit (not recommended).", configLocation = ModConfig.Type.SERVER, minimalValue = -1)
4060
public static int graalStatementLimit = 16384;
4161
@ConfigurableProperty(category = "general", comment = "The maximum number of lines in stdout and stderr script log files. Set to -1 to disable limit.", minimalValue = -1, configLocation = ModConfig.Type.SERVER)

src/main/java/org/cyclops/integratedscripting/evaluate/ScriptHelpers.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
import org.cyclops.integratedscripting.GeneralConfig;
99
import org.cyclops.integratedscripting.api.evaluate.translation.IEvaluationExceptionFactory;
1010
import org.cyclops.integratedscripting.evaluate.translation.ValueTranslators;
11-
import org.graalvm.polyglot.Context;
12-
import org.graalvm.polyglot.Engine;
13-
import org.graalvm.polyglot.EnvironmentAccess;
14-
import org.graalvm.polyglot.HostAccess;
15-
import org.graalvm.polyglot.ResourceLimits;
16-
import org.graalvm.polyglot.Value;
11+
import org.graalvm.polyglot.*;
1712

1813
import javax.annotation.Nullable;
1914
import java.nio.file.Path;
@@ -42,7 +37,18 @@ public static Context createBaseContext(@Nullable Function<Context.Builder, Cont
4237
.allowExperimentalOptions(GeneralConfig.graalAllowExperimentalOptions)
4338
.allowEnvironmentAccess(GeneralConfig.graalAllowEnvironment ? EnvironmentAccess.INHERIT : EnvironmentAccess.NONE)
4439
.allowNativeAccess(GeneralConfig.graalAllowNative)
45-
.allowHostAccess(HostAccess.ALL)
40+
.allowHostAccess(HostAccess.newBuilder()
41+
.allowPublicAccess(GeneralConfig.graalAllowHostPublicAccess)
42+
.allowAllImplementations(GeneralConfig.graalAllowHostAllImplementations)
43+
.allowAllClassImplementations(GeneralConfig.graalAllowHostAllClassImplementations)
44+
.allowArrayAccess(GeneralConfig.graalAllowHostArrayAccess)
45+
.allowListAccess(GeneralConfig.graalAllowHostListAccess)
46+
.allowBufferAccess(GeneralConfig.graalAllowHostBufferAccess)
47+
.allowIterableAccess(GeneralConfig.graalAllowHostIterableAccess)
48+
.allowIteratorAccess(GeneralConfig.graalAllowHostIteratorAccess)
49+
.allowMapAccess(GeneralConfig.graalAllowHostMapAccess)
50+
.allowAccessInheritance(GeneralConfig.graalAllowHostAccessInheritance)
51+
.build())
4652
.allowInnerContextOptions(false);
4753
if (GeneralConfig.graalStatementLimit > 0) {
4854
contextBuilder = contextBuilder.resourceLimits(ResourceLimits.newBuilder()

0 commit comments

Comments
 (0)