Security: Unsandboxed JSR223 Script Execution Enables Arbitrary Code Execution#858
Open
Nam0101 wants to merge 1 commit into
Conversation
JSR223ScriptExecutor.load() compiles arbitrary script strings via Compilable.compile() and execute() runs them via eval() with no ClassFilter, sandbox, or restricted ScriptContext. The bindings expose `_meta`, `args`, and `extParam`, but Nashorn/JS engines by default give scripts full access to Java reflection (e.g., Java.type('java.lang.Runtime').getRuntime().exec(...)). Comments in Operation.java explicitly warn 'JDK 8~13 可用自带 Nashorn 这个 js 引擎,注意配置 ClassFilter 防脚本注入攻击', but no ClassFilter is configured here. If script content is sourced from a database row, request payload, or any user-influenced channel (which the IF/CODE Operation suggests), this becomes RCE.
Affected files: JSR223ScriptExecutor.java
Signed-off-by: Nguyen Van Nam <nam.nv205106@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Security: Unsandboxed JSR223 Script Execution Enables Arbitrary Code Execution
Problem
Severity:
Critical| File:APIJSONORM/src/main/java/apijson/orm/script/JSR223ScriptExecutor.java:L41JSR223ScriptExecutor.load() compiles arbitrary script strings via Compilable.compile() and execute() runs them via eval() with no ClassFilter, sandbox, or restricted ScriptContext. The bindings expose
_meta,args, andextParam, but Nashorn/JS engines by default give scripts full access to Java reflection (e.g., Java.type('java.lang.Runtime').getRuntime().exec(...)). Comments in Operation.java explicitly warn 'JDK 8~13 可用自带 Nashorn 这个 js 引擎,注意配置 ClassFilter 防脚本注入攻击', but no ClassFilter is configured here. If script content is sourced from a database row, request payload, or any user-influenced channel (which the IF/CODE Operation suggests), this becomes RCE.Solution
For Nashorn, instantiate via NashornScriptEngineFactory.getScriptEngine(ClassFilter) with a strict allowlist (deny java.lang.Runtime, ProcessBuilder, java.io., java.net., java.lang.reflect.*, java.lang.Class, etc.). For GraalJS, set polyglot.js.allowHostAccess=false, allowHostClassLookup=false, allowIO=false, allowCreateThread=false, and run with a resource-limited Context. Validate that scripts come only from trusted admin sources, and document this requirement prominently. Consider disabling script execution by default (AbstractFunctionParser.ENABLE_SCRIPT_FUNCTION = false).
Changes
APIJSONORM/src/main/java/apijson/orm/script/JSR223ScriptExecutor.java(modified)Testing
Generated by ContribAI v6.8.0