Skip to content

fix(desktop): refuse symlink exception cards on Windows - #2532

Closed
abrichr wants to merge 2 commits into
mainfrom
grok/fix-windows-stop-queue-cards
Closed

abrichr wants to merge 2 commits into
mainfrom
grok/fix-windows-stop-queue-cards

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Desktop's exception-card reader is supposed to skip a link and, on POSIX, skip a file other users can read. On Windows, os.O_NOFOLLOW may be missing or a no-op, so test_a_linked_card_is_not_read still saw the card. The answer-mode assertion also failed because Windows st_mode is often 0o666 (438), not 0o600.

This keeps the POSIX checks intact: _read still uses O_NOFOLLOW and still rejects group/other permission bits only on POSIX, and _write_exclusive still opens the answer file with mode 0o600. _read now also lstats the path and refuses a symlink, which is what actually excludes links on Windows. The 0o600 assertion and the "other users can read" test stay strict on POSIX and are not run as POSIX bit checks on Windows.

The pull request also bumps openadapt-desktop from 0.31.0 to 0.31.1. That patch bump is only because the desktop release-intent check requires a version change for a fix that should ship. Merging this pull request ships Desktop 0.31.1 through the normal release pipeline.

The Rust lockfile audit failure comes from upstream advisories in the existing lockfile (RUSTSEC-2026-0221, RUSTSEC-2024-0429, RUSTSEC-2026-0486, and a yanked async-executor). It is not related to this change: Cargo.lock differs from main only in the openadapt-desktop version string.

Observed on:

  • d30166be Packages 45007372801, desktop Python engine tests windows-latest py3.12 job 137167041107 and py3.11 job 137167041148
  • 923f0a04 Packages 45013930658, desktop Python engine tests windows-latest py3.12 job 137183885862 (same three tests; Ubuntu and macOS stayed green)

_read relied on os.O_NOFOLLOW, which may be missing or a no-op on
Windows, so a card replaced with a symlink was still shown. lstat
the path first and refuse a link, and keep O_NOFOLLOW on POSIX.

The POSIX 0o600 and group/other-bit checks are unchanged. The tests
assert those permission bits only on POSIX, where st_mode carries them
(Windows often reports 0o666 / 438).
The Windows exception-card symlink fix should ship, so this bumps
openadapt-desktop from 0.31.0 to 0.31.1 and records the changelog.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: c62b703

Independent cross-vendor adversarial review of c62b703e86b6ee9eebb170017d810cc506002ddf (Grok-authored; I authored none of this PR).

Findings & fail-closed verification

  • Windows symlink refusal & POSIX safety preserved: exception_queue._read now checks stat.S_ISLNK(os.lstat(path).st_mode) (returning None on symlink or OSError) before os.open, closing the gap where os.O_NOFOLLOW is absent/no-op on Windows. On POSIX, atomic O_NOFOLLOW, O_CLOEXEC, fstat regular-file/size/owner checks, and the info.st_mode & 0o077 group/other permission refusal remain completely intact. (Note: on Windows a narrow pre-open lstat→open window is inherent to Python's os.open, consistent with open_cards's folder lstat check, and cards remain content-addressed by SHA-256 in valid_card.)
  • Cross-platform test accuracy: test_a_linked_card_is_not_read remains active on Windows; only the POSIX st_mode == 0o600 bit check and POSIX group/other permission-bit test are scoped to os.name == "posix", matching _read's existing POSIX-only permission-bit gate.
  • Release bump hygiene: Version bump 0.31.0 → 0.31.1 is consistent across all desktop manifests, lockfiles (Cargo.lock, uv.lock, package-lock.json), __init__.py, and CHANGELOG.md with no unrelated dependency changes.

Generality gate

  1. No per-app code in engine: Verified; operates purely on OS filesystem symlink/permission checks in openadapt_desktop.exception_queue.
  2. Fix the class, not the instance: Verified; enforces symlink refusal in the single _read entry point used for all exception cards on Windows while preserving POSIX guarantees.
  3. Held-out evidence: Verified via cross-platform unit tests across Ubuntu, macOS, and Windows CI runners; no real customer environment was exercised (and the single unrelated CI failure is the pre-existing upstream Rust lockfile advisory check).

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Superseded by #2533 (7afc296d), which already fixes the Windows stop-queue symlink break (pre-open lstat / reparse-point refusal, O_NOFOLLOW kept on POSIX, POSIX 0o600 / 0o077 checks intact) and whose windows-latest py3.11/py3.12 desktop engine tests passed on Packages 45030291953. Closing this PR; the branch is left in place.

@abrichr abrichr closed this Nov 22, 2026
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.

1 participant