Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cb0aac1
Reject task.json symlinks that escape the repository
sazid63 Dec 4, 2026
e5297d4
Test repo run rejection of escaping task.json symlinks
sazid63 Dec 4, 2026
3f77215
Clarify repo run path refusal behavior
sazid63 Dec 4, 2026
e28b86e
Reject task directory links that escape the repository
sazid63 Dec 4, 2026
a2c5de9
Reject task links escaping the exported eval directory
sazid63 Dec 4, 2026
34c0d61
Test task directory aliases and relocated link escapes
sazid63 Dec 4, 2026
ec4cc2c
Make relocated host target present in regression test
sazid63 Dec 4, 2026
d32e54e
Harden repo run task JSON link validation
sazid63 Dec 4, 2026
420d2e2
Add direct coverage for task link guards
Copilot Dec 4, 2026
4661cd9
Validate exported task links before file-type filtering
sazid63 Dec 4, 2026
909be2d
Move task path checks out of repo_run
sazid63 Dec 4, 2026
dc961ca
Mark intentional must-not-raise smoke test
sazid63 Dec 4, 2026
ac25f53
Extract task path validation helpers
sazid63 Dec 4, 2026
b7ff336
Separate source-tree task-link regressions from loader tests
sazid63 Dec 4, 2026
502b0f3
Preserve task selection when exported links are unresolved
sazid63 Dec 4, 2026
17c1f82
Move source-tree checks into a dedicated regression module
sazid63 Dec 4, 2026
df00c9e
Clarify selection-aware handling of unresolved task links
sazid63 Dec 4, 2026
cdf4c96
Clarify deferred task-link resolution regression
sazid63 Dec 4, 2026
c85636a
Cover task-directory aliases in pinned Git trees
sazid63 Dec 4, 2026
d472aab
Fix CI quality checks for task link validation
sazid63 Dec 5, 2026
b7043b7
Tighten task path validation comment
sazid63 Dec 5, 2026
8d6ae2d
test: cover exported task directory symlink escape and equivalent mut…
sazid63 Dec 5, 2026
81b27c5
Fix task directory containment boundaries
sazid63 Dec 5, 2026
0fbb7d2
Correct relocated directory-link regression fixture
sazid63 Dec 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dokimi/changelog.d/20261204_sazid63_repo_run_task_links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--
Copyright (C) 2026 Intel Corporation
SPDX-License-Identifier: Apache-2.0
-->

### Security

- **Reject escaping task paths** — `repo run` refuses task directories and task JSON links that leave the repository or escape the relocated eval directory.
5 changes: 5 additions & 0 deletions dokimi/docs/repo-evaluation-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ belongs to the repository's grader and is passed through unread, except `grader`
`eval check --schema-only` reports a `task.json` that is not valid JSON, not a JSON object, or cannot be
read (a link that loops, names a directory or nothing, or leaves the repository, in a tree or at `<dir>@rev`) as an `error:` line, and exits 1.

`repo run` refuses a task whose `task.json` link leaves the source repository, with exit 2.
It checks again after exporting the eval directory: relocation can make a relative link escape that was contained in the source tree.
After export, a task directory or task target that resolves outside the exported eval directory is refused before it is read.
Unresolved in-tree links are left to the selection-aware loader: a selected broken task fails, while an unrelated unselected broken task does not block the run.

| Key | Required | Read by | Meaning |
|---|---|---|---|
| `id` | yes | framework | equals the directory name, and contains no whitespace or comma: the workflow's `tasks`, `smoke-tasks` and `exclude-tasks` inputs are lists of ids split on whitespace and commas, so `eval check --schema-only` refuses an id containing either |
Expand Down
10 changes: 8 additions & 2 deletions dokimi/dokimi/commands/repo_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
from dokimi.exit_codes import EXIT_INCONCLUSIVE, EXIT_INFRA
from dokimi.repos.harness_profile import DELEGATION_MODES
from dokimi.repos.source import SourceArgumentError, tree_path
from dokimi.repos.task_source import (
check_exported_task_json_links as _check_exported_task_json_links,
check_task_json_links as _check_task_json_links,
)
from dokimi.digest import tree_digest
from dokimi.files import InputError
from dokimi.commands._shared import run_errors
Expand All @@ -33,8 +37,8 @@


def refuse_typed(source, args: argparse.Namespace) -> None:
"""Exit 2 for what the user typed: a pinned local path inside a repository, or a ``--manifest`` that leaves
the tree as written. A path the tree supplies (a link out of it) fails later, with exit 1."""
"""Exit 2 for what the user typed, and for a ``--manifest`` or ``--suite`` leaving the tree.
Task links are checked in ``_context``; other tree paths fail later, with exit 1."""
from dokimi.repos.source import check_pinned_root

try:
Expand Down Expand Up @@ -84,6 +88,7 @@ def _context(args: argparse.Namespace, out: Path, source, pin: bool = False):

tree = open_source(source, cache_dir_from_args(args))
manifest = manifest_for_tree(tree, args)
_check_task_json_links(tree, manifest) # refuse task paths that leave the source repository
require_runnable(manifest)
if manifest.image is None:
raise ValueError(f"{manifest.path} declares no `image`; entry points and agents run in it")
Expand All @@ -92,6 +97,7 @@ def _context(args: argparse.Namespace, out: Path, source, pin: bool = False):
content = out / "_eval" / "content"
# a pinned batch keeps its content until the pin is checked
staged = export_eval_dir(tree, manifest, content.with_name("content.next") if pin else content)
_check_exported_task_json_links(staged, manifest)
_require_grade(staged, manifest, args.task) # before the pin and the image build
suite = _suite_bases(args, tree, staged, manifest, cache_dir_from_args(args)) # its pins go in the batch pin
runner = DockerRunner(args.docker)
Expand Down
69 changes: 69 additions & 0 deletions dokimi/dokimi/repos/task_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (C) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

"""Validate task paths before and after exporting a repository evaluation tree."""

from __future__ import annotations

from pathlib import Path

from dokimi.files import InputError
from dokimi.repos.source import SourceArgumentError


def _check_source_path(tree, path: str, *, dirs: bool = False) -> None:
"""Convert confirmed repository escapes; leave other resolution errors to the loader."""
try:
tree.resolve(path, dirs=dirs)
except SourceArgumentError as exc:
if str(exc).startswith("path escapes the repository:"):
raise InputError(str(exc)) from exc


def check_task_json_links(tree, manifest) -> None:
"""Refuse task directories and task files that leave the source repository (contract §3)."""
_eval_dir, tasks = manifest.run_paths()
files = tree.files()
# A symlinked tasks root is itself an entry, even when it has no children.
if tasks in files:
_check_source_path(tree, tasks, dirs=True)
task_prefix = f"{tasks}/"
task_ids = {
rel[len(task_prefix):].partition("/")[0]
for rel in files
if rel.startswith(task_prefix) and rel[len(task_prefix):]
}
for task_id in sorted(task_ids):
task_dir = f"{tasks}/{task_id}"
_check_source_path(tree, task_dir, dirs=True)
_check_source_path(tree, f"{task_dir}/task.json")


def _refuse_export_escape(path: Path, root: Path, kind: str, shown: str) -> bool:
"""Refuse a resolved path outside the exported eval tree; defer loops and other resolution errors."""
try:
path.resolve(strict=False).relative_to(root)
except ValueError as exc:
raise InputError(f"{kind} escapes the exported eval directory: {shown}") from exc
except (OSError, RuntimeError):
return False
return True


def check_exported_task_json_links(content: Path, manifest) -> None:
"""Reject exported task paths outside eval_dir without pre-empting selection-aware loading."""
eval_dir, tasks = manifest.run_paths()
tasks_dir = content / Path(tasks).relative_to(eval_dir)
root = content.resolve()
if not _refuse_export_escape(tasks_dir, root, "tasks directory", tasks):
return
if not tasks_dir.is_dir():
return
for task_dir in tasks_dir.iterdir():
shown_dir = f"{tasks}/{task_dir.name}"
if not _refuse_export_escape(task_dir, root, "task directory", shown_dir):
continue
task_json = task_dir / "task.json"
if not task_json.is_symlink() and not task_json.exists():
continue # mutation-ok[delete-statement]: absent in-tree task files are still contained
_refuse_export_escape(task_json, root, "task link", f"{shown_dir}/task.json")
Loading