fix(auth): stop accepting session tokens via URL query parameters in NextAuthSessionGuard

Open Beginner friendly
#32 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
nextjs, typescript

Research direction

Read apps/api/src/common/guards/next-auth-session.guard.ts and trace how it extracts tokens from cookies and headers. Check the guard's unit tests and add coverage showing that token and sessionToken query parameters are rejected while the documented cookie and header methods still work. Done means query parameters cannot authenticate a request and the guard tests pass.

Written by the indexing model from the issue text.

Description

backend bug
Problem Description

In apps/api/src/common/guards/next-auth-session.guard.ts (lines 118–121), NextAuthSessionGuard falls back to reading session tokens from URL query parameters:

const queryToken = request.query?.token || request.query?.sessionToken;
if (typeof queryToken === 'string' && queryToken) {
  return queryToken;
}

Passing long-lived session tokens in URLs risks exposing them in server access logs, reverse proxy logs, browser history, and Referer headers.


Expected Behavior
  • API authentication must only accept session tokens via Cookie, Authorization: Bearer <token>, or x-session-token headers - not URL query parameters.

Where to Look
  • apps/api/src/common/guards/next-auth-session.guard.ts

Solution / Implementation Guide
  1. Remove the request.query?.token || request.query?.sessionToken fallback from NextAuthSessionGuard.
    • Note: apps/web SSE (apps/web/lib/hooks/useSalesChatRealtime.ts) already connects using cookies (withCredentials: true), so no frontend SSE changes are needed.
  2. Add/update guard unit tests to confirm query-param tokens are rejected.
Dominant language
TypeScript
Stars
2
Forks
1
Avg merge
6m
Merged PRs (30d)
27

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sumamakhan761/tryinstance

All issues in sumamakhan761/tryinstance

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.