Skip to content

Instantly share code, notes, and snippets.

@geusebi
Last active Feb 22, 2016
Embed
What would you like to do?
Alternative safe_join
def safe_join(directory, *pathnames):
pathnames = tuple(posixpath.normpath(p) for p in pathnames)
for filename in pathnames:
for sep in _os_alt_seps:
if sep in filename:
raise NotFound()
if os.path.isabs(filename) or \
filename == '..' or \
filename.startswith('../'):
raise NotFound()
return os.path.join(directory, *pathnames)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment