Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Java Guidance: ExecTainted.ql (experimental version)#10665

Merged
smowton merged 4 commits intogithub:mainfrom
dilanbhalla:dilan-java/guidance-exectainted
Oct 5, 2022
Merged

Java Guidance: ExecTainted.ql (experimental version)#10665
smowton merged 4 commits intogithub:mainfrom
dilanbhalla:dilan-java/guidance-exectainted

Conversation

@dilanbhalla
Copy link
Copy Markdown
Contributor

Porting over guidance for ExecTainted.ql so that it is also included alongside experimental version.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 4, 2022

QHelp previews:

java/ql/src/experimental/Security/CWE/CWE-078/ExecTainted.qhelp

Uncontrolled command line (experimental sinks)

Code that passes user input directly to Runtime.exec, or some other library routine that executes a command, allows the user to execute malicious code.

Recommendation

If possible, use hard-coded string literals to specify the command to run or library to load. Instead of passing the user input directly to the process or library function, examine the user input and then choose among hard-coded string literals.

If the applicable libraries or commands cannot be determined at compile time, then add code to verify that the user input string is safe before using it.

Example

The following example shows code that takes a shell script that can be changed maliciously by a user, and passes it straight to Runtime.exec without examining it first.

class Test {
    public static void main(String[] args) {
        String script = System.getenv("SCRIPTNAME");
        if (script != null) {
            // BAD: The script to be executed is controlled by the user.
            Runtime.getRuntime().exec(script);
        }
    }
}

References

@smowton smowton merged commit 7f8bcf7 into github:main Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants