cwe-94-code-injection

Replace dynamic ScriptEngine.eval() calls with predefined safe operations in Java.

3|1|Updated Mar 6, 2026
One-click install
npx skills add https://github.com/DevelopersCoffee/java-cwe-security-skills --skill cwe-94-code-injection
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cwe-94-code-injection
Source: https://github.com/DevelopersCoffee/java-cwe-security-skills/tree/main/cwe-94-code-injection
Command: npx skills add https://github.com/DevelopersCoffee/java-cwe-security-skills --skill cwe-94-code-injection

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses critical security vulnerabilities in Java code that arise from executing untrusted or dynamically generated code, preventing potential system compromise.

Core Features & Use Cases

  • Code Injection Remediation: Provides deterministic fixes for CWE-94 (Code Injection) vulnerabilities.
  • Secure Coding Practices: Guides developers to avoid executing user-provided scripts directly.
  • Use Case: When a SAST tool flags a ScriptEngine.eval() call with user input, this Skill can be applied to refactor the code to use a safe, predefined set of operations instead.

Quick Start

Apply the cwe-94-code-injection skill to secure the provided Java code snippet.

Frequently Asked Questions about cwe-94-code-injection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix CWE-94 code injection vulnerabilities flagged by SAST tools in Java?

To fix CWE-94 code injection vulnerabilities in Java, replace dynamic code execution like ScriptEngine.eval() with predefined, safe operations. This remediates the risk by ensuring user input never executes directly as code.

What is code injection in Java ScriptEngine.eval() calls?

Code injection occurs when untrusted input is passed directly into ScriptEngine.eval(), allowing arbitrary code execution. This critical vulnerability can lead to full system compromise if user-controlled data is evaluated as executable script.

How do I securely remediate dynamic script execution without breaking Java functionality?

Secure dynamic script execution by replacing eval calls with deterministic, safe operations mapping to a predefined set. If dynamic scripting is strictly unavoidable, execute the scripts strictly within heavily sandboxed environments to limit access.

Do I need a sandboxed environment to run dynamic Java scripts safely?

You need a sandboxed environment to run dynamic Java scripts safely only when dynamic scripting is absolutely unavoidable. The primary remediation strategy is to entirely replace ScriptEngine.eval() with predefined, safe operations.

Can I pass user input directly to ScriptEngine.eval() if I validate it first?

Passing user input directly to ScriptEngine.eval() remains insecure even with validation. You must refactor the application to avoid executing user-provided scripts directly, replacing the dynamic evaluation with predefined, safe operations.

Why does SAST flag my Java ScriptEngine.eval() method as a code injection risk?

SAST flags ScriptEngine.eval() as a code injection risk because the method executes dynamically generated code. If untrusted or user-controlled input reaches this evaluator, it creates a CWE-94 vulnerability allowing potential system compromise.