Skip to content

fix(files): serve a rendered page's files and media from the descriptor that was checked - #1892

Merged
devswha merged 7 commits into
mainfrom
fix/file-view-descriptor
Oct 25, 2026
Merged

devswha merged 7 commits into
mainfrom
fix/file-view-descriptor

Conversation

@devswha

@devswha devswha commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

What

When the file viewer draws an HTML page an agent wrote (Page), the server puts the page's own pictures, scripts and stylesheets into it and gives a video too large for that a short-lived address under /api/fs/page-media/. Until now both checked a path and then read it again by path (readFileSync, Bun.file). A folder swapped for a link between the check and the read could put another file's bytes into the page, where its script can read them, or under its video address.

Now each of those files is opened once and read only from that descriptor, after the opened file itself was shown to lie where the page may reach (openAuthorized in server/file-view.ts):

  • The open: O_RDONLY | O_NONBLOCK | O_NOFOLLOW. It must be a regular file with a nonzero inode, and the requested path, resolved again, must still name it (same device and inode).

  • Linux: the kernel's path of the descriptor (/proc/self/fd/<fd>) must lie in the page's folder or an OVIS_MEDIA_ROOTS folder, with no hidden name below it. An unreadable path, or one marked (deleted), is refused, and nothing falls back to a path check.

  • macOS: every folder from that root down to the file's own must be a real folder owned by the server's user and writable by no group or other user. This does not claim protection against the same user.

  • Windows: the second resolution and identity check only. Anyone allowed to write a folder on the way is outside the single-user model; documented, with no ACL claims.

  • Other platforms put no files into the page and mint no addresses.

  • The page itself: its path is resolved once, before the open; a page that is a symlink resolves to the file it leads to. That file is opened (O_NOFOLLOW) and proven from its descriptor, never by a second lookup:

    • Linux: its /proc/self/fd path must be that path.
    • Elsewhere: that path must be a file with the descriptor's device and inode that still resolves to itself.

    After the open, the asked path must still resolve to that file. The page's files come from that file's folder. A symlinked page still draws, taking its files from the folder it leads to, the only folder its one lookup proves (main took them from the link's folder).

  • Embedded files are read from their descriptor and rechecked for size and modification time.

  • A media address is minted only from a checked descriptor. Every request reopens and re-checks the file, and compares identity, size and modification time with what the render saw. It then streams from the descriptor in 256 KB positional reads, never the whole file. Answers are 200, HEAD, a single-range 206 and 416, per RFC 9110 section 14: another unit, several ranges, a malformed range, an If-Range or a HEAD get the whole file, and so does an empty file. The descriptor is closed exactly once, on end, error or client cancel.

  • server/file-routes.ts passes the request on, so Range and HEAD reach the stream.

What users see does not change. Root, hidden-name and symlink rules are not loosened (links into allowed folders keep working), and the sandbox, CSP and cross-site gates are untouched. DESIGN.md states each platform's guarantee and its limits. docs/guide.md adds the macOS ownership rule to OVIS_MEDIA_ROOTS.

This ports the two fix commits of the unpushed fix/descriptor-bound-page-files branch onto current main, without its twelve screenshot-stabilizing commits. Review findings are fixed here as well, in a second commit. The page's folder used to be resolved after the page was read; it is now resolved first, and the page read must be the file of its name in that folder. Range and HEAD handling now follows RFC 9110.

Security change: this needs a real review (it is the file-serving authorization path, and changes the /api/fs/page-media HTTP answers).

Fixes #1609

How it was verified

  • bun test ./server/file-view.test.ts on Linux: 61 pass, 0 fail. The new tests cover:
    • the three-swap race against embeds, minting and media reopen;
    • the page's folder swapped while the page is read, swapped around its lookup and put back before the open, swapped between its lookup and the open and left so, a link only while the path is looked up, and a link only while the page is opened (each also with the other platforms' samples);
    • a page that is itself a link draws, with its files from the folder it leads to;
    • /proc unreadable or (deleted);
    • the macOS folder rule (group or world writable, another owner);
    • the Windows recheck;
    • inode 0, a FIFO, and leaf links;
    • writes after authorization and during a stream;
    • over real HTTP: Range, HEAD (with and without a Range), 416, ignored ranges, If-Range, an empty file, and close-once on cancel during a read.
  • Mutations, each restored afterwards:
    • an always-passing /proc check fails the three swap tests;
    • resolving the folder after the read fails the new folder test;
    • dropping the page identity check fails the swap-and-restore test (and the leak reproduces);
    • dropping the (deleted) check fails the fail-closed test;
    • letting HEAD honor Range, answering 416 for an empty file, or skipping the asset fstat each fail their test;
    • dropping request in file-routes.ts fails page-media.contract (206 expected, 200 received).
  • macOS, real darwin (fresh clone on the test MacBook Air): 57 pass, 3 skipped (the Linux-only swap tests), 0 fail.
  • A live loopback server, driven with curl -i using the page's own fetch headers:
    • 200 sent all 9,437,184 bytes, identical to the file;
    • 206 returned exact Content-Range bytes for a closed and a suffix range;
    • HEAD returned the length with an empty body;
    • 416 returned bytes */9437184;
    • a guessed token got 404;
    • the descriptor ledger shows 15 opened and 15 closed, none twice.
  • scripts/file-viewer-regression.ts in Chrome: a new step plays and seeks a rendered page's 9 MB recording from its address, refuses it once lapsed and once revoked, and checks every descriptor closed once. It passes on the final commit, where the whole script reports 62 PASS lines.
  • bun run check fast on the final commit: 6,421 pass, 0 fail.
  • bun run check run bun test --timeout 15000 ./server/api.contract.test.ts ./server/page-media.contract.test.ts on the isolated herdr: 160 pass, 0 fail.
  • Reviews: omo-native-code-reviewer and Codex (Sol 6.1, xhigh), over three rounds. Both reproduced the page-folder races fixed above; Codex did so with a real concurrent folder exchange, with nothing mocked. The last round approved after rerunning that race for 10 seconds with no hooks:
    • before the second commit, 41,725 of 136,785 renders leaked the hidden folder's image;
    • after it, 0 of 149,544 did;
    • with a page.html of its own in the hidden folder, 0 of 241,195 did.

Not run: native Windows. The Windows test PC has been offline since before this work, and CI's Windows job does not run these tests.

mp added 3 commits October 24, 2026 23:11
…or that was checked

A rendered HTML page's own pictures, scripts and stylesheets, and the videos it
plays from /api/fs/page-media, were checked by path and then read again by path,
so a folder swapped for a link between the check and the read could put another
file's bytes into the page or under its media address.

Each such file is now opened once (O_NOFOLLOW, O_NONBLOCK), must be a regular
file whose path still names it, and is proven per platform before any byte is
read or an address minted: on Linux the descriptor's own /proc/self/fd path must
lie in the page's folder or an OVIS_MEDIA_ROOTS folder with no hidden name
(unreadable or deleted fails closed); on macOS every folder from that root down
must be owned by this user and writable by no group or other user; Windows keeps
the post-open identity recheck only (documented); other platforms authorize
nothing. The page's folder is resolved before the page is opened. A media
address reopens and re-checks on every request, plays only while the file has
the identity, size and modification time its render saw, and streams from its
descriptor in bounded positional reads with 200, HEAD, a single-range 206 and
416 (RFC 9110: another unit, several ranges or If-Range send the whole file),
closing the descriptor exactly once.

Ported from the unpushed fix/descriptor-bound-page-files branch, without its
screenshot-stabilizing commits.

Fixes #1609
…es come from

A page's folder was resolved before the page was opened, but a folder swapped
for a link around that lookup and put back before the open still made the
link's target the folder the page's files were allowed from. The page read must
now be the file of its name in that folder (same device and inode), or it is
refused.

A HEAD ignores Range and describes the whole file (RFC 9110 defines a range for
GET alone), and an empty file is sent whole whatever range is asked. The
failing-fstat test now fails the page's files and not the page itself, so it
checks what it names.
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 35 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4c8ce30 and 959af71.

Files selected for processing: 7
  • DESIGN.md
  • changelog.d/descriptor-bound-page-files.md
  • docs/guide.md
  • scripts/file-viewer-regression.ts
  • server/file-routes.ts
  • server/file-view.test.ts
  • server/file-view.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit was rate-limited on this PR, so no CodeRabbit review ran. The PR changes the /api/fs/page-media HTTP answers and the file-serving authorization path, so a code-review agent's review stands in, as AGENTS.md asks. Two independent reviewers looked at it over three rounds: omo-native-code-reviewer, and Codex (gpt-6.1-sol, fast, xhigh). Their findings and how each was resolved:

Round 1 (on the port, ac5cde683 before the follow-ups)

  • HIGH, reproduced by both reviewers. The page's folder was resolved by path after the page was read. A folder swapped for a link in between made the link's target the permitted root, so its files were embedded and its videos got addresses. Resolved: the folder is resolved before the page is opened. A test swaps the folder while the page is read. Moving the lookup back after the read fails that test.
  • MEDIUM. The (deleted) half of "fails closed on unreadable or deleted descriptor path" could not fail. Its hook threw inside the authorization, so the render was refused either way. Resolved: it counts authorizations instead. Removing the (deleted) check now fails it.
  • LOW. Range answered 416 for a header it should ignore: an unknown unit, several ranges, or a malformed range. Resolved: these now get the whole file (200), per RFC 9110 section 14. Unit names are case-insensitive, If-Range gets the whole file (the answer names no validator it could match), an end past the last byte is clamped, and 416 is kept for a range that starts past the end.
  • LOW. On macOS a share owned by another user, or one others may write to, plays nothing. This follows the rule Server: serve page media from the file that was actually checked #1609 sets. Resolved: docs/guide.md (OVIS_MEDIA_ROOTS) and the mediaRoots comment now say so.
  • LOW, not changed. pageFileHooks test seams are read on production paths. Each costs one property lookup, and the pattern follows the existing seams.
  • NOTE. A full 200 and a multi-chunk 206 go out chunked, without Content-Length. That is valid HTTP, and HEAD gives the length.

Round 2 (on ac5cde683)

  • HIGH, reproduced by both. Codex reproduced it with a real concurrent folder exchange, with nothing mocked. A folder swapped for a link only while its path was resolved, and put back before the page was opened, still made the link's target the root. Resolved in 49047e43e: the page read must be the file of its name in that folder (same device and inode), or the page is refused with 404. A page that is itself a symlink keeps its link's folder as root, as on main.
  • MEDIUM. HEAD with a Range answered 206. RFC 9110 defines a range for GET alone. Resolved: HEAD describes the whole file.
  • LOW. An empty file answered a suffix range with 416. Resolved: an empty file is sent whole for any range.
  • LOW. The failing-fstat test failed the page's own read, so it never reached the files' checks. Resolved: only the page's files fail now, and the test asserts that the page still renders.

Round 3 (on 49047e43e): APPROVE, no blockers. The reviewer reran the race for 10 seconds with no hooks:

Commit Renders Leaked the hidden folder's image
ac5cde683 136,785 41,725
49047e43e 149,544 0
49047e43e, hidden folder with its own page.html 241,195 0
  • MEDIUM. The new swap-and-restore test did not reach the inode comparison. Resolved in 10bc4cbef: the swapped-in folder now holds a page.html of its own. Removing the comparison alone now fails the test.

Known residuals, stated in DESIGN.md

  • A root is a path. Someone allowed to rename folders in its parent could move another real folder into its place while the page's files are looked up.
  • macOS does not protect against the same user's own processes.
  • Windows keeps only the post-open identity recheck.

