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

Đang mở Phù hợp với người mới
#32 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
85/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
nextjs, typescript

Hướng nghiên cứu

Đọc apps/api/src/common/guards/next-auth-session.guard.ts và theo dõi cách guard trích xuất token từ cookie và header. Kiểm tra các unit test của guard và bổ sung kiểm thử cho thấy các tham số truy vấn token và sessionToken bị từ chối, trong khi các phương thức cookie và header được tài liệu hóa vẫn hoạt động. Công việc hoàn tất khi các tham số truy vấn không thể xác thực một request và các bài kiểm thử của guard đều đạt.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
TypeScript
Star
2
Fork
1
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
27

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của sumamakhan761/tryinstance

Tất cả issue của sumamakhan761/tryinstance

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.