Skip to content

The development trace store's temporary folder is private to its user - #2313

Merged
marvin-bitterlich merged 1 commit into
mainfrom
ccr-efcafb6c-sxkls9-trace-store-temp
Nov 18, 2026
Merged

marvin-bitterlich merged 1 commit into
mainfrom
ccr-efcafb6c-sxkls9-trace-store-temp

Conversation

@marvin-bitterlich

Copy link
Copy Markdown
Contributor

Why?

#2298 gave a development host whose working directory has no node_modules a trace store under the system's temporary directory, in shivaedev-server-<hash of the working directory>/traces.db. Anyone who knows the working directory can work out that name. On a machine where users share /tmp, another user could make the folder first and read the traces, or put a link there and have the store written somewhere else. The folder was also created with the default mode, so others could read it.

How?

The stable folder is now shivaedev-server-<user id>-<hash>. The host creates it with mode 0700 and then looks at what holds the name, without following a link. It uses the folder only when all of these are true:

  • it is a real folder, not a link or a file
  • this user owns it
  • group and others have no permission on it

Otherwise it records in a folder made by mkdtemp, which is new and private every time. The one Info line at startup still names the store, and in that case also names the folder it refused:

Development traces are recorded to /tmp/shivaedev-server-d6VKSz/traces.db, because /srv/app has no node_modules folder and /tmp/shivaedev-server-1000-6bc42ab4a29b is not a folder that only this user can reach.
What holds the stable name Before Now
Nothing folder created with the default mode folder created 0700 and used
This user's folder, 0700 used used, same path on every start
This user's folder that others can reach used refused, fresh folder
A link followed refused, fresh folder
Another user's folder used refused, fresh folder

The stories use the existing traceStoreLocation kit, which starts a real Node process with its own TMPDIR. The kit gained verbs that open the folder to others, put a link in its place and hand it to another user, and readouts for the announced folder's owner and mode, the refused folder and the folder behind the link. On main, four of the six stories fail; the node_modules story and "a second start records to the same store" pass there and guard what did not change.

Decisions

  • The simplest design that closes the three cases: the user id in the name, owner-only creation, one lstat check, mkdtemp as the fallback. No lock file, no per-user parent folder and no configuration.
  • A refused folder is left alone. The host does not repair permissions or remove a link; it cannot know who made them. The log line names the folder so its owner can remove it.
  • While the stable name stays refused, every start gets a new folder, so earlier traces are not found at a stable path and the fresh folders are not cleaned up. This is the safe side of a state that needs a person to look at it.
  • On Windows the name has no user id and only "is a real folder" is checked. Node has no user ids there, and each user has a temporary directory of their own.
  • Patch with ### Fixed. No API changes. The path changes once, from shivaedev-server-<hash> to shivaedev-server-<user id>-<hash>; the store there starts empty and the old folder is left behind.

Callouts

  • The sandbox runs as root. The stories did exercise the changed mode, the link and the changed owner (through chown, which only root may do, so that story runs only as root and is skipped on a non-root CI runner). They did not exercise a second real user: no process without access tried to read the folder, so the kernel's enforcement of 0700 is taken as given.
  • Access control lists are not read; only the owner and the mode bits are.
  • Between the check and the first write the folder could only be swapped by its owner or by root, in a temporary directory with the sticky bit. A temporary directory without it is outside what this protects.
  • defaultTraceStore changed from Effect.sync to Effect.try, because creating a folder can fail. Its one caller already had UnknownError in its error type from opening the database.
  • Nothing ran on Windows or macOS.

Generated by Claude Code

A working directory without node_modules records traces under the
system's temporary directory, in a folder named only after a hash of the
working directory and created with default permissions. On a shared
temporary directory another user could make that folder or a link first
and read or redirect the traces.

The folder's name now carries the user's id, it is created with mode
0700, and it is used only when it is a real folder owned by this user
with no access for others. Otherwise the host records in a folder made
by mkdtemp, and the one startup log line names both.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VjCSiB3Dk7BRBmjic6wFM5
@marvin-bitterlich
marvin-bitterlich added this pull request to the merge queue Nov 18, 2026
@tally-code-quality

Copy link
Copy Markdown

Coverage 91.9% (−0.1 pts) · Patch 16.7%

15 of 18 added lines are not covered, in 2 files.

Uncovered added lines

Components · @shivaedev/server −1.3 pts · @shivaedev/test-sql −0.6 pts · 2 more
Component Coverage vs main
@shivaedev/server 94.1% −1.3 pts
@shivaedev/test-sql 96.6% −0.6 pts
@shivaedev/test-story 92.3% −0.2 pts
@shivaedev/sql 93.7% −0.1 pts

1e45a1b (merged onto 64d4061) vs main at 64d4061 · updated Nov 18, 16:29 UTC · Full report

Merged via the queue into main with commit 051c662 Nov 18, 2026
20 checks passed
@marvin-bitterlich
marvin-bitterlich deleted the ccr-efcafb6c-sxkls9-trace-store-temp branch November 18, 2026 16:38
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.

2 participants