Skip to content

fix(web): authenticate and bound metered /api routes - #1589

Merged
graphite-app[bot] merged 1 commit into
mainfrom
security/web-api-hardening
Aug 23, 2026
Merged

fix(web): authenticate and bound metered /api routes#1589
graphite-app[bot] merged 1 commit into
mainfrom
security/web-api-hardening

Conversation

@MaheshtheDev

@MaheshtheDev MaheshtheDev commented Aug 23, 2026

Copy link
Copy Markdown
Member

Cherry-picks #1579 and #1580 from @Sravanjangam (security audit #1578), plus improvements on top.

Verified locally: pre-fix /api/og returned 200 for a forged cookie, post-fix it returns 401. Five duplicate URLs collapse to two before reaching Exa, and a newline-laden name arrives as a single prompt line.

Supersedes #1528 and #1530.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 23, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
supermemory-mcp 3b0fc9c Aug 23 2026, 09:49 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 23, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
supermemory-app 3b0fc9c Commit Preview URL

Branch Preview URL
Aug 23 2026, 09:52 PM

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add the label Main to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@MaheshtheDev MaheshtheDev changed the title fix(web): verify sessions server-side on metered /api routes fix(web): authenticate and bound metered /api routes Aug 23, 2026
@MaheshtheDev
MaheshtheDev force-pushed the security/web-api-hardening branch 2 times, most recently from 469cd88 to b8020c9 Compare August 23, 2026 21:15
@MaheshtheDev
MaheshtheDev marked this pull request as ready for review August 23, 2026 21:18
@claude

claude Bot commented Aug 23, 2026

Copy link
Copy Markdown

Claude finished @MaheshtheDev's task in 1m 30s —— View job


Review Complete

Overview: Adds server-side session verification and input bounds to metered API routes that were previously vulnerable to forged cookies.

Issues found: None — this looks good to ship.

Details:

The security hardening is well-implemented:

  • verify-session.ts — Correctly verifies sessions against the backend auth endpoint with fail-closed behavior (returns false on any error). The isLocalDevRequest bypass for localhost in development mode properly addresses the Codex concern about the bun run dev:local workflow — gated by NODE_ENV !== "development" so it can't affect production.

  • /api/og — Session check added at the entry point. The readBoundedText helper properly caps response size at 2MB with streaming reads, preventing memory exhaustion from malicious large responses. It first checks content-length for early rejection, then still enforces the limit during streaming (defending against servers that lie about content-length). The existing SSRF protection remains intact.

  • /api/onboarding/extract-content — Session check + URL validation (max 10 URLs, http(s) only, ≤2048 chars) properly bounds the Exa API calls. URL deduplication via Set<string> on normalized parsed.href prevents duplicate metered calls.

  • /api/onboarding/research — Session check + name/email length limits (200/320 chars) + 60s AbortSignal.timeout prevents unbounded resource consumption. The sanitizeContextField helper collapsing whitespace to single spaces prevents prompt injection via newlines.

  • Deleted account-status — Good cleanup of an unused, unauthenticated route.

Previously raised concerns (now resolved):

  • Codex P2 (localhost auth) — Fixed in commit e8f720d by adding the isLocalDevRequest bypass
  • Graphite (let vs const) — Fixed; the code now uses const parsed = parseHttpUrl(...)

Score: 10/10


| Branch: security/web-api-hardening

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview: Adds server-side session verification and input bounds to metered API routes that were previously vulnerable to forged cookies.

Issues found: None — this looks good to ship.

Details:

The security hardening is well-implemented:

  • verify-session.ts — Correctly verifies sessions against the backend auth endpoint with fail-closed behavior (returns false on any error). Uses cache: "no-store" and redirect: "error" appropriately.

  • /api/og — Session check added at the entry point. The readBoundedText helper properly caps response size at 2MB with streaming reads, preventing memory exhaustion from malicious large responses. The existing SSRF protection (isPrivateHost, IPv4/IPv6 checks) remains intact.

  • /api/onboarding/extract-content — Session check + URL validation (max 10 URLs, http(s) only, ≤2048 chars per URL) properly bounds the Exa API calls.

  • /api/onboarding/research — Session check + name/email length limits (200/320 chars) + 60s timeout on the LLM call prevents unbounded resource consumption.

  • Deleted account-status — Good cleanup of an unused, unauthenticated route.

Score: 10/10

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b8020c91b3

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/web/lib/verify-session.ts
Comment thread apps/web/app/api/onboarding/extract-content/route.ts Outdated
MaheshtheDev added a commit that referenced this pull request Aug 23, 2026
hasVerifiedSession bypasses verification only for development builds served from a localhost host: dev:local runs on localhost while auth lives on api.supermemory.ai, so the session cookie never reaches the route. Also extracts parseHttpUrl so the parsed URL is a const.

Both raised in review on #1589.
@graphite-app

graphite-app Bot commented Aug 23, 2026

Copy link
Copy Markdown

Merge activity

Cherry-picks #1579 and #1580 from @Sravanjangam (security audit #1578), plus improvements on top.

- `/api/og`, `/api/onboarding/extract-content` and `/api/onboarding/research` now verify the session against the auth backend; the middleware only checked that a cookie was present, so a forged cookie reached handlers that spend metered Exa/xAI quota.
- Bounds those routes: 2MB cap on fetched HTML, max 10 http(s) URLs per request, name/email length limits and a 60s timeout on the LLM call.
- De-duplicates URLs before calling Exa, and collapses whitespace in `name`/`email` so a newline can't forge extra prompt lines. Both adapted from @SEPURI-SAI-KRISHNA's #1528 and #1530.
- Deletes the unused, unauthenticated `account-status` route.

Verified locally: pre-fix `/api/og` returned 200 for a forged cookie, post-fix it returns 401. Five duplicate URLs collapse to two before reaching Exa, and a newline-laden `name` arrives as a single prompt line.

Supersedes #1528 and #1530.
@graphite-app
graphite-app Bot force-pushed the security/web-api-hardening branch from e8f720d to 3b0fc9c Compare August 23, 2026 21:48
@graphite-app
graphite-app Bot merged commit 3b0fc9c into main Aug 23, 2026
5 of 7 checks passed
graphite-app Bot pushed a commit that referenced this pull request Aug 25, 2026
…og (#1596)

Cherry-picks two cleanup PRs and finishes the job. Net 262 deletions.

- #1473 (@abhay-codes07): drops a `console.log` in the fullscreen note editor that printed the whole note body on every keystroke, which PostHog session replay can capture.
- #1563 (@ishaanxgupta): removes `/api/onboarding/research` and `/api/onboarding/extract-content`. Neither has a caller anywhere in the repo, and both spent metered Exa and xAI quota. This reverts the guards added for them in #1589, which only existed to make unreachable code safe.
- On top: `EXA_API_KEY`, `XAI_API_KEY` and the `@ai-sdk/xai` dependency are removed, since deleting those routes left them with no consumer.

Co-Authored-By: abhay-codes07 <182421137+abhay-codes07@users.noreply.github.com>
Co-Authored-By: ishaanxgupta <124028055+ishaanxgupta@users.noreply.github.com>
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