Repository navigation
Refuse API paths that aren't in the diff - #121
Merged
Merged
Conversation
This was referenced Nov 19, 2026
david-crespo
added a commit
that referenced
this pull request
Nov 19, 2026
Built on #121, this is the first of three PRs that let another Node server mount `@oxide/skepsis` review pages. `buildDiffSource` turns the range flags (`-r`, `-f`, `-t`, `--interdiff`) into the diff command to run. It used to read the parsed flags from a top-level variable in `cli.ts` and call `process.exit` on a bad combination, such as `--interdiff` with `-r`. It now takes the flags as an argument and throws on bad ones, and the CLI catches the error and prints it and exits 1 as before. `buildApp` builds the routes and returns the `fetch` handler and the per-run token without binding a port, so the calling app can do what it wants with them. CLI behavior is unchanged. Most of the diff is code moving without modification. The first commit has the changes to `buildDiffSource`. The second moves it from `cli.ts` to `server/diffSource.ts`, and the third moves the routes from `server/main.ts` to `server/app.ts`. Of the roughly 390 non-blank lines those two commits remove, about 375 reappear unchanged. Apart from imports, the license headers of the two new files, and the tests described below, these are the lines in those two commits that are not straight moves: ```diff // commit 2: cli.ts → server/diffSource.ts -function detectVcs(): 'jj' | 'git' { +export function detectVcs(): 'jj' | 'git' { -function buildDiffSource(flags: { +export function buildDiffSource(flags: { // commit 3: server/main.ts → server/app.ts -export async function startServer(opts: { - port?: number - hostname?: string -}): Promise<{ port: number; token: string; close: () => void }> { - const { diffSource, port = 0, hostname = 'localhost', cwd, poll = true, send } = opts +export interface AppOptions { +} +export async function buildApp(opts: AppOptions, url: () => string) { + const { diffSource, cwd, poll = true, send } = opts - const env = { SKEPSIS_URL: serverUrl, SKEPSIS_ROOT: cwd } + const env = { SKEPSIS_URL: url(), SKEPSIS_ROOT: cwd } + return { fetch: app.fetch, token } // commit 3: what is left in server/main.ts +export async function startServer( + opts: AppOptions & { port?: number; hostname?: string }, +): Promise<{ port: number; token: string; close: () => void }> { + const { port = 0, hostname = 'localhost' } = opts + const { fetch, token } = await buildApp(opts, () => serverUrl) - const server = serve({ fetch: app.fetch, port, hostname }, (info) => { + const server = serve({ fetch, port, hostname }, (info) => { - `skepsis on ${serverUrl}/#token=${token} (${displayCommand(diffSource)})`, + `skepsis on ${serverUrl}/#token=${token} (${displayCommand(opts.diffSource)})`, ``` The second commit also changes tests. Three tests in `cli.test.ts` ran the CLI with a bad `--interdiff` combination and checked for exit code 1 and the message on stderr. They are now unit tests in `server/diffSource.test.ts` that check `buildDiffSource` throws the same messages, plus a fourth test checking that an interdiff's diff source has no endpoints. No test checks the CLI's exit code and stderr for these combinations anymore.
david-crespo
added a commit
that referenced
this pull request
Nov 19, 2026
Built on #122, this PR lets one process serve diffs from more than one repository. `jj` and `git` invocations, working-copy reads, and comment writes now take the repository directory as an argument. The static file middleware also receives an absolute path to the web files' directory, so nothing depends on the process's working directory. The CLI passes `process.cwd()`, so its behavior is the same. The directory is fixed when an app is built and each app has its own token, so a request can't choose a directory or reach another app's repository, and #121 keeps its file paths to the files in the diff. A new test builds two apps for separate repositories in one process and checks that each returns its own diff and file contents. About 160 of the 220 changed lines are tests: that test, and new unit tests for `buildDiffSource` and `detectVcs` in a directory other than the process's working directory. The source change is about 55 lines that add the directory argument.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/api/file-contentsand the two comment routes take a file path from the request and read or write that file under the repository directory. They didn't check the path, so one starting with../reached files outside the repository.GET /api/file-contents?path=../outside.txtreturnedoutside.txt, and the comment routes could rewrite it. These routes are behind the per-run token, so only the page could do this. It matters more for thecreateAppexport stacked on this PR (#124), where a host application can turn the token off and check requests itself.The routes now accept only a path in the latest diff, or a rename's old path, and return 400 otherwise. That also blocks files inside the repository that the diff doesn't show, such as an ignored
.env. When a path isn't in the last diff, the server runs the diff once more before refusing, so a file that just changed isn't rejected.The 71 changed lines are 36 for the check and 35 in tests. We checked that
/api/file-contentsreturns 400 for a file outside the repository and for an unchanged file inside it, and that both comment routes return 400 for the outside file and leave it unchanged. Both content requests returned 200 before the fix. The git test fixture now runsgit add --intent-to-add, because two existing tests request untracked files, whichgit diffleaves out.