Skip to content

web: open SSE streams same-origin so the session cookie reaches them (c-13e86c) - #41

Merged
cybersicilian merged 7 commits into
mainfrom
ej/20261124-142817-7e3c57
Nov 24, 2026
Merged

cybersicilian merged 7 commits into
mainfrom
ej/20261124-142817-7e3c57

Conversation

@cybersicilian

@cybersicilian cybersicilian commented Nov 24, 2026 •

Copy link
Copy Markdown

Refs #31

Why

Task activity stream answers 401 after a UI login on the E5 stack

Seen during the c-01377e live check (branch ej/20261124-140004-61d777, which merges c-f4115c + c-869050 on main): after logging in through the console form as the legacy ARTEX admin, GET /api/exploration/activity/stream?task=N&since=… answers 401 repeatedly and the Sessions tab shows "Reconnecting". Other API calls with the same session succeed.

What changed

  • web: open SSE streams same-origin so the session cookie reaches them (c-13e86c) (ad7d883)

    Since the session moved to an HttpOnly cookie, getToken() returns null, but
    sseUrl still sent non-production builds (next dev) straight to :8787.
    That cross-origin EventSource carries no cookie and no token, so every
    connect answered 401 and the Sessions tab showed Reconnecting. Other calls
    went through the same-origin /api rewrite and worked. Predates E5.

    • web/src/lib/sse.ts: sseUrl is always a same-origin /api/ path (throws
      otherwise); NEXT_PUBLIC_SSE_BASE is removed (a cross-origin stream cannot
      present the cookie, and CORS '*' forbids credentials).
    • next.config.mjs: compress:false in dev, measured: with a browser's
      Accept-Encoding the rewrite gzips and buffers the stream; without
      compression frames arrive as sent.
    • server: PG test signs in through the login handler as the bootstrap
      ARTEX admin and as a console user, then opens the activity stream with
      only the cookie and reads a frame; no session -> 401.
  • server: SSE streams send a first comment when they open (c-13e86c) (b89fab2)

    streamActivity and streamLogs flushed only headers until the first event or
    the 20 s ping. The Next.js dev rewrite passes headers on only with a first
    body byte, so the EventSource stayed unopened and the Sessions tab showed
    Reconnecting for 20 s on an idle task (measured: TTFB 20.0 s through next
    dev, immediate direct). openSSE sets the SSE headers and writes ': open'.
    The PG test now asserts the comment is the first line.

  • HANDOFF: c-13e86c state, gotchas, decision (cd64413)

  • HANDOFF: condense the E5 entry to its on-main state (E5: engagement authorization artifact in the target gate, hash-chained audit schema #31) so Current state fits (d228f19)

  • HANDOFF: move the 2026-11-23 audit's operator-facing list to docs/handoff/ (dc77cdc)

  • HANDOFF: deltas stamp (c-13e86c) (4f13c18)

Files changed

Tests touched: server/activity_stream_auth_pg_test.go, web/src/lib/sse.test.mjs

15 files, +303 −141
File + −
server/activity_stream_auth_pg_test.go 142 0
HANDOFF.md 26 90
docs/handoff/2026-11-23-security-audit-operator-changes.md 61 0
web/src/lib/api.ts 0 33
server/sse_open.go 22 0
web/src/lib/sse.ts 20 0
web/src/lib/sse.test.mjs 14 0
server/server.go 2 10
README.md 5 4
web/next.config.mjs 4 0
web/package.json 2 1
web/src/app/(main)/function/tasks/detail/_tabs/sessions-tab.tsx 2 1
web/src/app/(main)/system/logs/page.tsx 1 1
web/src/hooks/use-side-questions.ts 1 1
scripts/verify.sh 1 0

Opened by Composite · ej/20261124-142817-7e3c57 → main · card c-13e86c · run 20261124-142817-7e3c57

🤖 Generated with Claude Code


Summary by cubic

Fixes the activity stream answering 401 after a console login: the HttpOnly session cookie never reached the cross-origin EventSource that sseUrl built in dev builds, so every connect was unauthenticated.

  • SSE streams are now always same-origin /api/ paths; NEXT_PUBLIC_SSE_BASE is removed.
  • openSSE writes a : open comment so proxies that wait for a first body byte pass the headers through immediately.
  • Dev compression is off so the Next.js rewrite doesn't buffer the stream.
  • Adds a Postgres test that logs in as the legacy ARTEX admin and a console user, then opens the stream with only the cookie.

Written for commit 4f13c18. Summary will update on new commits.

View guided diff

cybersicilian and others added 7 commits November 24, 2026 14:41
…(c-13e86c)

Since the session moved to an HttpOnly cookie, getToken() returns null, but
sseUrl still sent non-production builds (next dev) straight to <host>:8787.
That cross-origin EventSource carries no cookie and no token, so every
connect answered 401 and the Sessions tab showed Reconnecting. Other calls
went through the same-origin /api rewrite and worked. Predates E5.

- web/src/lib/sse.ts: sseUrl is always a same-origin /api/ path (throws
  otherwise); NEXT_PUBLIC_SSE_BASE is removed (a cross-origin stream cannot
  present the cookie, and CORS '*' forbids credentials).
- next.config.mjs: compress:false in dev, measured: with a browser's
  Accept-Encoding the rewrite gzips and buffers the stream; without
  compression frames arrive as sent.
- server: PG test signs in through the login handler as the bootstrap
  ARTEX admin and as a console user, then opens the activity stream with
  only the cookie and reads a frame; no session -> 401.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
streamActivity and streamLogs flushed only headers until the first event or
the 20 s ping. The Next.js dev rewrite passes headers on only with a first
body byte, so the EventSource stayed unopened and the Sessions tab showed
Reconnecting for 20 s on an idle task (measured: TTFB 20.0 s through next
dev, immediate direct). openSSE sets the SSE headers and writes ': open'.
The PG test now asserts the comment is the first line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	HANDOFF.md
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cybersicilian
cybersicilian merged commit b0b46d1 into main Nov 24, 2026
6 of 7 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T22:21:30.160597Z
We couldn’t complete this review. Comment @codex review to try again.
4f13c18 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

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.

1 participant