Building a command line with string concatenation#338
Merged
kevin-mcgoldrick merged 1 commit intomasterfrom Jul 24, 2024
Merged
Building a command line with string concatenation#338kevin-mcgoldrick merged 1 commit intomasterfrom
kevin-mcgoldrick merged 1 commit intomasterfrom
Conversation
kevin-mcgoldrick
added a commit
that referenced
this pull request
Jul 24, 2024
* 'master' of https://github.com/intuit/Tank: Building a command line with string concatenation (#338)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code that builds a command line by concatenating strings that have been entered by a user allows the user to execute malicious code.
Recommendation
Execute external commands using an array of strings rather than a single string. By using an array, many possible vulnerabilities in the formatting of the string are avoided.
Example
In the following example, latlonCoords contains a string that has been entered by a user but not validated by the program. This allows the user to, for example, append an ampersand (&) followed by the command for a malicious program to the end of the string. The ampersand instructs Windows to execute another program. In the block marked 'BAD', latlonCoords is passed to exec as part of a concatenated string, which allows more than one command to be executed. However, in the block marked 'GOOD', latlonCoords is passed as part of an array, which means that exec treats it only as an argument.
References
OWASP: Command Injection.
SEI CERT Oracle Coding Standard for Java: IDS07-J. Sanitize untrusted data passed to the Runtime.exec() method.
Common Weakness Enumeration: CWE-78.
Common Weakness Enumeration: CWE-88.
Please make sure these check boxes are checked before submitting
mvn clean test -P default** PR review process **