Not run: native Windows. The Windows test PC has been offline, and CI's Windows job does not run server/file-view.test.ts.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass gate review of 10bc4cb: one blocker. The page document can still come from outside its folder. Assets and media hold up.

Blocker (reproduced): a folder swapped right after it is resolved still serves an outside page

  • Where: server/file-view.ts:622-632. The server resolves the page's folder, and only then opens and re-stats the page by path.
  • Reproduction: the gate swapped the folder for a symlink to an outside folder just after resolution and left the link in place. Both later path checks then agree on the outside file. The response was HTTP 200 with <p>OUTSIDE-PAGE-SECRET</p>; it should have been 404.
  • Why it counts: Server: serve page media from the file that was actually checked #1609 asks that page documents, too, be read only from the descriptor that was checked, and that a swapped path serve no outside bytes.
  • Why the tests miss it: they cover a swap during the read, and a swap that is put back before the open. They don't cover a swap that stays in place after the folder is resolved.

Fix: open the page with the same openAuthorized descriptor rule as its assets: O_NOFOLLOW, then confine the descriptor's own path (/proc/self/fd, and the macOS walk) to the folder. Add a regression for a swap that stays in place.

Holds

  • Baseline: 59/59 file-view tests pass, and 5 of the gate's 6 probes pass. The failing probe is the page swap above.
  • Assets and media: swaps on images, scripts, stylesheets, page-media minting and reopening are all refused. A mutant that disables the /proc/self/fd check fails all three of the PR's swap tests.
  • Descriptors: every one is closed exactly once, including on refusals, errors, HEAD, 416, ranged reads and a mid-read client cancel. The fd count is unchanged after the probe.
  • FIFO: a FIFO is refused before any read, with no blocking.
  • Hidden names: they are refused after the /proc lookup.
  • On eamac (macOS): server/file-view.test.ts passes, 56/56.

Windows has no descriptor-path check (documented as outside the single-user threat model). The merge pass re-checks the fix commit, looking only at the changed range.

The page's folder was fixed before the page was opened, but the page itself was
still opened by path: a folder swapped for a link to another folder just after it
was resolved, and left so, served that folder's page (the merge pass's gate
reproduced an outside page answered with 200).

The page's own path is now resolved together with its folder, before the open,
and the page read must be that file: on Linux the kernel's path of its descriptor
(an unreadable one fails closed), elsewhere its path resolved again after the
open. A page that is itself a link is the file it leads to and keeps taking its
files from the link's folder, as before; a test now holds that.
@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Thanks. The blocker is reproduced and fixed in 3fbf8d6.

What changed: pageWithLocalFiles now resolves the page's own path together with its folder, before the page is opened. The page read must be that file:

  • on Linux, through the kernel's path of its descriptor (/proc/self/fd/<fd> must equal the path resolved before the open). An unreadable path fails closed, and a (deleted) path never matches.
  • on other platforms, through its path resolved again after the open, a sample like their asset checks, as DESIGN.md says.

This runs alongside the existing check that the page is the file of its name in the folder (same device and inode). A folder swapped for a link just after it is resolved, and left so, now gets 404. DESIGN.md says this too.

Why not openAuthorized for the page itself: its O_NOFOLLOW open and its folder confinement would refuse a page that is itself a symlink to elsewhere, which renders on main, with its files taken from the link's folder. The descriptor-path check above refuses the swap you reproduced, and still lets that page render. A new test holds both:

  • "refuses a page whose folder becomes a link to another folder once it is resolved" is your case, with the link left in place. It answers 404 and holds none of the outside page's bytes.
  • "draws a page that is itself a link, taking its files from the link's folder" holds main's rule.

Mutations, each reverted afterwards:

  • an always-true page check fails the first test only;
  • a rule that confines the page to its link's folder fails the second only;
  • dropping the assets' (deleted) check fails "fails closed on unreadable or deleted descriptor path" only. That test now answers the page's own /proc lookup with its real path, so the failure still lands on the files' checks.

