Skip to content

fix(core): refuse a nonregular session record without blocking - #432

Merged
ElbertePlinio merged 3 commits into
mainfrom
fix/410-bounded-record-read
Oct 29, 2026
Merged

ElbertePlinio merged 3 commits into
mainfrom
fix/410-bounded-record-read

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

getSession read the session record with a plain readFile. A FIFO at the record path blocked that read with no limit, so the owned display check (#219) and the permit gate before it could hang past the 3 s input budget. The sessions directory is private to the user, so only a process of the same user could plant one.

getSession now opens the record once with O_RDONLY | O_NONBLOCK, checks the opened descriptor, and refuses anything that is not a regular file with Session record at <path> is not a regular file, before any read. It reads through the same descriptor, so a FIFO swapped in after any earlier check of the path is refused too. A missing record and invalid JSON give the same results as before. The fix sits in getSession and not only in the ownership check, because withAgentPermit reads the record before the ownership check runs. Every caller now gets an error instead of a hang for a FIFO record, and listSessions already skips records that throw.

Closes #410

Requirement Verified by Scenario and edge cases Result Evidence
Bounded, non-blocking record read in the ownership check Unit tests on core and desktop-linux FIFO at the record path for getSession, the typing check, verifyOwnedDisplayTarget, typeText, click and pressKey; a record swapped for a FIFO holding valid JSON after a path check Refused in well under 1 s, no X connection and no xdotool call; the new tests time out or fail on the old code 410/before.log, 410/before-swap.log, 410/after.log
Refuses a non-regular record file Unit tests, CLI QA on a private session Normal record, FIFO record for desktop type and desktop click Normal typing works; with a FIFO both refuse in about 480 ms with the clear error 410/qa/
Existing behavior kept Focused and full suites Missing record, invalid JSON, input closure across teardown and prune Unchanged 410/full/

QA ran with a temporary PICKFORGE_HOME and a CLI-created session on its own Xvfb; the record was swapped for a FIFO and restored before teardown.

Sol review, 2 rounds: round 1 4/10 (blocker: the path was checked with stat and read again, so a FIFO swapped in between was read; should: no deadline around the read under libuv threadpool starvation). Round 2 9/10: the single-descriptor read resolves the blocker, with a swap test that fails on the first version; the should is settled, because validateOwnedTarget refuses a read that returns after the 3 s budget, and Sol found no late input path.

Checks on 153b2a4 (before the merge of main, which only brought the test fixes from #430): oxlint, typecheck, build; full vitest coverage run with the desktop, window, wait, browser and viewer requirements on (191 files, 3425 passed, 4 skipped); PICKFORGE_REQUIRE_XVFB=1 cargo test --workspace --locked (328 passed). PickCheck 0.4.0 against main is clean.

getSession read the record with a blocking readFile, so a FIFO at the
record path stalled the agent permit gate and the owned display check
past their deadlines. Refuse a record that is not a regular file and
open it with O_NONBLOCK.

Closes #410
getSession opens the record once with O_NONBLOCK and checks that descriptor before reading, so a FIFO swapped in after a path check is refused.
@ElbertePlinio
ElbertePlinio merged commit 220044b into main Oct 29, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/410-bounded-record-read branch October 29, 2026 13:36
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.

desktop: bound the session record read in the owned display check

1 participant