druid-javascript-injection-fix
How to patch the Apache Druid 0.20.0 JavaScript sandbox bypass vulnerability. Use this skill when fixing CVE in Druid where authenticated attackers can execute arbitrary code through malicious JavaScript payloads via the sampler endpoint. The vulnerability allows empty key "" in filter specifications to bypass JavaScript security settings.
- License 许可
- MIT
- 最近更新
- 2026-10-02
- Stars
- ★ 93
- Forks
- 8
01 前言 Front Matter
- name
- druid-javascript-injection-fix
- description
- How to patch the Apache Druid 0.20.0 JavaScript sandbox bypass vulnerability. Use this skill when fixing CVE in Druid where authenticated attackers can execute arbitrary code through malicious JavaScript payloads via the sampler endpoint. The vulnerability allows empty key "" in filter specifications to bypass JavaScript security settings.
03 SKILL.md 正文
Fixing Apache Druid JavaScript Injection Vulnerability
Vulnerability Overview
Apache Druid 0.20.0 contains a critical vulnerability where authenticated attackers can execute arbitrary Java code through malicious JavaScript payloads. The vulnerability exists in the /druid/indexer/v1/sampler endpoint where the empty key "" in filter specifications can bypass JavaScript security settings.
Affected Component: Druid indexer sampler - specifically the JavaScriptFilter validation
Root Cause: Insufficient validation of filter specification keys before JavaScript execution
Identifying the Vulnerable Code
The vulnerability is typically found in:
druid-core/src/main/java/org/apache/druid/query/filter/JavaScriptFilter.java- Filter parsing/validation logic that processes the
transformSpec.filterJSON
Look for:
- JavaScript filter implementations that execute user-provided functions
- Lack of validation on the filter specification keys
- Missing checks for suspicious keys (especially empty strings
"")
Patch Strategy
1. Validate Filter Specification Keys
Add validation to reject or sanitize suspicious keys in the filter specification:
// Reject empty keys or keys that bypass security
if (filterSpec.containsKey("") || filterSpec.containsKey(null)) {
throw new IllegalArgumentException("Invalid filter specification: contains empty or null keys");
}
2. Strengthen JavaScript Context Setup
Ensure the JavaScript execution context:
- Explicitly disables dangerous Java interop
- Validates function syntax before execution
- Runs in a restricted scope
// Example: Check for java.lang.Runtime references
String function = getFunction();
if (function.contains("java.lang.Runtime") ||
function.contains("java.lang.ProcessBuilder")) {
throw new IllegalArgumentException("JavaScript functions cannot access Java runtime");
}
3. Validate Filter Configuration Structure
Before executing any JavaScript filter, validate the complete filter specification:
- All keys should be expected, known keys
- Nested objects should follow the documented schema
- Reject any non-standard keys
Testing the Patch
After patching, verify:
-
Legitimate requests work:
- Standard JavaScript filters execute correctly
- Filters with valid syntax pass validation
- Normal sampler operations complete successfully
-
Exploit attempts are blocked:
- Requests with empty key
""are rejected - Java Runtime calls in JavaScript are blocked
- Invalid filter specifications throw clear errors
- Error messages don't leak sensitive information
- Requests with empty key
Common Patch Locations in Druid
druid-core/src/main/java/org/apache/druid/query/filter/JavaScriptFilter.javadruid-indexing-service/src/main/java/org/apache/druid/indexing/*/SamplerResource.javadruid-core/src/main/java/org/apache/druid/query/filter/FilterJsonHolder.java(if parsing logic here)
Patch File Format
Create patches using git diff to generate unified diff format:
git diff > fix-javascript-injection.patch
Patches should be applied to the repository with:
cd /root/druid
git apply /root/patches/fix-javascript-injection.patch
or
cd /root/druid
git am /root/patches/fix-javascript-injection.patch
04 同仓库更多 Skills
object_counter
Count occurrences of an object in the image using computer vision algorithm.
travel-planning-workflow
Invoke this skill when performing travel planning. It defines a structured workflow for generating itineraries. Following this workflow is essential to ensure the final plan satisfies user requirements.
bundled-dataset-search-tool
invoke this skill when you need to perform database search for travel planning. This skill provides some useful pre-packaged tools to look up accommodations, attractions, cities, driving distance, flights, and restaurants from the bundled dataset.
glm-output
Output-processing guidance for GLM tasks. Especially useful after glm-basics and glm-calibration when you need verifier-matching metrics from output.nc and a final /root/metrics.json.
glm-calibration
Calibration guidance for GLM tasks. Often most effective after glm-basics has clarified the setup; glm-output is the companion skill for exact final metric computation.
glm-basics
A good starting point for GLM calibration tasks. Use to inspect glm3.nml, confirm how GLM runs, and identify the relevant files before moving on to calibration and output evaluation.