Skip to content

Comments

Implement bad1 servlet with tainted script evaluation#3

Open
kyle-semgrep wants to merge 1 commit intomainfrom
blcktest3
Open

Implement bad1 servlet with tainted script evaluation#3
kyle-semgrep wants to merge 1 commit intomainfrom
blcktest3

Conversation

@kyle-semgrep
Copy link
Owner

@kyle-semgrep kyle-semgrep commented Dec 11, 2025

Added a servlet that demonstrates potential code injection vulnerabilities through HTTP request headers.


Note

Adds bad1 servlet that reads a request header, URL-decodes it, and evaluates it via Java ScriptEngine and JSF EL, with helper methods and a hardcoded eval example.

  • Backend / Servlet:
    • New servlet bad1 at @WebServlet("/cmdi-00/BenchmarkTest00006").
    • Reads BenchmarkTest00006 header, URL-decodes to param, sets text/html content type.
    • Evaluates param-derived script via ScriptEngine (engine.eval(script)) and builds/evaluates JSF EL using ExpressionFactory/ValueExpression.
    • Includes hardcoded engine.eval("this is a hardcoded script") example.
    • Adds helpers: createTaintedScript(String) and evaluateExpression(String).

Written by Cursor Bugbot for commit 9858939. This will update automatically on new commits. Configure here.

Added a servlet that demonstrates potential code injection vulnerabilities through HTTP request headers.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +36 to +38
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Import javax.script classes for ScriptEngine usage

Compilation will fail here because ScriptEngineManager and ScriptEngine are referenced without any corresponding javax.script imports. With only the servlet imports present at the top of the file, javac reports cannot find symbol for these types, so the servlet cannot build until the imports are added or fully qualified names are used.

Useful? React with 👍 / 👎.

Comment on lines +48 to +52
FacesContext context = FacesContext.getCurrentInstance();
ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
ELContext elContext = context.getELContext();
//ruleid: tainted-code-injection-from-http-request
ValueExpression vex = expressionFactory.createValueExpression(elContext, "expression" + param, String.class);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Missing JSF/EL imports for expression evaluation

The code constructs FacesContext, ExpressionFactory, ELContext, and ValueExpression but no imports for the JSF/EL packages are declared. As written, javac will error on these symbols and prevent the servlet from compiling until the appropriate javax.faces.* and javax.el.* imports are added.

Useful? React with 👍 / 👎.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

String script = createTaintedScript(param);

//ruleid: tainted-code-injection-from-http-request
engine.eval(script); //Bad things can happen here.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Script engine evaluates untrusted user input from headers

User-controlled input from the HTTP header BenchmarkTest00006 flows through createTaintedScript() and is evaluated via engine.eval(), enabling arbitrary JavaScript code injection. Similarly, the same tainted param is concatenated into EL expressions via createValueExpression(), allowing Expression Language injection attacks. An attacker can execute arbitrary code on the server by crafting malicious header values.

Additional Locations (2)

Fix in Cursor Fix in Web

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