Skip to content

Conversation

ggolawski
Copy link
Contributor

@ggolawski ggolawski commented Apr 19, 2020

This PR adds a query to detect OGNL injections. It flags the code where user-provided OGNL expression is evaluated (getValue, setValue and callMethod in the below examples):

public void testOgnlParseExpression(@RequestParam String expr) throws Exception {
    Object tree = Ognl.parseExpression(expr);
    Ognl.getValue(tree, new HashMap<>(), new Object());
    Ognl.setValue(tree, new HashMap<>(), new Object());

    Node node = (Node) tree;
    node.getValue(null, new Object());
    node.setValue(null, new Object(), new Object());
  }

  public void testOgnlCompileExpression(@RequestParam String expr) throws Exception {
    Node tree = Ognl.compileExpression(null, new Object(), expr);
    Ognl.getValue(tree, new HashMap<>(), new Object());
    Ognl.setValue(tree, new HashMap<>(), new Object());

    tree.getValue(null, new Object());
    tree.setValue(null, new Object(), new Object());
  }

  public void testOgnlDirectlyToGetSet(@RequestParam String expr) throws Exception {
    Ognl.getValue(expr, new Object());
    Ognl.setValue(expr, new HashMap<>(), new Object());
  }

  public void testStruts(@RequestParam String expr) throws Exception {
    OgnlUtil ognl = new OgnlUtil();
    ognl.getValue(expr, new HashMap<>(), new Object());
    ognl.setValue(expr, new HashMap<>(), new Object(), new Object());
    new OgnlUtil().callMethod(expr, new HashMap<>(), new Object());
  }

Evaluation of unvalidated expressions can let attacker to modify Java objects' properties or execute arbitrary code.

The tests and required qlpack.yml in src/experimental and test/experimental are also included.

@ggolawski ggolawski requested a review from a team as a code owner June 27, 2020 16:30
@aschackmull aschackmull merged commit 13cb853 into github:master Jun 30, 2020
@ggolawski ggolawski deleted the ognl-injection branch July 13, 2020 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants