fix(nova_file_controller): prevent path traversal in static file routes#383
Open
Taure wants to merge 2 commits into
Open
fix(nova_file_controller): prevent path traversal in static file routes#383Taure wants to merge 2 commits into
Taure wants to merge 2 commits into
Conversation
User-supplied path segments were joined onto the served root without canonicalisation, so a request containing .. (or %2E%2E once decoded) could escape the served directory. The controller now decodes each segment, rejects absolute paths, and resolves . and .. against a zero-depth floor; any attempt to climb above the root returns 403. Also unblocks safe URL-decoding of segments, so UTF-8 filenames served from a wildcard route work as expected.
Adds 13 tests covering depth-counting edge cases (chained .., mixed subdir/.., long traversal chains, going below root after descending), common bypass attempts (double URL encoding, backslash, empty segment, '...', NUL byte), and previously-untested positive paths (subdirectory serve, '.' segments, .. that resolves back inside root).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a path-traversal weakness in
nova_file_controller:get_dir/1: user-supplied URL segments were joined onto the served root without canonicalisation, so a request containing..(or%2E%2Eonce decoded) could escape the served directory.The controller now:
./..against a zero-depth floor; anything climbing above the root returns403.This also unblocks safe URL-decoding of segments, so UTF-8 filenames served from a wildcard route work as expected (which addresses the legitimate part of #381 — that PR can rebase on this and drop the hand-rolled decode in
get_dir, leaving only the mime /file_infofixes).Eight new EUnit tests cover:
..traversal -> 403.%2E%2Etraversal -> 403.%2e%2E-> 403.%2E%2E%2F...-> 403.Test plan
rebar3 eunit(390 tests, 0 failures)rebar3 dialyzer(clean)rebar3 xref(clean)~/bin/elp eqwalize nova_file_controller(no new errors)