-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* remove github action scan folder after index-js is built #3499 * save the github action index.js as sechub-scan.cjs * save the github action index.js as sechub-scan.cjs * prevent command injection in sechub-cli.ts * add doc to shell-cmd-sanitizer.ts * use whitelist in github action to prevent command injection * revert action.yml changes temporarily * pr clean up * pr clean up * use child_process execFileSync to pass commands to go client in array * pass process.env to execFileSync in GitHub Action * pass process.env to execFileSync in GitHub Action * update versions used in 01-start.sh github action * protect against shell arguments that are commands in github actions * replace potentially dangerous shell command injection code * use commandExists npm library to check if shell argument is a malicious command * use commandExists npm library to check if shell argument is a malicious command * use commandExists npm library to check if shell argument is a malicious command * fix integration tests * revert info logs to debug * revert info logs to debug
- Loading branch information
Showing
13 changed files
with
1,209 additions
and
1,042 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
import * as shellArgSanitizer from '../src/shell-arg-sanitizer'; | ||
|
||
describe('sanitize', () => { | ||
test.each([ | ||
['rm -rf /; echo hacked'], // Command chaining | ||
['echo $(whoami)'], // Command substitution | ||
['cat /etc/passwd | grep root'], // Piping | ||
['touch /tmp/test && ls /tmp'], // Logical AND | ||
['echo hello > /tmp/test'], // Redirection | ||
['`reboot`'], // Backticks | ||
['$(reboot)'], // Subshell | ||
['; reboot'], // Semicolon | ||
['| reboot'], // Pipe | ||
['& reboot'], // Background process | ||
['> /dev/null'], // Redirection to null | ||
['< /dev/null'], // Input redirection | ||
['|| reboot'], // Logical OR | ||
['&& reboot'], // Logical AND | ||
['$(< /etc/passwd)'], // Command substitution with input redirection | ||
['$(cat /etc/passwd)'], // Command substitution with cat | ||
['$(echo hello > /tmp/test)'], // Command substitution with redirection | ||
['$(touch /tmp/test && ls /tmp)'], // Command substitution with logical AND | ||
['$(cat /etc/passwd | grep root)'], // Command substitution with pipe | ||
['$(rm -rf /; echo hacked)'], | ||
['kill'], | ||
['sleep'], | ||
['shutdown'], | ||
['reboot'], | ||
['halt'], | ||
['ps'], | ||
['top'], | ||
['killall'], | ||
['pkill'], | ||
['pgrep'], | ||
['chown'], | ||
['chmod'], | ||
['chgrp'], | ||
['passwd'], | ||
['su'], | ||
['sudo'], | ||
['chsh'], | ||
['chfn'], | ||
['chroot'] | ||
])( | ||
'%s throws CommandInjectionError', | ||
(arg) => { | ||
/* test */ | ||
expect(() => shellArgSanitizer.sanitize(arg)).toThrow(/Command injection detected in shell argument:/); | ||
} | ||
); | ||
|
||
test.each([ | ||
['/path/to/sechub-cli'], | ||
['-configfile'], | ||
['/path/to/config.json'], | ||
['-output'], | ||
['/path/to/workspace'], | ||
['-addScmHistory'], | ||
['scan'], | ||
['-jobUUID'], | ||
['-project'], | ||
['--reportformat'], | ||
['json'], | ||
['getReport'] | ||
])( | ||
'does not throw CommandInjectionError for safe shell argument: %s', | ||
(arg) => { | ||
/* test */ | ||
expect(() => shellArgSanitizer.sanitize(arg)).not.toThrow(); | ||
}); | ||
|
||
it('removes whitespaces', function () { | ||
/* prepare */ | ||
const arg = ' /path/to/sechub-cli '; | ||
|
||
/* execute */ | ||
const sanitized = shellArgSanitizer.sanitize(arg); | ||
|
||
/* test */ | ||
expect(sanitized).toEqual('/path/to/sechub-cli'); | ||
}); | ||
}); |
This file contains 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
Oops, something went wrong.