Skip to content

Comments

Add bad1 servlet with script evaluation#4

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

Add bad1 servlet with script evaluation#4
kyle-semgrep wants to merge 1 commit intomainfrom
newblcktest

Conversation

@kyle-semgrep
Copy link
Owner

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

Implement a servlet that processes HTTP requests and evaluates scripts, potentially leading to code injection vulnerabilities.


Note

Introduces a new servlet mapped to /cmdi-00/BenchmarkTest00006 that reads a request header, decodes it, and evaluates JavaScript and JSF EL expressions built from it.

  • Servlet:
    • Adds bad1 with @WebServlet("/cmdi-00/BenchmarkTest00006") handling GET/POST.
    • Reads and URL-decodes BenchmarkTest00006 request header.
    • Uses ScriptEngine to eval a script constructed from the header and a hardcoded script.
    • Uses JSF ExpressionFactory/ValueExpression to build and evaluate expressions derived from the header.
    • Adds helpers: createTaintedScript(String) and evaluateExpression(String).

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

Implement a servlet that processes HTTP requests and evaluates scripts, potentially leading to code injection vulnerabilities.
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 +39 to +42
String script = createTaintedScript(param);

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

Choose a reason for hiding this comment

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

P1 Badge Stop evaluating request headers as JavaScript

Request header BenchmarkTest00006 is decoded and directly concatenated into script, which is then passed to engine.eval(...). A client can supply arbitrary JavaScript in that header to execute on the server, enabling remote code execution on every POST/GET request. Guarding the script creation with validation or avoiding eval on user input is needed to prevent this injection path.

Useful? React with 👍 / 👎.

Comment on lines +50 to +54
ELContext elContext = context.getELContext();
//ruleid: tainted-code-injection-from-http-request
ValueExpression vex = expressionFactory.createValueExpression(elContext, "expression" + param, String.class);

String result = evaluateExpression("expression" + param);

Choose a reason for hiding this comment

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

P1 Badge Avoid creating JSF expressions from untrusted headers

The same unvalidated header value is appended to an EL string and fed into ExpressionFactory.createValueExpression, with evaluateExpression executing the expression. An attacker can craft the header to run arbitrary server-side EL code whenever this servlet handles a request. Sanitize or reject user-supplied data before building EL expressions to avoid expression injection.

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 is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on December 18

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: User input directly evaluated as JavaScript code

User-controlled input from the HTTP header BenchmarkTest00006 flows through createTaintedScript() and is passed directly to engine.eval() without sanitization. This allows attackers to execute arbitrary JavaScript code on the server by crafting malicious header values, leading to remote code execution.

Additional Locations (1)

Fix in Cursor Fix in Web

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);
Copy link

Choose a reason for hiding this comment

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

Bug: User input evaluated in Expression Language injection

User-controlled input from the HTTP header is concatenated into JSF Expression Language strings and passed to createValueExpression() and evaluateExpression(). An attacker can inject malicious EL expressions that get evaluated, potentially leading to remote code execution, data access, or server compromise through EL injection attacks.

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