Skip to content

Fix path-containment bypass in LocalFileHandler.can_show - #1116

Open
AAtomical wants to merge 1 commit into
jupyter:mainfrom
AAtomical:fix/localfile-prefix-containment
Open

Fix path-containment bypass in LocalFileHandler.can_show#1116
AAtomical wants to merge 1 commit into
jupyter:mainfrom
AAtomical:fix/localfile-prefix-containment

Conversation

@AAtomical

Copy link
Copy Markdown

can_show() guarded the localfiles root with a bare fullpath.startswith(self.localfile_path) check. Because that is a string comparison rather than a path comparison, a sibling directory whose absolute path shares the configured root as a string prefix passes the guard. For example, with --localfiles /data/notebooks, a request resolving to /data/notebooks_backup/credentials.ipynb satisfies startswith("/data/notebooks") and is served, leaking files outside the intended root (CWE-22).

Compare against the root joined with a trailing separator (and accept the root itself) so only genuine descendants of the root are allowed. Classical ../../../etc traversal remains blocked as before.

Fixes #1115

can_show() guarded the localfiles root with a bare
`fullpath.startswith(self.localfile_path)` check. Because that is a
string comparison rather than a path comparison, a sibling directory
whose absolute path shares the configured root as a string prefix
passes the guard. For example, with `--localfiles /data/notebooks`, a
request resolving to `/data/notebooks_backup/credentials.ipynb`
satisfies `startswith("/data/notebooks")` and is served, leaking files
outside the intended root (CWE-22).

Compare against the root joined with a trailing separator (and accept
the root itself) so only genuine descendants of the root are allowed.
Classical `../../../etc` traversal remains blocked as before.

Fixes jupyter#1115
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nbviewer LocalFileHandler Prefix-Path Containment Bypass Allows Reading Files from Sibling Directories

1 participant