bun test ./server/file-view.test.ts: 61 pass, 0 fail. Typecheck is clean.

The CI failures on 10bc4cb were runner faults, not tests: three jobs ended with "The self-hosted runner lost communication with the server" before any step ran. 3fbf8d6 is pushed and starts a fresh run. Before the push, all three ran green on it through the shared heavy queue:

  • bun run check fast: 6,421 pass, 0 fail.
  • bun run check run bun test --timeout 15000 ./server/api.contract.test.ts ./server/page-media.contract.test.ts: 160 pass, 0 fail.
  • scripts/file-viewer-regression.ts: 62 PASS lines, including the page-media step.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass gate re-check of 3fbf8d6: the reported swap is fixed, but the fix opens a new window between its two lookups.

Fixed:

  • The original probe now gets a 404.
  • A swap after both lookups gets a 404.
  • A swap that is put back before the open gets a 404.
  • A swap during the read serves only the inside page.

Still open: a swap between the two lookups serves the outside page. The code is at server/file-view.ts:639-650.

  1. folder = realpathSync(dirname(path)) resolves the folder.
  2. site is then replaced with a link to outside, and the link stays in place.
  3. The new file = realpathSync(path) resolves to outside/page.html.
  4. The open, the stat and the descriptor-path check all agree on that file, so the server answers HTTP 200 with <p>OUTSIDE-PAGE-SECRET</p>.

The gate reproduced this with a real rename and a real symlink, between the two real lookups. The tests miss it because the pageFolder hook now runs after both lookups.

Fix: resolve the folder once, then check the opened descriptor against that single result, not against a second realpathSync.

  • Linux: require readlink(/proc/self/fd/<fd>) === join(folder, basename(path)).
  • macOS: use the equivalent walk.

A second path lookup can always be raced. Only the descriptor's own path, compared with the first resolution, closes this.

Please also move the test's swap hook so it runs between the folder resolution and the open.

Holds

  • Normal pages and their assets render.
  • File descriptors stay balanced on every path, including the new rejection.
  • The new check is caught by a mutant: the test gets 200 instead of 404.
  • 67 file-view and probe tests pass.

…its folder

The previous commit resolved the page's folder and then the page's own path in
two lookups, so a folder swapped for a link between them still served another
folder's page (the merge pass reproduced it with a real rename and symlink).

The folder is now looked up once; the page is opened as the file of its name in
that folder (O_NOFOLLOW) and proven from its descriptor alone: on Linux its
/proc/self/fd path must be that path; elsewhere that name must be a file with
the descriptor's device and inode that still resolves to itself. An HTML file
that is itself a symlink is therefore no longer drawn as a page (its Source view
still shows it), noted in the changelog fragment. The swap test's hook now runs
between the folder's lookup and the open, and also covers the other platforms'
samples.
@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

You're right, and thanks for the exact window. The second realpathSync(path) was a lookup an attacker could race. Fixed in 06b4e6c, as you proposed:

  • One lookup: the folder is resolved once.
  • The open: the page is then opened as join(folder, basename(path)), with O_NOFOLLOW.
  • The proof, from the descriptor alone:
    • Linux: readlink(/proc/self/fd/<fd>) must equal that path. An unreadable path fails closed, and a (deleted) path never matches.
    • macOS and Windows: that name must be a file (lstat, not a link) with the descriptor's device and inode, and must still resolve to itself. A folder swapped for a link and left in place fails this. Like the other non-Linux checks, these are samples, and DESIGN.md says so.
  • The hook: the test's pageFolder hook now runs between the folder's one lookup and the open. That is your window, and the test leaves the link in place. The test runs on this platform and again with darwin simulated, so it covers both branches.

