-
Notifications
You must be signed in to change notification settings - Fork 13.9k
fix(api): return 403 for authorization failures, reserve 401 for missing session #41660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@rocket.chat/meteor": patch | ||
| "@rocket.chat/http-router": patch | ||
| --- | ||
|
|
||
| fix(api): return 403 for authorization failures, reserve 401 for missing session |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -895,14 +895,13 @@ export class APIClass<TBasePath extends string = '', TOperations extends Record< | |
| } | ||
| } catch (e: any) { | ||
| result = ((e: any) => { | ||
| switch (e.error) { | ||
| const errorKey = typeof e === 'string' ? e : e.error || e.message; | ||
| switch (errorKey) { | ||
| case 'error-too-many-requests': | ||
| return api.tooManyRequests(typeof e === 'string' ? e : e.message); | ||
| case 'unauthorized': | ||
| case 'error-unauthorized': | ||
| if (applyBreakingChanges) { | ||
| return api.unauthorized(typeof e === 'string' ? e : e.message); | ||
| } | ||
| case 'error-not-authorized': | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This new mapping also catches plain Useful? React with 👍 / 👎. |
||
| return api.forbidden(typeof e === 'string' ? e : e.message); | ||
| case 'forbidden': | ||
| case 'error-forbidden': | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This remap causes any
Error('error-not-authorized')thrown from typed routes to resolve to a 403 response, but several routes registered withtyped: true(e.g.rooms.adminRooms) don't declare a403schema in their response map — only400/401. Since the typed Router validates responses against declared schemas underTEST_MODE, those routes will throw a missing-response-validator error instead of returning the intended 403. Add403: validateForbiddenErrorResponseto all typed routes that can throwerror-not-authorized, or scope this remap to endpoints whose specs were already updated.Prompt for AI agents