Skip to content

Commit aad3610

Browse files
authored
Merge pull request #1116 from AAtomical/fix/localfile-prefix-containment
Fix path-containment bypass in LocalFileHandler.can_show
2 parents 0c36226 + 31b9fb0 commit aad3610

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

nbviewer/providers/local/handlers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def can_show(self, path):
9999
os.path.normpath(os.path.join(self.localfile_path, path))
100100
)
101101

102-
if not fullpath.startswith(self.localfile_path):
102+
prefix = self.localfile_path.rstrip(os.sep) + os.sep
103+
if not (fullpath + os.sep).startswith(prefix):
103104
self.log.warn("Directory traversal attempt: '%s'" % fullpath)
104105
return False
105106

0 commit comments

Comments
 (0)