One behaviour change, now in the changelog fragment: an HTML file that is itself a symlink is no longer drawn as Page. Its Source view still shows it, because the Page | Source toggle stays in the header. Seen from its descriptor, such a page can't be told from a folder swapped for a link, so refusing it is the cost of not doing a second lookup. If you'd rather keep symlinked pages, say so and I'll find another way.

Mutations, each reverted afterwards:

  • an always-true Linux descriptor-path check fails the swap test;
  • dropping the non-Linux realpath sample fails its darwin run.
  • Opening by the asked path, or without O_NOFOLLOW, are equivalent mutants: the descriptor-path check refuses both cases on its own. The "never draws the asked page with the files of a folder it was not read from" test guards the combination.

Tests: bun test ./server/file-view.test.ts gives 61 pass on Linux. On the test MacBook Air, in a fresh clone of this head, it gives 58 pass and 3 Linux-only skips. Before the push, the pre-push gate ran green on this head through the shared heavy queue:

  • bun run check fast: 6,421 pass, 0 fail.
  • bun run check run bun test --timeout 15000 ./server/api.contract.test.ts ./server/page-media.contract.test.ts: 160 pass, 0 fail.
  • scripts/file-viewer-regression.ts: 62 PASS lines, including the page-media step.

The earlier CI on 3fbf8d6 ended cancelled or failed on the self-hosted runners, not in a test step. The push starts a fresh run.

…up leads to

The previous commit stopped drawing an HTML file that is itself a symlink, to
avoid a second path lookup. Symlinked pages are a normal setup, so the page's
path is now resolved once (a link to the file it leads to), that file is opened
with O_NOFOLLOW and proven from its descriptor as before (Linux: /proc/self/fd
path; elsewhere: lstat identity and a realpath sample), and the page's files come
from that file's folder. A linked page therefore takes its files from the folder
it leads to, the only folder its one lookup proves; the changelog says so.
@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass gate re-check, round 3 (06b4e6c): the round 2 gap is closed, but the change reopens a schedule the previous commit refused.

Closed. A swap right after the folder lookup, with the link left in place, is now refused from the descriptor. The new test reaches that point, and it fails if the descriptor guard is removed. 77 tests pass. Normal pages, their assets and legitimate symlinked parent folders still render, and descriptors are closed.

Reopened: a swap that is put back before the open serves the outside page (server/file-view.ts:641-646). The gate reproduced it with a real rename and symlink:

  1. Rename the page's folder away, and put a symlink to an outside folder in its place.
  2. Let the folder lookup run. folder resolves to the outside folder.
  3. Put the real folder back before the open.
  4. The code opens join(folder, basename(path)), which is the outside page. Its descriptor path matches that same outside file, so the server answers HTTP 200 with <p>OUTSIDE-PAGE-SECRET</p>.

The same schedule gets a 404 on 3fbf8d6, because its second lookup no longer agreed. The test at server/file-view.test.ts:754-779 dropped its 404 assertion, so nothing catches this now.

Fix: keep the descriptor proof, and also check, after the open, that the requested path still resolves to the opened file (realpathSync(path) === file). A swap at any one moment then fails one of the two checks. Please restore the outside-document assertion in that test as well, so no schedule can return the outside bytes.

Note (not blocking): off Linux, the check is a sample: it can still race between lstat and realpath. That is fine within the documented single-user trust model.

…e opened

With one lookup, a folder that was a link only while the page's path was looked
up, and was put back before the open, made that lookup another folder's page
(the merge pass reproduced it on 06b4e6c with a real rename and symlink).

After the descriptor proof, the asked path must still resolve to the opened
file, so a swap at any one moment fails one of the two checks; a stable symlinked
page still draws. The swap-and-restore test asserts the 404 and the absence of
the other folder's page again, and a new test opens through a link put back
before the later checks, which only the descriptor proof refuses (pageOpened
seam).
@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Round 3 is fixed in 959af71 (the push also carries 19ea1bd). Thanks for keeping the proof honest.

