Skip to content

Security: Unsandboxed JSR223 Script Execution Enables Arbitrary Code Execution#858

Open
Nam0101 wants to merge 1 commit into
Tencent:masterfrom
Nam0101:contribai/fix/security/unsandboxed-jsr223-script-execution-enab
Open

Security: Unsandboxed JSR223 Script Execution Enables Arbitrary Code Execution#858
Nam0101 wants to merge 1 commit into
Tencent:masterfrom
Nam0101:contribai/fix/security/unsandboxed-jsr223-script-execution-enab

Conversation

@Nam0101
Copy link
Copy Markdown

@Nam0101 Nam0101 commented May 16, 2026

Summary

Security: Unsandboxed JSR223 Script Execution Enables Arbitrary Code Execution

Problem

Severity: Critical | File: APIJSONORM/src/main/java/apijson/orm/script/JSR223ScriptExecutor.java:L41

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.

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

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

Generated by ContribAI v6.8.0

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant