Skip to content

fix(example): prevent path traversal in file-listing server - #315

Open
mcollina wants to merge 1 commit into
mainfrom
fix/ghsa-3439-file-listing-path-traversal
Open

mcollina wants to merge 1 commit into
mainfrom
fix/ghsa-3439-file-listing-path-traversal

Conversation

@mcollina

Copy link
Copy Markdown
Member

The file-listing example passed client-supplied paths straight to join(process.cwd(), path), so its list_files, get_file_info, file://read, and watch_files operations accepted ../ traversal and could reach files outside the working directory with the privileges of the server process. The file://read resource also percent-decoded its path query parameter through URLSearchParams before touching the filesystem.

This change resolves every destination against an explicit root and rejects anything that escapes it. Containment is checked against the symlink-resolved path so a symlink pointing outside the root is rejected too. This hardens the example without changing the library itself, addressing GHSA-3439-r3q5-g34g.

Bound every client-supplied path in the file-listing example to the server's
working directory. list_files, get_file_info, file://read and watch_files now
resolve paths against an explicit root and reject any destination that escapes
it, including '..' traversal and symlinks resolved after fs.realpath.

This hardening addresses GHSA-3439-r3q5-g34g.

This branch has not been deployed

No deployments
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.

1 participant