Confine attachment reads to canonical root #10

Merged
Collaborator

Summary

Attachment reads now require a strict descendant of the configured attachments root after resolving symlinks. The validated canonical path is used for stat and read, preserving the displayed filename and existing errors.

- allow raw prefixes of attachmentsRoot, /tmp/, or /private/tmp/
+ resolve the configured root and candidate with realpath
+ require candidate path components to be strictly below root
+ stat and read that same canonical candidate

Evidence

  • Before: Five regression scenarios failed on the original reader (six assertions): default temporary-file access, shared-prefix siblings, file and directory symlink escapes, and the canonical spelling of a symlinked configured root. The independently measured pristine blade baseline had 30 tests, three smoke skips, no failures.
  • After: All 10 attachment-path tests pass. The full coverage run passed 38 blade tests (three live-smoke skips) and 34 MessagesCore tests, with no failures. Native build passed. Tests also preserve target-size enforcement and symlink display filenames.
  • Independent SVD integration verified head 0675815f98f7caa6777ed75cefa2fb77286bad8b: build green, blade suite green, spec fidelity and reader audit clean, zero blockers, ready for merge. Run 20261116T114111Z-8827a41a.
  • SwiftPM used an external scratch directory; --disable-sandbox was required for the dispatch coverage run because nested sandbox activation failed. Remote CI has no statuses and is reported as absent. make lint remains red against the repository's existing formatting baseline; pristine main independently reports 5,699 formatter diagnostics with the available Xcode formatter.

Merge Danger

Door: two-way

A code revert restores the prior behavior; there is no migration.

Blast Radius: attachments

Callers using temporary attachment fixtures must explicitly configure their attachments root. MessagesCore store-path policy is unchanged. This fixes path confinement but leaves the disclosed check-then-use race between canonicalization and reading; descriptor-based hardening requires separate work.

Closes #2

Co-Authored-By: gpt-6.1-terra noreply@openai.com

## Summary Attachment reads now require a strict descendant of the configured attachments root after resolving symlinks. The validated canonical path is used for stat and read, preserving the displayed filename and existing errors. ```diff - allow raw prefixes of attachmentsRoot, /tmp/, or /private/tmp/ + resolve the configured root and candidate with realpath + require candidate path components to be strictly below root + stat and read that same canonical candidate ``` ## Evidence - **Before:** Five regression scenarios failed on the original reader (six assertions): default temporary-file access, shared-prefix siblings, file and directory symlink escapes, and the canonical spelling of a symlinked configured root. The independently measured pristine blade baseline had 30 tests, three smoke skips, no failures. - **After:** All 10 attachment-path tests pass. The full coverage run passed 38 blade tests (three live-smoke skips) and 34 MessagesCore tests, with no failures. Native build passed. Tests also preserve target-size enforcement and symlink display filenames. - Independent SVD integration verified head `0675815f98f7caa6777ed75cefa2fb77286bad8b`: build green, blade suite green, spec fidelity and reader audit clean, zero blockers, ready for merge. Run `20261116T114111Z-8827a41a`. - SwiftPM used an external scratch directory; `--disable-sandbox` was required for the dispatch coverage run because nested sandbox activation failed. Remote CI has no statuses and is reported as absent. `make lint` remains red against the repository's existing formatting baseline; pristine main independently reports 5,699 formatter diagnostics with the available Xcode formatter. ## Merge Danger **Door:** two-way A code revert restores the prior behavior; there is no migration. **Blast Radius:** attachments Callers using temporary attachment fixtures must explicitly configure their attachments root. MessagesCore store-path policy is unchanged. This fixes path confinement but leaves the disclosed check-then-use race between canonicalization and reading; descriptor-based hardening requires separate work. Closes #2 Co-Authored-By: gpt-6.1-terra <noreply@openai.com>
Resolve attachment paths and the configured root before comparing path components, and use the validated path for file checks and reads. Remove implicit temporary-directory access, add confinement regression tests, and document the behavior change.

Closes #2
Co-Authored-By: gpt-6.1-terra <noreply@openai.com>
Sign in to join this conversation.
No description provided.