Skip to content

Instantly share code, notes, and snippets.

View geusebi's full-sized avatar

Giampaolo Eusebi geusebi

View GitHub Profile
@geusebi
geusebi / safe_join.py
Last active February 22, 2016 07:01
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()