📝 Add security best practice note for subprocess shell execution

This commit is contained in:
2026-05-24 00:17:40 +08:00
parent 0e662294db
commit bf24ba14b3
2 changed files with 27 additions and 0 deletions
+4
View File
@@ -43,6 +43,10 @@ if __name__ == "__main__":
- Shell 内置命令:有些命令(如 Windows 的 dir, copy 或 Linux 的 export)并不是独立的可执行文件,
而是 Shell 的内置命令。如果不设 shell=True,Python 会报错找不到文件。
- 通配符展开:比如 "rm *.txt"
IMPORTANT:
不得不用的情况:如果必须要用 shell=True(比如必须调用系统内置命令),且涉及用户输入,
务必使用 shlex.quote()Linux/macOS)对用户输入进行转义过滤。
"""
subprocess.run(
'echo ">>>>>>>>>>>>" && env && echo "<<<Hello World!>>>"',