diff options
| author | Jesse Vincent <jesse@primeradiant.com> | 2026-06-09 19:13:52 -0700 |
|---|---|---|
| committer | Drew Ritter <drew@primeradiant.com> | 2026-06-16 10:09:45 -0700 |
| commit | 7fbae0252fe90778ce0c06fde3bf5f87aa396fc2 (patch) | |
| tree | 05a8fc852bd949de403dd347575e6f64d4c3db5a /tests/brainstorm-server/server.test.js | |
| parent | 01de36703dcef42c9c5c5eafa840fb6cd8bcb29a (diff) | |
fix(brainstorm-server): fix auth-integration bugs from full-branch review
A second adversarial review of the merged branch found that combining the
session-key auth with the feature work created real bugs the (vacuous) tests
missed:
- [Critical] GET /files/ (empty name) resolved to CONTENT_DIR and crashed the
process with uncaught EISDIR — newly reachable because the query-stripping
refactor turns /files/?key=... into /files/. Reject non-regular-file names.
- [High] --open opened a KEYLESS url, which the auth gate 403s — the headline
feature landed on the error page. Open the keyed url.
- [High] Same-port restart regenerated the token (port persisted, token not), so
the open tab's old cookie 403'd and never reconnected — contradicting the
documented promise. Persist the token (BRAINSTORM_TOKEN_FILE / .last-token)
alongside the port.
- [Medium] Token sat in world-readable server-info/server.log (0644 in /tmp).
umask 077 in start-server.sh + mode 0600 on server-info/.last-token.
- [Medium] touchActivity() ran before the auth check, so unauthenticated requests
defeated the idle timeout. Count activity only after authorization.
- [Low] COOKIE_NAME embedded the pre-fallback port; derive it from the actual
bound port (also prevents a cross-server cookie-jar collision on fallback).
Tests added/strengthened (previously passed vacuously): /files/ no-crash; the
auto-open url carries the key and is reachable (200); restart reuses the same key
not just the port; unauthenticated requests don't reset the idle clock.
Full suite green (ws-protocol 32, helper 12, auth 13, server 29, lifecycle 8,
stop-server 4); restart smoke confirms same port+key and old URL -> 200.
Diffstat (limited to 'tests/brainstorm-server/server.test.js')
| -rw-r--r-- | tests/brainstorm-server/server.test.js | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/brainstorm-server/server.test.js b/tests/brainstorm-server/server.test.js index 9455ba1..25ea720 100644 --- a/tests/brainstorm-server/server.test.js +++ b/tests/brainstorm-server/server.test.js @@ -202,6 +202,14 @@ async function runTests() { assert.strictEqual(res.status, 404, '/files/ must 404 on dotfiles'); }); + await test('GET /files/ (empty name) returns 404 and does not crash the server', async () => { + const res = await fetch(`http://localhost:${TEST_PORT}/files/`); + assert.strictEqual(res.status, 404, '/files/ (the content dir) must 404, not EISDIR-crash'); + // The server must still be alive afterward. + const alive = await fetch(`http://localhost:${TEST_PORT}/`); + assert.strictEqual(alive.status, 200, 'server must survive a /files/ request'); + }); + await test('returns 404 for non-root paths', async () => { const res = await fetch(`http://localhost:${TEST_PORT}/other`); assert.strictEqual(res.status, 404); |
