Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
99dada18
Commit
99dada18
authored
Oct 21, 2020
by
Vitor Meireles De Sousa
Committed by
Nick Gaskill
Oct 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add OS command injection into secure coding guidelines documentation
parent
9b24e58e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
0 deletions
+73
-0
doc/development/secure_coding_guidelines.md
doc/development/secure_coding_guidelines.md
+73
-0
No files found.
doc/development/secure_coding_guidelines.md
View file @
99dada18
...
...
@@ -431,3 +431,76 @@ requires :file_path, type: String, file_path: true
NOTE:
**Note:**
Absolute paths are not allowed by default. If allowing an absolute path is required, you
need to provide an array of paths to the parameter
`allowlist`
.
## OS command injection guidelines
Command injection is an issue in which an attacker is able to execute arbitrary commands on the host
operating system through a vulnerable application. Such attacks don't always provide feedback to a
user, but the attacker can use simple commands like
`curl`
to obtain an answer.
### Impact
The impact of command injection greatly depends on the user context running the commands, as well as
how data is validated and sanitized. It can vary from low impact because the user running the
injected commands has limited rights, to critical impact if running as the root user.
Potential impacts include:
-
Execution of arbitrary commands on the host machine.
-
Unauthorized access to sensitive data, including passwords and tokens in secrets or configuration
files.
-
Exposure of sensitive system files on the host machine, such as
`/etc/passwd/`
or
`/etc/shadow`
.
-
Compromise of related systems and services gained through access to the host machine.
You should be aware of and take steps to prevent command injection when working with user-controlled
data that are used to run OS commands.
### Mitigation and prevention
To prevent OS command injections, user-supplied data shouldn't be used within OS commands. In cases
where you can't avoid this:
-
Validate user-supplied data against an allowlist.
-
Ensure that user-supplied data only contains alphanumeric characters (and no syntax or whitespace
characters, for example).
-
Always use
`--`
to separate options from arguments.
### Ruby
Consider using
`system("command", "arg0", "arg1", ...)`
whenever you can. This prevents an attacker
from concatenating commands.
For more examples on how to use shell commands securely, consult
[
Guidelines for shell commands in the GitLab codebase
](
shell_commands.md
)
.
It contains various examples on how to securely call OS commands.
### Go
Go has built-in protections that usually prevent an attacker from successfully injecting OS commands.
Consider the following example:
```
golang
package
main
import
(
"fmt"
"os/exec"
)
func
main
()
{
cmd
:=
exec
.
Command
(
"echo"
,
"1; cat /etc/passwd"
)
out
,
_
:=
cmd
.
Output
()
fmt
.
Printf
(
"%s"
,
out
)
}
```
This echoes
`"1; cat /etc/passwd"`
.
**Do not**
use
`sh`
, as it bypasses internal protections:
```
golang
out
,
_
=
exec
.
Command
(
"sh"
,
"-c"
,
"echo 1 | cat /etc/passwd"
)
.
Output
()
```
This outputs
`1`
followed by the content of
`/etc/passwd`
.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment