Skip to content

False negative in Java rule command-injection-formatted-runtime-call #3763

@tacu22

Description

@tacu22

Describe the bug

The pattern in Java command injection rule has a common false negative:

import java.lang.Runtime;

class Cls {
    public Cls(String input) {
        Runtime r = Runtime.getRuntime();
        // ruleid: command-injection-formatted-runtime-call
        r.exec("/bin/sh -c some_tool" + input);   // it is ok
    }
}

class Cls {
    public Cls(String input) {
        Runtime r = Runtime.getRuntime();
        // ruleid: command-injection-formatted-runtime-call
        r.exec(new String[] {"/bin/sh", "-c", "some_tool", input});  // false negative
    }
}

To Reproduce

https://semgrep.dev/playground/s/jxAWY

Expected behavior
A clear and concise description of what you expected to happen.

Priority
How important is this to you?

  • P0: blocking me from making progress
  • P1: this will block me in the near future
  • P2: annoying but not blocking me

Additional Context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions