Repository navigation
Fix/repo run task symlink escape - #1610
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
| resolved = path.resolve(strict=True) | ||
| except (OSError, RuntimeError) as exc: | ||
| raise PrepError(f"{shown}: cannot resolve task.json: {exc}") from exc |
There was a problem hiding this comment.
Impact: an unrelated dangling task link now prevents running a valid explicitly selected task.
Trigger: commit tasks/broken/task.json -> missing.json alongside valid fix_add, then run the committed source with --task fix_add (including with a suite containing only fix_add).
Evidence: this strict resolution raises before wanted is applied; previously only selected task files were read. Selection isolation is already exercised by test_a_malformed_task_the_suite_and_the_selection_leave_out_does_not_stop_the_run.
Fix: Keep escape validation, but defer non-escape resolution errors for unselected tasks, and add a dangling-link variant of that regression test.
Workaround: remove or repair the unrelated link.
Should fix: A run shows it; it was not judged to be met in ordinary use.
Shown by running: exit 1 (at the head) · exit 0 (at the merge base) · exit 0 (at the head with the fix)
python -m pytest -q -p no:randomly -p no:cacheprovider tests/test_proof_dangling_unselected.py
What the proof does: Calls load_tasks selecting fix_add while an unselected task has a dangling task.json symlink, and asserts the selected task still loads.
The problem shows as the output DANGLING_BLOCKS_SELECTED.
Script: dokimi/tests/test_proof_dangling_unselected.py (19 lines).
try:
tasks = load_tasks(tmp_path, manifest, ["fix_add"], check_keys=False)
except PrepError as exc:
> raise AssertionError(f"DANGLING_BLOCKS_SELECTED: {exc}")
E AssertionError: DANGLING_BLOCKS_SELECTED: ev/tasks/broken/task.json: cannot resolve task.json: [Errno 2] No such file or directory: '/tmp/pytest-of-root/pytest-0/test_dangling_unselected_link_0/tasks/broken/missing.json'
tests/test_proof_dangling_unselected.py:18: AssertionError
=========================== short test summary info ============================
FAILED tests/test_proof_dangling_unselected.py::test_dangling_unselected_link_does_not_block_selected_task
1 failed in 0.58s
Validate every task path for repository-boundary escapes before selection, while deferring ordinary resolution failures for unselected tasks. This keeps outside files out of run artifacts without allowing an unrelated dangling task link to block a selected run. Recompute the selected task's resolved path strictly before reading it and report escape errors as CLI input errors. Add regression coverage for working-tree and committed-tree escapes, unselected external links, and selected/unselected dangling links. Signed-off-by: Sajid Hossain <322897530+sazid63@users.noreply.github.com>
2c4cd49 to
888d0c4
Compare
| summary = run_batch(ctx, tasks, arms, options, args.reps, batch_dir, jobs=args.jobs, force=args.force, | ||
| max_batch_usd=args.max_batch_usd, log=_progress, label_host=label_host, | ||
| preflight=lambda task, opts: check_container_signed_in(ctx, opts, task, batch_dir / "_eval")) | ||
| max_batch_usd=args.max_batch_usd, log=_progress, label_host=label_host) |
There was a problem hiding this comment.
Restore the sign-in preflight wiring.
Impact: a logged-out harness now starts the entire batch instead of refusing before any cell, producing authentication-error runs; existing invocations with repo run --no-preflight also become parser errors because its registration was removed.
Trigger: run with missing/invalid container credentials, or pass the previously supported flag.
Evidence: run_batch() defaults preflight to None, and no replacement check is performed here; test_no_preflight_flag_on_the_paid_commands explicitly requires this flag on repo run. Restore the callback, flag application/registration, and NotSignedIn translation independently of the symlink fix.
Workaround: verify container credentials manually and omit the flag.
Should fix: A run shows it; it was not judged to be met in ordinary use.
Shown by running: exit 1 (at the head) · exit 0 (at the merge base) · exit 0 (at the head with the fix)
python -m pytest -q -p no:randomly -p no:cacheprovider tests/test_zz_preflight_flag.py
What the proof does: Builds the CLI parser and asserts repo run has the --no-preflight option.
The problem shows as the output repo run lost --no-preflight.
dokimi/tests/test_zz_preflight_flag.py
import argparse
from dokimi.cli import build_parser
def test_flag():
parser = build_parser()
for name in ('repo', 'run'):
sub = next(a for a in parser._actions if isinstance(a, argparse._SubParsersAction))
parser = sub.choices[name]
assert '--no-preflight' in parser._option_string_actions, 'repo run lost --no-preflight' parser = sub.choices[name]
> assert '--no-preflight' in parser._option_string_actions, 'repo run lost --no-preflight'
E AssertionError: repo run lost --no-preflight
E assert '--no-preflight' in {'-h': _HelpAction(option_strings=['-h', '--help'], dest='help', nargs=0, const=None, default='==SUPPRESS==', type=Non...ry root: tasks whose base is a commit of another repository, named as <url>@<sha> (contract §2.1)', metavar=None), ...}
E + where {'-h': _HelpAction(option_strings=['-h', '--help'], dest='help', nargs=0, const=None, default='==SUPPRESS==', type=Non...ry root: tasks whose base is a commit of another repository, named as <url>@<sha> (contract §2.1)', metavar=None), ...} = _LeafParser(prog='dokimi repo run', usage=None, description='Exit 2 for a source that does not parse (a path that is n...ne left cells not started.', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)._option_string_actions
tests/test_zz_preflight_flag.py:9: AssertionError
=========================== short test summary info ============================
FAILED tests/test_zz_preflight_flag.py::test_flag - AssertionError: repo run ...
1 failed in 1.01s
Signed-off-by: sazid63 <322897530+sazid63@users.noreply.github.com>
512e122 to
9829db3
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1610 +/- ##
==========================================
- Coverage 96.49% 96.48% -0.02%
==========================================
Files 569 570 +1
Lines 75249 75285 +36
Branches 12980 12985 +5
==========================================
+ Hits 72611 72638 +27
- Misses 1615 1620 +5
- Partials 1023 1027 +4
🚀 New features to boost your workflow:
|
Mutation of changed linesAt 8ae4e7e: 36 caught · 1 missed Each row is a small deliberate break (a mutant) of a line this PR changes that every test reaching that line still passes. Add a test that fails on it or, if it cannot change behaviour, put
Not checked:
Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary. |
Cover dangling external links and in-tree task-file links, and split task-file handling out of workspace.py to satisfy the growth ratchet. Signed-off-by: sazid63 <322897530+sazid63@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Exercise task symlink loops and assert repo-run preflight surfaces task path escapes. Signed-off-by: sazid63 <322897530+sazid63@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
8e5c296 to
e5de6a4
Compare
| for candidate in (path, *path.parents): | ||
| if candidate == content_root: | ||
| break | ||
| if candidate.is_symlink(): | ||
| candidate.unlink() | ||
| break |
There was a problem hiding this comment.
The previously identified host-side deletion is still possible here. Impact: rejecting an untrusted repository can delete a symlink outside the exported evaluation tree. Trigger: content/tasks/evil -> /host/task-dir, with /host/task-dir/task.json -> /host/payload.json. Evidence: the leaf-first loop tests content/tasks/evil/task.json first; is_symlink() follows the directory ancestor, returns true for the host-side task.json, and unlink() removes /host/task-dir/task.json rather than the exported evil link. _export() preserves these directory links. The new directory-link test uses a regular external task file, so it does not exercise this case. Only remove a link after verifying its ancestors are contained (for example, walk from the export root toward the leaf), and add a regression asserting the external symlink remains unchanged. Workaround: do not evaluate repositories with externally linked task directories.
Should fix: A run shows it; it was not judged to be met in ordinary use.
Shown by running: exit 1 (at the head) · exit 1 (at the merge base, which cannot run it) · exit 0 (at the head with the fix)
python proof_c1.py
What the proof does: Calls resolve_task_paths with a symlinked task directory whose external task.json is a symlink and asserts the external symlink survives.
The problem shows as the output HOST FILE DELETED.
Script: dokimi/proof_c1.py (23 lines), dokimi/proof_c1_note.txt (1 lines).
HOST FILE DELETED: external task.json symlink was unlinked
napetrov
left a comment
There was a problem hiding this comment.
Change class: CONTRACT (head 896fcff)
- Contract: candidate. errors dokimi/dokimi/commands/repo_run.py:167; errors dokimi/dokimi/repos/task_files.py:26
- Responsibility: none
- Dependency: none
- Review depth: check the changed surface: callers, docs, tests pin new behaviour
- Coverage gaps: none
No new blocking findings on 896fcfff.
Both task-path fixes touch the same preparation flow and conflict in their shared test file. Reconcile this PR with #1611 before merging either.
CI was still running for Intel CI (awaiting approval); agent-quality (awaiting approval); ci (awaiting approval); cli-interface (awaiting approval).
Reviewed the diff, edge cases and prior threads. Path containment was reviewed statically. The full local suite was outside coverage.
| if candidate == content_root: | ||
| break | ||
| if candidate.is_symlink(): | ||
| candidate.unlink() |
There was a problem hiding this comment.
question: Preserve the task-path error when cleanup fails
Can resolve_task_paths report TaskPathEscapeError if unlinking the exported entry raises OSError? Keep the containment decision independent of cleanup so callers retain the intended diagnostic.
Signed-off-by: sazid63 <322897530+sazid63@users.noreply.github.com>
Signed-off-by: sazid63 <322897530+sazid63@users.noreply.github.com>
Signed-off-by: sazid63 <322897530+sazid63@users.noreply.github.com>
ac91483 to
002eb72
Compare
Signed-off-by: sazid63 <322897530+sazid63@users.noreply.github.com>
Signed-off-by: sazid63 <322897530+sazid63@users.noreply.github.com>
Signed-off-by: sazid63 <322897530+sazid63@users.noreply.github.com>
49e455e to
63ae05a
Compare
|
@napetrov Thanks for the review. I've updated the implementation to address the path-containment and cleanup concerns. The latest changes:
The source-tree and post-export checks are handled separately in #1611, while this PR focuses on loader-level containment and safe task resolution. Could you please review the latest commit, particularly the cleanup-safety and selection-isolation behavior? |
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Signed-off-by: sazid63 <322897530+sazid63@users.noreply.github.com>
84f42e8 to
8ae4e7e
Compare
sazid63
left a comment
There was a problem hiding this comment.
Follow-up on the latest head (8ae4e7e):
The loader-level changes are now in place:
- Unselected in-tree dangling task links no longer prevent a valid selected task from running.
- The
repo runsign-in preflight and--no-preflightoption have been restored. - Rejected paths are no longer unlinked during containment validation, avoiding accidental deletion of host-side files through directory symlinks.
- Removing the cleanup operation also keeps containment errors independent of cleanup failures.
The latest commit is pushed. The remaining workflow runs are currently awaiting maintainer approval.
Could you review the latest head and confirm whether any further changes are required?
napetrov
left a comment
There was a problem hiding this comment.
Change class: CONTRACT (head 8ae4e7e)
- Contract: candidate. errors dokimi/dokimi/commands/repo_run.py:167; errors dokimi/dokimi/repos/task_files.py:31
- Responsibility: none
- Dependency: none
- Review depth: check the changed surface: callers, docs, tests pin new behaviour
- Coverage gaps: none
No new actionable findings.
This PR enforces task path containment in the shared exported-task loader. It overlaps #1611, which also checks the source tree and wires its checks into repo run.
Review alongside #1611 so the shared task loader and the source/export checks agree on scope. The paired merge with #1639 conflicts in workspace.load_tasks.
CI on head 8ae4e7e: 0 failing Actions jobs; merge base b1e1d6e is behind base tip 5225c2a.
Compared the change and input edges against the merge base and checked existing threads and GitHub Actions. Runtime checks used local fixtures. Live credentials and external path access were outside the review. Focused tests on the head: extra 3 passed, 11 deselected in 0.41s.
napetrov
left a comment
There was a problem hiding this comment.
Checked current task path handling, the sign-in wiring, three focused in-tree and selected-task tests, and required CI. The earlier path-error cleanup concern is obsolete because the validator no longer unlinks rejected entries. Coverage used local fixtures.
Summary
Prevent
repo runfrom reading task definitions through symlinks that escape the exported evaluation tree, without letting unrelated dangling task links block explicitly selected tasks.Changes
repo runsign-in preflight wiring, including--no-preflightand input-error handling.Validation