[PR #6459] [MERGED] fix(api): return 401 for invalid Bearer token instead of 404 #6281

Closed
opened 2026-11-02 04:07:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6459
Author: @mrchatam
Created: 9/11/2026
Status: ✅ Merged
Merged: 9/12/2026
Merged by: @MHSanaei

Base: main ← Head: fix/bearer-invalid-401


📝 Commits (1)

  • d19c42c fix(api): return 401 for invalid Bearer token instead of 404

📊 Changes

2 files changed (+19 additions, -8 deletions)

View changed files

📝 internal/web/controller/api.go (+5 -1)
📝 internal/web/controller/api_auth_test.go (+14 -7)

📄 Description

Summary

  • When Authorization: Bearer is present but the token does not match (or is disabled), checkAPIAuth now returns 401 Unauthorized instead of masking as 404.
  • Requests with no Authorization header still get 404 (scanner masking preserved).
  • Wrong webBasePath continues to 404 via NoRoute, so script authors can distinguish auth failure from a mistyped base path.

Fixes #6255

Test plan

  • go test ./internal/web/controller/ -run TestCheckAPIAuth_
  • Manual: valid Bearer → 200; invalid Bearer → 401; no Authorization → 404; wrong base path → 404

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6459 **Author:** [@mrchatam](https://github.com/mrchatam) **Created:** 9/11/2026 **Status:** ✅ Merged **Merged:** 9/12/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/bearer-invalid-401` --- ### 📝 Commits (1) - [`d19c42c`](https://github.com/MHSanaei/3x-ui/commit/d19c42cd742c0d6ae4bb88c454ffdb6e0f455403) fix(api): return 401 for invalid Bearer token instead of 404 ### 📊 Changes **2 files changed** (+19 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/controller/api.go` (+5 -1) 📝 `internal/web/controller/api_auth_test.go` (+14 -7) </details> ### 📄 Description ## Summary - When `Authorization: Bearer` is present but the token does not match (or is disabled), `checkAPIAuth` now returns **401 Unauthorized** instead of masking as **404**. - Requests with no `Authorization` header still get 404 (scanner masking preserved). - Wrong `webBasePath` continues to 404 via `NoRoute`, so script authors can distinguish auth failure from a mistyped base path. Fixes #6255 ## Test plan - [x] `go test ./internal/web/controller/ -run TestCheckAPIAuth_` - [ ] Manual: valid Bearer → 200; invalid Bearer → 401; no Authorization → 404; wrong base path → 404 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:39 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6281
No description provided.