Skip to content

fix: harden WebSocket auth — dedicated token, header-only, fail closed - #586

Open
MubyLateef wants to merge 1 commit into
Heliobond:mainfrom
MubyLateef:fix/websocket-auth-hardening
Open

fix: harden WebSocket auth — dedicated token, header-only, fail closed#586
MubyLateef wants to merge 1 commit into
Heliobond:mainfrom
MubyLateef:fix/websocket-auth-hardening

Conversation

@MubyLateef

Copy link
Copy Markdown

authenticate() in src/lib/websocket.ts fell back to ADMIN_API_KEY when WS_AUTH_TOKEN was unset and accepted the token via a ?token= query parameter (checked before the Authorization header). Query strings leak into access logs, proxy/CDN logs, browser history, and Referer headers, so this exposed the admin REST key over a channel the REST routes deliberately avoid.
closes #498

  • Require a dedicated WS_AUTH_TOKEN; no ADMIN_API_KEY fallback.
  • Accept the token only as Authorization: Bearer <token>; drop ?token=.
  • Fail closed in production when WS_AUTH_TOKEN is unset (dev/test still skip auth for convenience).

Timing-safe comparison was already in place. Adds websocket-auth.test.ts and updates .env.example / docs/SETUP.md.

Description

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Testing checklist

  • Tests pass locally
  • Added new tests (if applicable)
  • Code follows project conventions

Related issues

Screenshots (if applicable)

authenticate() in src/lib/websocket.ts fell back to ADMIN_API_KEY when
WS_AUTH_TOKEN was unset and accepted the token via a ?token= query
parameter (checked before the Authorization header). Query strings leak
into access logs, proxy/CDN logs, browser history, and Referer headers,
so this exposed the admin REST key over a channel the REST routes
deliberately avoid.

- Require a dedicated WS_AUTH_TOKEN; no ADMIN_API_KEY fallback.
- Accept the token only as `Authorization: Bearer <token>`; drop ?token=.
- Fail closed in production when WS_AUTH_TOKEN is unset (dev/test still
  skip auth for convenience).

Timing-safe comparison was already in place. Adds websocket-auth.test.ts
and updates .env.example / docs/SETUP.md.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@MubyLateef Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

WebSocket auth accepts ADMIN_API_KEY via a ?token= URL query parameter and compares it with plain ===

1 participant