Repository navigation
test(tier3): cover run-directory checks on local directory downloads - #479
Conversation
download_dir_with_exclusions and download_dir_filtered in the local environment resolved the source but never checked it against the allowed local roots, so a source such as /workspace/../../../etc passed through the mapped prefix and reached Harbor's tar and find commands. Route all three directory downloads through one helper that resolves the source, applies the allowed-roots check with the same error as download_dir, and rejects the logs parent. Tests cover ".." sources through /workspace, /logs and ~, a relative ".." source and a plain absolute source for every directory download, and confirm sources inside the run directory still reach Harbor. Signed-off-by: Christopher Kevin <[email protected]>
rng1995
left a comment
There was a problem hiding this comment.
Independent review of the full source/test diff and all directory-download callers at 19d10df found no actionable findings. The shared helper applies the resolve-based allowed-roots check before destination mutation or delegation to Harbor, and retains the whole-logs-parent restriction. All 40 cases in tests/test_harbor_local_environment.py pass on macOS with Python3.12.13 and locked Harbor0.25.0, including the new mapped-prefix/relative/absolute escape cases, valid in-root traversal, and existing transfer lifecycle cases. This is the existing repair for #472’s download-boundary feedback; no duplicate fix or branch change was created.
The in-run-directory download tests only recorded that Harbor's tar/find methods were reached. The stand-ins now copy the selected files, so the excluded and filtered downloads are checked for the files they keep and drop, including nested paths and the source string passed through. Also add a case where a symlink inside the run directory points outside it, for all three download variants. Signed-off-by: Christopher Kevin <[email protected]>
Signed-off-by: Christopher Kevin <[email protected]>
There was a problem hiding this comment.
Current-head adoption review at a5f25a7: production local_environment.py is byte-identical to reviewed 19d10df; newer commits add content stubs and merge main, with CHANGELOG-only manual ordering resolution. The root-helper guard remains valid. An unmocked Harbor 0.25 probe independently reproduced inherited exclusion/filter transfer failures on main and this PR; verified follow-up #493 repairs staging without changing this PR branch. Combined production source retains these guards and passes all 60 local-environment tests after updating the old filtered test lifecycle/delegation assumption. Seventeen real content/filter/source/cleanup tests and both independent reviews approve the distinct fix. The current review threads are resolved; #493 remains proposed until merged. No new source defect introduced by this PR was found.
rng1995
left a comment
There was a problem hiding this comment.
Reviewed a5f25a731d98 and all three directory-download entry points. The common helper consistently checks allowed roots before delegating or creating the target, and all 21 added download cases passed locally. No new defect in this diff. Those tests stub Harbor's transfer methods and used installed Harbor 0.24 rather than the pinned 0.25, so they do not qualify real archive transfers or sandbox behavior. The separate transfer-protocol concern remains documented in the existing review/#493.
Main now applies the allowed-roots check to the excluded and filtered local directory downloads: both go through _download_local_directory, which refuses a source outside the run directory before any find or tar runs. The source change and the changelog entry on this branch are therefore dropped in favor of main's versions. This branch keeps its tests, rewritten to run against the real implementation instead of stubbing Harbor's downloads. They cover ".." paths that leave the run directory (through /workspace, /logs, ~ and relative spellings) and ".." paths that stay inside it, for download_dir, the excluded download and the filtered download. Signed-off-by: Christopher Kevin <[email protected]>
Picks up #476 and #479; #476's entry is already under Unreleased. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Narendran Raghavan <[email protected]>
Summary
Main now applies the allowed-roots check to local directory downloads, including the excluded and filtered ones (
download_dir_with_exclusionsanddownload_dir_filteredgo through_download_local_directory, which refuses a source outside the run directory or behind a symlink before Harbor runstarorfind). This PR keeps tests for that:..paths that leave the run directory (/workspace,/logs,~, relative) are refused and..paths that stay inside it still work, fordownload_dir, excluded and filtered downloads. The tests run the real implementation rather than stubbing Harbor's base download methods.Verification
make lint(ruff check src testspasses)tests/test_harbor_local_environment.pyagainst Harbor 0.25.0 (54 passed); the full suite runs in CI. With main's check removed in a scratch copy, 12 of the 15 new cases and 4 of main's own refusal cases failRelease Impact