-
Notifications
You must be signed in to change notification settings - Fork 31
APPSEC-2486 S4036: Improve description #5142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
== Ask Yourself Whether | ||
|
||
* The directories in the PATH environment variable may be defined by not trusted entities. | ||
* The PATH environment variable only contains fixed, trusted directories. | ||
|
||
There is a risk if you answered yes to this question. | ||
There is a risk if you answered no to this question. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
When executing an OS command and unless you specify the full path to the executable, then the locations in your application's ``++PATH++`` environment variable will be searched for the executable. That search could leave an opening for an attacker if one of the elements in ``++PATH++`` is a directory under his control. | ||
When you run an OS command, it is always important to protect yourself against | ||
the risk of accidental or malicious replacement of the executables in the | ||
production system. | ||
|
||
To do so, the methodology consists in verifying and being intentional about | ||
whether the executable that is going to be used **is actually** the one you | ||
expect to be used. | ||
|
||
For example, if you call ``++git++`` (without specifying a path), the operating | ||
system will search for the executable in the directories specified in the | ||
``++PATH++`` environment variable. + | ||
An attacker could have added, in a permissive directory covered by ``++PATH++`` | ||
, another executable called ``++git++``, but with a completely different | ||
behavior, for example exfiltrating data or exploiting a vulnerability in your | ||
own code. | ||
|
||
However, if you call ``++/usr/bin/git++`` or ``++../git++`` (relative path) | ||
directly, the operating system will intentionally use the executable you intend | ||
to use. + | ||
Note that you still need to make sure that the executable is not world-writeable | ||
and potentially overwritten. This is not the scope of this rule. | ||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
=== Message | ||
|
||
Make sure the "PATH" used to find this command includes only what you intend. | ||
Make sure the "PATH" variable only contains fixed, unwriteable directories. | ||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,25 @@ | ||
== Recommended Secure Coding Practices | ||
|
||
Fully qualified/absolute path should be used to specify the OS command to execute. | ||
If you wish to rely on the ``++PATH++`` environment variable to locate the OS | ||
command, make sure that each of its listed directories is fixed, not susceptible | ||
to change, and not writable by unprivileged users. | ||
|
||
If you determine that these folders cannot be altered, and that you are sure | ||
that the git program you intended to use will be used, then you can determine | ||
that these risks are under your control. | ||
|
||
A good practice you can use is to also hardcode the ``++PATH++`` variable you | ||
want to use, if you can do so in the framework you use. | ||
|
||
However, if these steps are too long to do, or business logic of your | ||
organization blocks you from following them, then consider using the absolute | ||
path of the command instead. | ||
|
||
[source,bash] | ||
---- | ||
$ whereis git | ||
git: /usr/bin/git /usr/share/man/man1/git.1.gz | ||
$ ls -l /usr/bin/git | ||
-rwxr-xr-x 1 root root 3376112 Jan 28 10:13 /usr/bin/git | ||
---- | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To debate - This can also be left outside of this PR since "messages" follow a special treatment