FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Simplifies alias search path sanitisation. by zooba · Pull Request #301 · python/pymanager · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
21 changes: 11 additions & 10 deletions src/manage/aliasutils.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@

DEFAULT_SITE_DIRS = ["Lib\\site-packages", "Scripts"]

# Our script removes sys.path[0] if empty to avoid trivial search path hijacks.
# In virtually all cases it should be the directory where our scripts are
# generated, which has no importable packages (unless there are unauthorised
# modifications, which are out of scope for our security threat model).
# We don't try to be any more clever, since we don't know what kind of
# interpreter we are running inside - this script may be generated for any
# arbitrary executable installed by PyManager, and so it's possible that
# sys.path[0] is already sanitised or entirely unrelated.

SCRIPT_CODE = """import sys

# Clear sys.path[0] if it contains this script.
# Be careful to use the most compatible Python code possible.
try:
if sys.path[0]:
if sys.argv[0].startswith(sys.path[0]):
sys.path[0] = ""
else:
open(sys.path[0] + "/" + sys.argv[0], "rb").close()
sys.path[0] = ""
except OSError:
pass
if not sys.path[0]:
del sys.path[0]
except AttributeError:
pass
except IndexError:
Expand Down
Loading

Back | FazBrowse Home | New Git URL