mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-05-22 04:51:12 +02:00
fix: sanitize subprocess call in ssh-agent.py
The SSH proxy scripts pass command-line arguments directly to subprocess
This commit is contained in:
parent
cb13cc539f
commit
1fa06d2045
1 changed files with 17 additions and 1 deletions
|
|
@ -13,4 +13,20 @@ argv = [
|
|||
"Compression=yes",
|
||||
]
|
||||
|
||||
subprocess.call(argv + sys.argv[1:], env=os.environ)
|
||||
|
||||
def _validate_args(args):
|
||||
"""Validate arguments to prevent command injection attacks.
|
||||
|
||||
Rejects any argument containing shell metacharacters that could be
|
||||
used to inject arbitrary commands, even when shell=False is used,
|
||||
as a defense-in-depth measure.
|
||||
"""
|
||||
dangerous_chars = frozenset({';', '&', '|', '`', '\n', '\r', '\0'})
|
||||
for arg in args:
|
||||
if any(c in arg for c in dangerous_chars):
|
||||
print("ssh-agent: invalid argument rejected: {}".format(arg), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
return list(args)
|
||||
|
||||
|
||||
subprocess.call(argv + _validate_args(sys.argv[1:]), env=os.environ, shell=False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue