Skip to content

fix(api): add admin auth guard to upload file-serve route#76

Open
teddylee777 wants to merge 1 commit into
mainfrom
fix/issue-65-admin-upload-auth
Open

fix(api): add admin auth guard to upload file-serve route#76
teddylee777 wants to merge 1 commit into
mainfrom
fix/issue-65-admin-upload-auth

Conversation

@teddylee777
Copy link
Copy Markdown
Member

Summary

  • GET /api/admin/upload/[filename] served admin-uploaded assets without any authentication check, allowing any client that knew a filename to download admin-private branding/logos.
  • Add auth() + isAdmin(session.user.role as UserRole) guard at the start of the GET handler: no session → 401 Unauthorized, non-admin → 403 Forbidden, admin → existing file-serve path (unchanged).
  • Preserve the existing path-traversal defense (.., /, \) and MIME handling; no changes to the sibling POST handler or shared auth helpers.
  • Add a Playwright e2e regression test (frontend/e2e/admin-upload-auth.spec.ts) asserting the 401 unauthenticated case — matches the existing e2e infrastructure.

Closes #65

The GET handler at frontend/src/app/api/admin/upload/[filename]/route.ts
served admin-uploaded files to any caller without an authentication
check, while the sibling POST handler already required auth() + isAdmin().
This asymmetry let unauthenticated clients read admin-private branding
and logo assets once a filename leaked (browser history, server logs,
CDN cache).

Add the session + role check at the start of the GET handler:
- no session -> 401 Unauthorized
- authenticated non-admin -> 403 Forbidden
- admin/super_admin -> existing file-serve path (unchanged)

Keep the existing path-traversal defense and MIME handling intact.
Add a Playwright e2e regression test covering the unauthenticated 401
case (matches the existing e2e infra under frontend/e2e/).
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.

🔴[P0] fix(api): admin upload file-serve route has no authentication check

1 participant