Skip to content

test(tier3): cover run-directory checks on local directory downloads - #479

Merged
chrisknvidia merged 4 commits into
mainfrom
fix/christopherk/local-env-download-root-check
Nov 13, 2026
Merged

chrisknvidia merged 4 commits into
mainfrom
fix/christopherk/local-env-download-root-check

Conversation

@chrisknvidia

@chrisknvidia chrisknvidia commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Main now applies the allowed-roots check to local directory downloads, including the excluded and filtered ones (download_dir_with_exclusions and download_dir_filtered go through _download_local_directory, which refuses a source outside the run directory or behind a symlink before Harbor runs tar or find). 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, for download_dir, excluded and filtered downloads. The tests run the real implementation rather than stubbing Harbor's base download methods.

Verification

  • I am familiar with the Contributing Guidelines
  • Added or updated focused tests
  • Ran make lint (ruff check src tests passes)
  • Ran tests/test_harbor_local_environment.py against 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 fail
  • Did not add credentials, private datasets, or proprietary benchmark content

Release Impact

  • No CHANGELOG entry needed: tests only

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]>
@chrisknvidia
chrisknvidia marked this pull request as ready for review November 13, 2026 08:01
devin-ai-integration[bot]

This comment was marked as resolved.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>

@rng1995 rng1995 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@chrisknvidia chrisknvidia changed the title fix(tier3): apply the allowed-roots check to local directory downloads test(tier3): cover run-directory checks on local directory downloads Nov 13, 2026
@chrisknvidia
chrisknvidia merged commit b6399bb into main Nov 13, 2026
24 checks passed
@chrisknvidia
chrisknvidia deleted the fix/christopherk/local-env-download-root-check branch November 13, 2026 17:42
rng1995 added a commit that referenced this pull request Nov 13, 2026
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]>
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.

2 participants