Skip to content

JavascriptFunctionDefinition` "looks-like-JSON" heuristic enables JS injection in the polyglot engine #4326

Closed

Description

@ruispereira

Affected version: 26.4.2 (confirmed still present in 26.5.1)
Component: com.arcadedb.function.polyglot.JavascriptFunctionDefinition

Summary

The function string-concatenates user-controlled arguments into JavaScript source, then calls polyglotEngine.eval(...). A heuristic skips escaping when the value "looks like JSON" — i.e., opens with {/[ and closes with }/]. Any caller able to influence such a string argument can inject arbitrary JavaScript.

Code

engine/com/arcadedb/function/polyglot/JavascriptFunctionDefinition.java:123–129

final boolean looksLikeJson =
    (trimmed.startsWith("{") && trimmed.endsWith("}") && trimmed.length() > 2 && trimmed.contains(":")) ||
    (trimmed.startsWith("[") && trimmed.endsWith("]") && trimmed.length() > 2);
final boolean alreadyQuoted =
    (trimmed.startsWith("'") && trimmed.endsWith("'") && trimmed.length() > 1);

if (looksLikeJson || alreadyQuoted) {
  // Pass through as-is for JSON-like objects/arrays or already-quoted strings
  return str;
}

Impact

Arbitrary JavaScript execution inside the polyglot engine, e.g. {a:require('child_process').execSync('id'),b:1}. Defeats every sandbox
boundary the engine attempts.

Suggested fix

Always JSON-encode (or JS-string-escape) the value. If structured data must pass through, marshal as ProxyObject / ProxyArray and bind it as a Value parameter — never via source concatenation.

Activity

  1. self-assigned this
    on May 25, 2026
  2. added this to the 26.6.1 milestone on May 26, 2026
  3. added a commit that references this issue on May 26, 2026
  4. added a commit that references this issue on Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions