Skip to content

fix(filer): don't follow symlinks in outputs - #124

Merged
uniqueg merged 6 commits into
devfrom
fix/114-output-symlinks
Nov 9, 2026
Merged

uniqueg merged 6 commits into
devfrom
fix/114-output-symlinks

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Summary

The outputs filer no longer follows symbolic links in outputs:

  • An output fails, with an error that names the link, if any component of its path is a symbolic link, if its path has a .. component, or, for a directory, if any entry below it is a link. This holds for HTTP, FTP, S3 and file: outputs; for file: outputs with a glob, every match is checked.
  • HTTP, FTP and S3 uploads open the file with O_NOFOLLOW (open_for_upload); S3 now uploads from the open file (upload_fileobj). FTP uploads open the file read-only (was r+b).
  • The outputs filer mounts the task's paths read-only (readOnly on the task volume's mounts in Filer.get_spec("outputs")); the filer copies the claim's mounts, so the executors' mounts are unchanged.
  • HTTP and FTP uploads fail an output that can't be opened (e.g. a refused link, a missing file) with 1 and a log message instead of raising; FTP also catches read and connection errors (OSError). This also covers the r+b/OSError item of fix(filer): harden downloads, uploads and copies #120.
  • Entries of a directory output skip the check that the directory's own check already covers.
  • Docs: new section "Symbolic links in outputs" in docs/filer.md, entry in docs/upgrading.md.

Closes #114

Verification

  • .venv/bin/pytest -q -p no:cacheprovider: 532 passed (new tests/unit/test_filer_symlinks.py: links to files and directories, links in parent components, .. after a link, links below directories, a link to /proc/self/environ, glob matches, and the O_NOFOLLOW open with the check stubbed out, per protocol; regular outputs still upload).
  • ruff check ., ruff format --check ., mypy: clean.
  • mkdocs build --strict: clean.
  • pre-commit run --all-files: passed, except gitleaks and actionlint, which were skipped locally (their Go toolchain download fails in the sandbox); CI runs them.
  • CI: all checks passed (after renaming test fixture content that CodeQL read as stored credentials). Open code scanning alerts on the PR: only the existing zlib CVE-2026-4738 (medium) in both images.

Lane

Full review (adversarial + quality reviewers, two rounds).

Declined review findings

  • Use a shared constant for the task-volume name in taskmaster.py too (low): taskmaster.py is being changed in parallel by another PR; left for a follow-up.
  • Check only path components below the task's mount point (low, links in the filer image such as Alpine's /var/run): with fix(filer): mount task paths under a fixed prefix #115, task paths are mounted below a fixed prefix without links, so the case disappears.
  • A FIFO at a FILE output path blocks the open (low, round 2): unchanged from before (the old open blocked too) and affects only the task's own filer, which the pod timeout ends.
  • Sourcery: race-safe traversal (openat per component): declined in its thread, as no executor runs while the outputs filer does.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Prevent the outputs filer from following symbolic links and safely reject unsafe output paths across all supported protocols.

Bug Fixes:

  • Prevent outputs filer jobs from following or uploading symbolic links, including links in parent paths, directory contents, glob matches, and paths containing .. components.
  • Handle unreadable or failed HTTP and FTP output uploads as logged task failures instead of uncaught errors.

Enhancements:

  • Mount task output paths read-only while preserving writable executor mounts.
  • Use safe read-only file handling for HTTP, FTP, and S3 uploads.

Documentation:

  • Document symbolic-link restrictions for outputs and the required executor migration behavior.

Tests:

  • Add comprehensive cross-protocol tests covering symbolic links, unsafe paths, glob matches, upload failures, read-only mounts, and valid outputs.

The outputs filer fails an output whose path goes through a symbolic
link or has a '..' component, or a directory output with a link
anywhere below it, for every protocol (HTTP, FTP, S3, file:), and logs
why. Upload files are opened with O_NOFOLLOW (S3 now uploads from the
open file), and the outputs filer mounts the task's paths read-only.
Directory entries skip the check that their directory covers. Docs:
filer and upgrade guide.

Closes #114

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg added this to the v0.11.0 milestone Nov 9, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add shared helpers to detect links and unsafe path components and open upload files without following symlinks.

  • src/tesk_core/transput.py L10, L113-193

API

Make transput uploads reject unsafe outputs by default while allowing directory-entry callers to skip redundant checks.

  • src/tesk_core/transput.py L252-262, L272-275

Uses of the API

Apply safe opening and link checks across HTTP, FTP, S3, and file outputs, including glob matches, and handle inaccessible uploads cleanly.

  • src/tesk_core/filer.py L32-39, L200-205, L371-376 (+3 small edits)
  • src/tesk_core/filer_s3.py L13, L146-154, L188

Configuration

Copy task volume mounts before mutation and make them read-only only for the outputs filer.

  • src/tesk_core/filer_class.py L14-17, L228-231, L284-291 (+1 small edits)

Documentation

Document output symlink restrictions and the required executor upgrade behavior.

  • docs/filer.md L31-43
  • docs/upgrading.md L9-18

Tests

Cover symlink detection, safe opens, protocol behavior, glob matches, and read-only output mounts.

  • tests/unit/test_filer_symlinks.py L1-325

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Comment thread tests/unit/test_filer_symlinks.py Fixed
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.15%. Comparing base (03de79f) to head (94e98c7).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #124      +/-   ##
==========================================
+ Coverage   94.62%   95.15%   +0.52%     
==========================================
  Files          10       10              
  Lines        1377     1424      +47     
==========================================
+ Hits         1303     1355      +52     
+ Misses         74       69       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

CodeQL took the fixture's sample credentials for stored secrets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg marked this pull request as ready for review November 9, 2026 02:44

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/tesk_core/transput.py" line_range="269" />
<code_context>
             self.ftype,
             url_for_log(self.url),
         )
+        if check_links and output_has_symlink(
+            self.path, recursive=self.ftype == Type.Directory
+        ):
</code_context>
<issue_to_address>
**Symlink replacements escape output paths**

When another process can modify the shared task volume after validation and before a path or glob match is opened or copied, `Transput.upload` uses paths after `output_has_symlink` checks them, but `open_for_upload` protects only the final component, and `file:` copies re-expand globs and follow links. A replaced ancestor or directory entry therefore lets the filer read or upload data outside the intended task paths.

Use a race-safe traversal and transfer strategy that prevents or detects symlink replacement for every path component and glob match.

Also at `src/tesk_core/transput.py:191`, `src/tesk_core/filer.py:231`, `src/tesk_core/filer.py:369-371`, `src/tesk_core/filer.py:474`, `src/tesk_core/filer_s3.py:188`.
</issue_to_address>

### Comment 2
<location path="src/tesk_core/filer.py" line_range="199" />
<code_context>
         # because requests sends an empty file object with chunked encoding,
         # which presigned upload URLs such as S3's reject.
-        with open(self.path, "rb") as file:
+        with open_for_upload(self.path) as file:
             data = file if os.fstat(file.fileno()).st_size > 0 else b""
             try:
</code_context>
<issue_to_address>
**Upload open errors escape filer**

When a file open fails in the HTTP or FTP upload path, including when `O_NOFOLLOW` rejects a link introduced after validation, `open_for_upload` raises `OSError`, but the HTTP and FTP upload paths do not convert it to a failed-output result; `process_file` catches only `InvalidURL`, so the exception escapes and aborts output processing instead of reporting the affected output as failed.

Catch `OSError` in the HTTP and FTP upload paths, log the output failure, and return 1 consistently with S3.

Also at `src/tesk_core/filer.py:891`.
</issue_to_address>

Linked issues

#114 fix(filer): do not follow symbolic links in outputs · 6 of 6 met

# Requirement Status Notes
1 Refuse symbolic links in output paths and directory contents, and open upload files with O_NOFOLLOW. ✅ Met The shared output check examines path components and walks directories without following links; HTTP, FTP, and S3 use open_for_upload.
2 For file: outputs, copy links as links or refuse them. ✅ Met FileTransput rejects linked output paths and checks each glob match before copying.
3 Apply the link handling to HTTP, S3, FTP, and file: outputs. ✅ Met All four output implementations use the shared output check.
4 Mount the task volume read-only in the outputs filer where possible. ✅ Met Filer.get_spec sets readOnly on task-volume mounts for outputs and removes it for inputs; the claim mounts are copied first.
5 Add regression tests for symlinked file and directory outputs over HTTP, S3, FTP, and file:. ✅ Met The new tests cover linked files, linked directories, links below directories, and each protocol.
6 Document output-link handling in the filer and upgrading docs. ✅ Met Both docs/filer.md and docs/upgrading.md describe the behavior.

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: src/tesk_core/transput.py:269, src/tesk_core/filer.py:199


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/tesk_core/transput.py Resolved
Comment thread src/tesk_core/filer.py Resolved
HTTP and FTP uploads log an output that can't be opened (e.g. a
symbolic link refused by O_NOFOLLOW, or a missing file) and fail it
with 1, as S3 uploads do, instead of raising; FTP uploads also fail an
output whose read or connection fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit a10a257 into dev Nov 9, 2026
19 checks passed
@uniqueg
uniqueg deleted the fix/114-output-symlinks branch November 9, 2026 04:44
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.

fix(filer): do not follow symbolic links in outputs

2 participants