fix(security): block Python subprocess git bypass in git_gate.py — detects subprocess.run/call/Popen/os.system wrapping git/gh commands

This commit is contained in:
AIOSAI
2026-05-16 10:38:20 -07:00
parent 8625918d30
commit d7dbb6291b
+8 -1
View File
@@ -146,10 +146,17 @@ def main():
cmd = tool_input.get("command", "")
if not cmd:
return
# Subprocess bypass detection — scan raw command for git/gh inside
# subprocess.run/call/Popen/os.system patterns before stripping quotes.
if re.search(r"subprocess\.\w+|os\.system|os\.popen|Popen", cmd):
if re.search(r"['\"]git['\"]|['\"]gh['\"]", cmd):
_block(GIT_REDIRECT)
# Strip quoted strings before matching — text inside "..." or '...' is data
# (PR descriptions, commit messages, examples in docs), not code to enforce.
scan = re.sub(r'"(?:[^"\\]|\\.)*"', '""', cmd)
scan = re.sub(r"'(?:[^'\\]|\\.)*'", "''", scan)
scan = re.sub(r"'(?:[^'\\]|\\.)*'", "''", cmd)
if (
BLOCKED_GIT_RE.search(scan)
or BLOCKED_GIT_STASH_RE.search(scan)