fix(web): bypass auth proxy for local dev#1213
Conversation
There was a problem hiding this comment.
Summary
Reviewed — found 1 issue(s). This PR moves the local development auth-proxy bypass from contributor instructions into apps/web/middleware.ts; the review focused on whether that bypass is safe and correctly scoped. The current implementation can be triggered from forwarded host data before any session or API auth checks run.
Findings
apps/web/middleware.ts
- The local-dev bypass trusts the public request hostname and can skip authentication for production requests with a spoofed forwarded host.
Verdict
| console.debug("[PROXY] Path:", url.pathname) | ||
| console.debug("[PROXY] Method:", request.method) | ||
|
|
||
| if (LOCAL_DEV_HOSTS.has(url.hostname)) { |
There was a problem hiding this comment.
getPublicRequestUrl(request) can derive url.hostname from forwarded host headers, so a production request with X-Forwarded-Host: localhost or 127.0.0.1 can enter this branch and skip the session checks, including the /api/* 401 guard. Please gate this bypass to a non-production/local-dev environment and/or check the actual internal request host instead of the forwarded public URL.
TestingThe testing subagent validated the middleware behavior locally against Commands run: cd /code/supermemoryai/supermemory/apps/web
export PATH="$HOME/.bun/bin:$PATH" && PORT=3000 bun run dev:app --hostname 0.0.0.0
curl -sS -o /tmp/body -D /tmp/headers -w 'status=%{http_code} redirect=%{redirect_url}\n' 'http://localhost:3000/'
curl -sS -o /tmp/body -D /tmp/headers -w 'status=%{http_code} redirect=%{redirect_url}\n' 'http://127.0.0.1:3000/'
curl -sS -o /tmp/body -D /tmp/headers -w 'status=%{http_code} redirect=%{redirect_url} type=%{content_type}\n' 'http://localhost:3000/api/nonexistent'
curl -sS -o /tmp/body -D /tmp/headers -w 'status=%{http_code} redirect=%{redirect_url} type=%{content_type}\n' 'http://127.0.0.1:3000/api/nonexistent'
curl -sS -H 'Host: app.supermemory.ai' -H 'X-Forwarded-Host: app.supermemory.ai' -H 'X-Forwarded-Proto: https' -o /tmp/body -D /tmp/headers -w 'status=%{http_code} redirect=%{redirect_url}\n' 'http://127.0.0.1:3000/'
cd /code/supermemoryai/supermemory/apps/web
export PATH="$HOME/.bun/bin:$PATH" && PORT=3000 bun run dev:app --hostname ::1
curl -g -sS --max-time 15 -o /var/tmp/pr1213-testing/pr-ipv6-actual-root.body -D /var/tmp/pr1213-testing/pr-ipv6-actual-root.headers -w 'status=%{http_code} redirect=%{redirect_url}\n' 'http://[::1]:3000/'
export PATH="$HOME/.bun/bin:$PATH" && bunx biome ci apps/web/middleware.ts CONTRIBUTING.md
cd apps/web && bunx tsc --noEmitResult: Evidence artifacts: Verdict
Attached Images and Videos 🎥 View recording: pr1213-localhost-127-route-level-404-bypass.webm |
getPublicRequestUrl trusts x-forwarded-host, so the hostname check alone could be spoofed in production to skip the /api 401 gate. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Pushed two commits (maintainer edits): a merge with main, and a guard change — the localhost bypass now also requires Reason: |




Description
This removes a manual setup step for OSS contributors by making the web middleware
automatically allow plain localhost development.
Previously, CONTRIBUTING.md instructed contributors to manually edit the web proxy/middleware
before running bun run dev:local. Without that edit, local requests could be redirected
through the auth proxy instead of reaching the local app directly.
Changes
Add a local-dev host bypass in apps/web/middleware.ts
Run the bypass before reading Better Auth session cookies
Remove the obsolete manual proxy-edit step from CONTRIBUTING.md
Why
bun run dev:local should work without contributors modifying tracked source files. This keeps
local setup simpler and avoids accidental dirty worktrees.
Testing
Session Details
(aside)to your comment to have me ignore it.