File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed
Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change 1010
1111DEFAULT_SITE_DIRS = ["Lib\\ site-packages" , "Scripts" ]
1212
13+ # Our script removes sys.path[0] if empty to avoid trivial search path hijacks.
14+ # In virtually all cases it should be the directory where our scripts are
15+ # generated, which has no importable packages (unless there are unauthorised
16+ # modifications, which are out of scope for our security threat model).
17+ # We don't try to be any more clever, since we don't know what kind of
18+ # interpreter we are running inside - this script may be generated for any
19+ # arbitrary executable installed by PyManager, and so it's possible that
20+ # sys.path[0] is already sanitised or entirely unrelated.
21+
1322SCRIPT_CODE = """import sys
1423
15- # Clear sys.path[0] if it contains this script.
16- # Be careful to use the most compatible Python code possible.
1724try:
18- if sys.path[0]:
19- if sys.argv[0].startswith(sys.path[0]):
20- sys.path[0] = ""
21- else:
22- open(sys.path[0] + "/" + sys.argv[0], "rb").close()
23- sys.path[0] = ""
24- except OSError:
25- pass
25+ if not sys.path[0]:
26+ del sys.path[0]
2627except AttributeError:
2728 pass
2829except IndexError:
You can’t perform that action at this time.
0 commit comments