Skip to content

fix: restrict API routes to localhost-only access#25

Merged
rogerdigital merged 1 commit into
mainfrom
fix/api-auth-middleware
May 5, 2026
Merged

fix: restrict API routes to localhost-only access#25
rogerdigital merged 1 commit into
mainfrom
fix/api-auth-middleware

Conversation

@rogerdigital
Copy link
Copy Markdown
Owner

Summary

  • Add src/middleware.ts to enforce localhost-only access on all /api/* routes
  • Check Host header to block non-localhost network access
  • Check Origin header when present to block CSRF from external origins
  • OAuth callback routes unaffected (browser redirects to localhost URL carry correct Host)

Closes #24

Test plan

  • pnpm lint passes
  • Dev server: all existing API calls from the UI still work (localhost origin)
  • curl -H "Host: evil.com" http://localhost:3000/api/settings returns 403
  • curl http://127.0.0.1:3000/api/settings returns 200
  • curl -H "Origin: https://evil.com" http://localhost:3000/api/settings returns 403

All /api/* routes were completely unauthenticated. Add middleware
that checks Host and Origin headers to ensure requests originate
from localhost only. Blocks CSRF attacks and remote access to
credentials and publishing endpoints.

Closes #24
@rogerdigital rogerdigital merged commit d346e78 into main May 5, 2026
3 checks passed
@rogerdigital rogerdigital deleted the fix/api-auth-middleware branch May 5, 2026 15:46
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.

security: all API routes are unauthenticated, credentials can be overwritten

1 participant