19ea1bd, symlinked pages draw again. The owner's rule is usability over hardening, and symlinked pages are a normal setup:

  • Lookup: the page's path is resolved once, so a link resolves to its target.
  • Open: that file is opened with O_NOFOLLOW and proven from its descriptor, as in 06b4e6c.
  • Its files come from that file's folder, the only folder the one lookup proves. Keeping the link's folder would need the second lookup you showed is raceable. The changelog fragment says so.

959af71, your round 3 fix. After the descriptor proof, the asked path must still resolve to the opened file (realpathSync(path) === file). A swap at any one moment now fails one of the two checks, while a stable symlinked page still passes both:

  • In place only during the lookup, put back before the open: the post-open check refuses it. The test "refuses a page whose folder was a link only while its path was looked up" asserts the 404 again, and the absence of the other folder's page.
  • In place after the lookup and left there: the descriptor proof refuses it, and so does the post-open check.
  • A link after the lookup, put back right after the open: only the descriptor proof refuses this one. The new test "refuses a page opened through a folder that was a link only while it was opened" covers it through a pageOpened seam. It runs on this platform and again with darwin simulated.

Mutations, each reverted, and each fails exactly the test named:

  • no post-open path check: the looked-up-only test;
  • an always-true Linux /proc proof: the opened-through test;
  • no identity sample on other platforms: the opened-through test's darwin run;
  • files taken from the link's folder: "draws a page that is itself a link, taking its files from the folder it leads to".

Results:

  • bun test ./server/file-view.test.ts: 62 pass on Linux.
  • On the test MacBook Air, in a fresh clone of this head: 59 pass, 3 Linux-only skips, 0 fail.
  • The pre-push gate (check fast, the api.contract and page-media.contract suites, and scripts/file-viewer-regression.ts) ran on this head through the shared heavy queue before the push: all green (check fast ok; the two contract suites 160 tests pass; file-viewer regression ok).

Your note is taken: off Linux, the page check remains a sample, as DESIGN.md says.

@devswha

devswha commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review-work report. Overall: PASSED after four gate rounds.

Lane Verdict Confidence
Gate round 1 (10bc4cb) REJECT: the page document was still read by path, so a swapped folder served an outside page HIGH
Gate round 2 (3fbf8d6) REJECT: a swap between the folder lookup and the page lookup leaked the outside page HIGH
Gate round 3 (06b4e6c) REJECT: a swap restored before the open served the outside page; the test had lost its 404 assertion HIGH
Gate round 4 (959af71) APPROVE HIGH

What 959af71 does

  • The page's path is resolved once, opened with O_NOFOLLOW, and proven from its descriptor: on Linux /proc/self/fd, elsewhere lstat identity plus realpath.
  • After the open, the requested path must still lead to the opened file.
  • The page's files come only from that file's folder.

Gate evidence (round 4)

  • Four real rename/symlink timings: right after the lookup with the link left in place, put back before the open, during the read, and after the open. Each gives 404 or the inside page, never outside bytes.
  • Descriptors are closed on every path.
  • The outside-document assertion is back. Removing either guard makes it fail.
  • 72 file-view and conventions tests pass. Merge-pass QA also passes on eamac (macOS): 56/56 file-view.test.ts at 10bc4cb.

Assets and media (from round 1, unchanged): inlined images, scripts and stylesheets, page-media minting and reopening are all served from the checked descriptor. A FIFO is refused before any read, and hidden names are refused.

Accepted by the documented single-user contract

  • A page that is a symlink renders its target and that folder's assets.
  • Off Linux, the check is a sample.
  • Windows has no descriptor-path check.

All required checks are green and no review thread is open.

CodeRabbit did not review this PR (rate-limited or skipped). The reviews above stand in for it.

@devswha
devswha merged commit 8c88fa3 into main Oct 25, 2026
18 checks passed
@devswha
devswha deleted the fix/file-view-descriptor branch October 25, 2026 00:13
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.

Server: serve page media from the file that was actually checked

1 participant