Skip to content

Commit 31fc654

Browse files
committed
chore: add semgrep python-forbid-subprocess-usage rule (#14)
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.tech>
1 parent aeb1d28 commit 31fc654

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
rules:
2+
- id: python-forbid-subprocess-usage
3+
languages: [python]
4+
severity: WARNING
5+
message: "Run commands with `run_command` from `xcp_storage.utils.process`, not directly with `subprocess` or `os`."
6+
paths:
7+
include:
8+
- src/
9+
exclude:
10+
- src/xcp_storage/utils/process.py
11+
pattern-either:
12+
- pattern: import subprocess
13+
- pattern: import subprocess.$X
14+
- pattern: from subprocess import $X
15+
- pattern: from subprocess.$X import $Y
16+
- pattern: pty.spawn(...)
17+
- patterns:
18+
- pattern: os.$FUNC(...)
19+
- metavariable-regex:
20+
metavariable: $FUNC
21+
regex: '^(system|popen|exec.*|spawn.*|posix_spawn.*)$'
22+
- patterns:
23+
- pattern: asyncio.$FUNC(...)
24+
- metavariable-regex:
25+
metavariable: $FUNC
26+
regex: '^create_subprocess_(exec|shell)$'

0 commit comments

Comments
 (0)