Skip to content

Fix/repo run task symlink escape - #1610

Merged
napetrov merged 14 commits into
intel:mainfrom
sazid63:fix/repo-run-task-symlink-escape
Dec 6, 2026
Merged

napetrov merged 14 commits into
intel:mainfrom
sazid63:fix/repo-run-task-symlink-escape

Conversation

@sazid63

@sazid63 sazid63 commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Prevent repo run from reading task definitions through symlinks that escape the exported evaluation tree, without letting unrelated dangling task links block explicitly selected tasks.

Changes

  • Reject task JSON paths that resolve outside the exported eval tree, including symlinked task directories and dangling external links.
  • Preserve selection isolation: an unselected dangling link or symlink loop does not block a valid selected task; selected broken links still fail clearly.
  • Restore repo run sign-in preflight wiring, including --no-preflight and input-error handling.
  • Add regression tests for symlink escapes, dangling links, loops, in-tree links, and preflight behavior.
  • Split task-file handling into a helper to satisfy the file-growth limit and document the path restriction.

Validation

  • Focused tests: 204 passed, 4 skipped.
  • Documentation tests: 608 passed.
  • Static and type checks: 17 passed, 3 skipped (network-dependent).
  • Changed-line coverage: 89%.

@sazid63
sazid63 requested a review from a team as a code owner December 4, 2026 14:13
Copilot AI balanced review requested due to automatic review settings December 4, 2026 14:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@exai-bot

exai-bot commented Dec 4, 2026 •

Copy link
Copy Markdown

OpenCodeReview: Commit 8ae4e7e was not reviewed. This PR has reached its review limit (6 reviews).

CI at 8ae4e7e: 2 passing.

To review this commit: re-request review from exai-bot in the Reviewers list.

Last review (49e455e): no findings

Open threads from the bot: 0

Comment thread dokimi/dokimi/repos/workspace.py Outdated
Comment on lines +275 to +277
resolved = path.resolve(strict=True)
except (OSError, RuntimeError) as exc:
raise PrepError(f"{shown}: cannot resolve task.json: {exc}") from exc

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · should fix
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>
@sazid63
sazid63 force-pushed the fix/repo-run-task-symlink-escape branch from 2c4cd49 to 888d0c4 Compare December 4, 2026 14:34
Comment thread dokimi/dokimi/commands/repo_run.py Outdated
Comment on lines +467 to +468
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · should fix
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>
@sazid63
sazid63 force-pushed the fix/repo-run-task-symlink-escape branch from 512e122 to 9829db3 Compare December 4, 2026 16:18
@codecov-commenter

codecov-commenter commented Dec 4, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 92.30769% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.48%. Comparing base (b1e1d6e) to head (8ae4e7e).

Files with missing lines Patch % Lines
dokimi/dokimi/repos/task_files.py 87.50% 4 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
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     
Files with missing lines Coverage Δ
dokimi/dokimi/commands/repo_run.py 97.33% <100.00%> (+0.03%) ⬆️
dokimi/dokimi/repos/errors.py 100.00% <100.00%> (ø)
dokimi/dokimi/repos/workspace.py 94.00% <100.00%> (-0.04%) ⬇️
dokimi/dokimi/repos/task_files.py 87.50% <87.50%> (ø)

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Tests miss 1 of 37 small breaks of the lines this PR changes

At 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 # mutation-ok[<operator>]: <reason> at the end of the line or alone on the line above.

Where Operator Change no test notices Tests reaching the line
dokimi/dokimi/repos/task_files.py:55 bump-int 200 → 201 2

Not checked:

  • 10 changed lines were not mutated

Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary.

sazid63 and others added 3 commits December 4, 2026 22:59
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>
@sazid63
sazid63 force-pushed the fix/repo-run-task-symlink-escape branch from 8e5c296 to e5de6a4 Compare December 4, 2026 22:59
Comment thread dokimi/dokimi/repos/task_files.py Outdated
Comment on lines +28 to +33
for candidate in (path, *path.parents):
if candidate == content_root:
break
if candidate.is_symlink():
candidate.unlink()
break

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security · should fix
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 napetrov mentioned this pull request Dec 4, 2026
8 tasks done

@napetrov napetrov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread dokimi/dokimi/repos/task_files.py Outdated
if candidate == content_root:
break
if candidate.is_symlink():
candidate.unlink()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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>
@sazid63
sazid63 force-pushed the fix/repo-run-task-symlink-escape branch from ac91483 to 002eb72 Compare December 4, 2026 23:20
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>
@sazid63
sazid63 force-pushed the fix/repo-run-task-symlink-escape branch from 49e455e to 63ae05a Compare December 5, 2026 00:02
@sazid63

sazid63 commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

@napetrov Thanks for the review. I've updated the implementation to address the path-containment and cleanup concerns.

The latest changes:

  • Kept containment validation independent of cleanup. Rejected paths are not unlinked, avoiding accidental modification of host-side files through directory symlinks.
  • Strengthened the directory-symlink regression test to verify that both the external task directory and its host-side task.json symlink remain untouched.
  • Preserved selection-aware handling of unresolved in-tree task links, so an unrelated dangling task does not prevent a valid explicitly selected task from running.
  • Documented the non-mutating behavior directly in the implementation.

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>
@sazid63
sazid63 force-pushed the fix/repo-run-task-symlink-escape branch from 84f42e8 to 8ae4e7e Compare December 5, 2026 01:05

@sazid63 sazid63 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 run sign-in preflight and --no-preflight option 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 napetrov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@napetrov
napetrov merged commit b13f6d8 into intel:main Dec 6, 2026
30 checks passed
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.

5 participants