Skip to content

fix(api)!: return 403 for authorization failures, reserve 401 for missing session - #41590

Draft
ggazzo wants to merge 2 commits into
developfrom
chore/api-401-403-semantics
Draft

fix(api)!: return 403 for authorization failures, reserve 401 for missing session#41590
ggazzo wants to merge 2 commits into
developfrom
chore/api-401-403-semantics

Conversation

@ggazzo

@ggazzo ggazzo commented Jul 27, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

In the REST API the status codes for authentication and authorization failures are inverted relative to their meaning: error-invalid-user ("you are not logged in") falls through to API.v1.failure()400, while error-unauthorized ("you are logged in but not allowed") was mapped to 401 under the 9.0.0 flag. So the only code that reached 401 never meant unauthenticated, and the condition that genuinely is 401 answered 400.

I classified all 31 error-unauthorized / error-not-authorized throws in apps/meteor/server, apps/meteor/app and apps/meteor/ee by the guard preceding them — every single one is an authorization check (hasPermissionAsync, canAccessRoom, canDeleteFile, agent department scope). None means unauthenticated. Full per-site census in the issue.

This PR makes 401 mean exactly one thing — no valid session — so a client can act on it again. The change is applied directly, not deferred behind applyBreakingChanges, hence the major changeset.

  • server/api/ApiClass.tserror-unauthorized / unauthorized and error-not-authorized / not-authorized all map to forbidden() (403). error-unauthorized was already 403 and simply no longer flips to 401; error-not-authorized was not handled by the switch at all and fell through to 400.
  • server/api/v1/rooms.tsrooms.membersOrderedByRole (view-broadcast-member-list), rooms.hide and rooms.bannedUsers returned 401 for access/permission failures and now return 403. Response schemas declare 403.
  • server/api/v1/middlewares/permissions.ts — a missing session now answers 401 instead of 403-with-[error-unauthorized]-in-the-message. Also removed the dead if (applyBreakingChanges) fork on the !hasPermission path, whose two branches were byte-identical (the legacy branch named its variable failure, so API.v1.failure was probably intended and the if/else was left half-finished).

Worth calling out: before this, the same permission denial answered 403 from permissionsMiddleware and 401 from a handler once the flag turned on. That inconsistency is gone.

Why this matters beyond tidiness

The ~134 unauthenticated checks live almost entirely in apps/meteor/server/meteor-methods/. Over DDP the error code reaches the client verbatim and no status code is involved. As each method migrates to a typed route, that same check starts answering 400 — indistinguishable from a validation error.

It already cost us once: in #40675 (sendMessage + getReadReceipts migration) a client handler that treated any REST 401 as an expired session logged out live sessions and failed the omnichannel e2e shards. It was reverted, and it cannot be reimplemented correctly until 401 has a single meaning. This PR is the prerequisite.

Issue(s)

Refs #41589
Refs ARCH-2297

Steps to test or reproduce

  1. rooms.hide as a user without access to the room → was 401, now 403.
  2. rooms.bannedUsers on a private room the caller is not in → was 401, now 403.
  3. rooms.membersOrderedByRole on a broadcast room without view-broadcast-member-list → was 401, now 403. (Untested branch: findRoomByIdOrName answers notFound first for non-members, so it is only reachable for a member of a broadcast room.)
  4. Any endpoint whose handler throws error-not-authorized (e.g. rooms.changeArchivationState without archive-room) → was 400, now 403.
  5. A route with permissionsRequired and no authRequired, called with no session → was 403, now 401.

Tests: apps/meteor/tests/end-to-end/api/rooms.ts. Updated the rooms.hide no-access assertion to 403, and added the missing no-access test for rooms.bannedUsers, which had none.

Further comments

Status: draft while CI tells us the real blast radius. Two things I expect the suite to surface, and I'd rather have the numbers than guess:

  1. Tests asserting 400 on endpoints that reach an error-not-authorized throw now get 403.
  2. Routes that can now return 403 without declaring 403: in their response schema — response validation runs against the declared schema in TEST_MODE, so those may fail rather than pass through.

One subtlety found while auditing: several error-not-authorized sites throw a plain Error, not Meteor.Error / MeteorErrorserver/api/lib/rooms.ts:27,68,113, server/api/v1/omnichannel/lib/inquiries.ts:28, server/lib/omnichannel/closeLivechatRoom.ts:39, ee/server/lib/omnichannel/business-hour/lib/business-hour.ts:14, ee/server/api/ldap.ts:36. The switch keys off e.error, which is undefined on a plain Error, so those still fall through to 400 and are not affected by this PR. They carry the code in message instead and want a separate cleanup.

Deliberately not in this PR — step 2 of the issue: introducing a dedicated error-unauthenticated code mapped to 401 and moving the ~134 missing-session guards onto it. A blanket remap of error-invalid-user is not viable, since the same code also means "that user does not exist" (244 occurrences in total, only 134 of them guarded by a missing-session check). Separate, much larger change, and it depends on this one landing first.

I also left rooms.ts:1147 alone — in the same handler as the broadcast check, it answers notFound for an access failure, a third treatment of the same class of condition in one file. Changing it to 403 would leak room existence, so it deserves its own discussion rather than a drive-by fix.

Every `error-unauthorized` / `error-not-authorized` throw in the codebase
follows an authorization check, never a missing session, yet the error
switch in ApiClass mapped `error-unauthorized` to 401 once the 9.0.0
breaking-change flag turns on — while the permission middleware answered
403 for the same condition. Clients could not infer session state from
the status code, which is what logged out live sessions in the
sendMessage/getReadReceipts migration.

- `error-unauthorized` now always maps to 403, dropping the 401 it would
  have been promoted to in 9.0.0
- `error-not-authorized`, previously unmapped and falling through to 400,
  maps to 403 from 9.0.0
- rooms.membersOrderedByRole, rooms.hide and rooms.bannedUsers returned
  401 for access failures; they return 403 from 9.0.0 and declare it in
  their response schemas
- drop the dead `if (applyBreakingChanges)` fork in the permissions
  middleware, both branches were identical

The unauthenticated side still throws `error-invalid-user` and answers
400; splitting it out needs a dedicated error code and is tracked
separately.

Refs #41589, ARCH-2297
@ggazzo
ggazzo requested a review from a team as a code owner July 27, 2026 17:46
@dionisio-bot

dionisio-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is targeting the wrong base branch. It should target 9.0.0, but it targets 8.8.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f5280a2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@rocket.chat/meteor Major
@rocket.chat/core-typings Major
@rocket.chat/rest-typings Major
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Major
@rocket.chat/http-router Patch
@rocket.chat/model-typings Patch
@rocket.chat/models Patch
@rocket.chat/ui-contexts Major
@rocket.chat/web-ui-registration Major
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

REST authorization error mapping and permission handling are updated for 401/403 semantics. Three room endpoints declare 403 responses while retaining breaking-change compatibility, and end-to-end tests and release notes document the behavior.

Changes

REST authorization semantics

Layer / File(s) Summary
Authorization error mapping
apps/meteor/server/api/ApiClass.ts, apps/meteor/server/api/v1/middlewares/permissions.ts
Authorization errors now produce forbidden responses in the applicable paths, and the redundant permission middleware branch is removed.
Room endpoint response contracts
apps/meteor/server/api/v1/rooms.ts
rooms.membersOrderedByRole, rooms.hide, and rooms.bannedUsers declare 403 responses and switch between forbidden and unauthorized responses according to the breaking-change setting.
Behavior validation and release notes
apps/meteor/tests/end-to-end/api/rooms.ts, .changeset/rest-401-403-semantics.md
Room authorization tests and the changeset document current and planned 401/403 behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • RocketChat/Rocket.Chat#41589 — Directly addresses the REST authorization-status fixes implemented in ApiClass.ts, permissions.ts, and rooms.ts.

Suggested labels: type: bug

Suggested reviewers: dougfabris, kevlehman, sampaiodiego

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main change: authorization failures now map to 403, with 401 kept for unauthenticated access semantics.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (2)
  • ARCH-2297: Request failed with status code 401
  • API-401: Request failed with status code 401

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/meteor/server/api/ApiClass.ts (1)

901-902: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the new inline implementation comments.

The same guideline violation appears at all affected sites; retain the migration rationale in the changeset or PR description instead.

  • apps/meteor/server/api/ApiClass.ts#L901-L902: remove the authorization-mapping comment.
  • apps/meteor/server/api/v1/rooms.ts#L1156-L1156: remove the 401/403 migration comment.
  • apps/meteor/server/api/v1/rooms.ts#L1304-L1304: remove the 401/403 migration comment.
  • apps/meteor/server/api/v1/rooms.ts#L1709-L1709: remove the 401/403 migration comment.
  • apps/meteor/tests/end-to-end/api/rooms.ts#L4666-L4666: remove the test comment.
  • apps/meteor/tests/end-to-end/api/rooms.ts#L5116-L5116: remove the test comment.

As per coding guidelines, avoid code comments in the implementation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/meteor/server/api/ApiClass.ts` around lines 901 - 902, Remove the new
inline migration and authorization-mapping comments without changing surrounding
behavior: delete the comments at apps/meteor/server/api/ApiClass.ts lines
901-902; apps/meteor/server/api/v1/rooms.ts lines 1156, 1304, and 1709; and
apps/meteor/tests/end-to-end/api/rooms.ts lines 4666 and 5116. Retain the
underlying implementation and tests unchanged.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/meteor/tests/end-to-end/api/rooms.ts`:
- Line 5117: Update the status assertion in the affected end-to-end room API
test to use the same 9.0.0 breaking-change version gate as the rooms API
implementation: expect 403 when the gate is enabled and 401 otherwise, so both
behaviors are validated.

---

Nitpick comments:
In `@apps/meteor/server/api/ApiClass.ts`:
- Around line 901-902: Remove the new inline migration and authorization-mapping
comments without changing surrounding behavior: delete the comments at
apps/meteor/server/api/ApiClass.ts lines 901-902;
apps/meteor/server/api/v1/rooms.ts lines 1156, 1304, and 1709; and
apps/meteor/tests/end-to-end/api/rooms.ts lines 4666 and 5116. Retain the
underlying implementation and tests unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 038e183a-9f9c-422d-b306-e00671207c95

📥 Commits

Reviewing files that changed from the base of the PR and between 4947601 and fb912af.

📒 Files selected for processing (5)
  • .changeset/rest-401-403-semantics.md
  • apps/meteor/server/api/ApiClass.ts
  • apps/meteor/server/api/v1/middlewares/permissions.ts
  • apps/meteor/server/api/v1/rooms.ts
  • apps/meteor/tests/end-to-end/api/rooms.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: CodeQL-Build
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build
  • GitHub Check: Hacktron Security Check
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/server/api/v1/middlewares/permissions.ts
  • apps/meteor/tests/end-to-end/api/rooms.ts
  • apps/meteor/server/api/ApiClass.ts
  • apps/meteor/server/api/v1/rooms.ts
🧠 Learnings (4)
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.

Applied to files:

  • .changeset/rest-401-403-semantics.md
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/server/api/v1/middlewares/permissions.ts
  • apps/meteor/tests/end-to-end/api/rooms.ts
  • apps/meteor/server/api/ApiClass.ts
  • apps/meteor/server/api/v1/rooms.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/server/api/v1/middlewares/permissions.ts
  • apps/meteor/tests/end-to-end/api/rooms.ts
  • apps/meteor/server/api/ApiClass.ts
  • apps/meteor/server/api/v1/rooms.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/server/api/v1/middlewares/permissions.ts
  • apps/meteor/tests/end-to-end/api/rooms.ts
  • apps/meteor/server/api/ApiClass.ts
  • apps/meteor/server/api/v1/rooms.ts
🔇 Additional comments (5)
apps/meteor/server/api/ApiClass.ts (1)

903-911: LGTM!

apps/meteor/server/api/v1/middlewares/permissions.ts (1)

46-47: LGTM!

apps/meteor/server/api/v1/rooms.ts (1)

80-80: LGTM!

Also applies to: 1137-1137, 1157-1157, 1297-1299, 1305-1305, 1702-1704, 1710-1710

apps/meteor/tests/end-to-end/api/rooms.ts (1)

5105-5115: LGTM!

Also applies to: 5118-5125

.changeset/rest-401-403-semantics.md (1)

1-15: LGTM!

.query({ roomId: privateRoom._id })
.expect('Content-Type', 'application/json')
// TODO: MAJOR 403 — currently 401 until the 9.0.0 breaking changes are applied
.expect(401)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Make the expected status version-aware.

apps/meteor/server/api/v1/rooms.ts returns 403 when the 9.0.0 breaking-change gate is enabled and 401 otherwise. Hardcoding 401 here will fail on 9.0.0+ and does not validate the new behavior. Assert the status using the same version gate.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/meteor/tests/end-to-end/api/rooms.ts` at line 5117, Update the status
assertion in the affected end-to-end room API test to use the same 9.0.0
breaking-change version gate as the rooms API implementation: expect 403 when
the gate is enabled and 401 otherwise, so both behaviors are validated.

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.67%. Comparing base (5ba7bd5) to head (f5280a2).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41590      +/-   ##
===========================================
- Coverage    68.69%   68.67%   -0.02%     
===========================================
  Files         4139     4140       +1     
  Lines       159268   159306      +38     
  Branches     27964    27983      +19     
===========================================
- Hits        109403   109402       -1     
- Misses       44705    44739      +34     
- Partials      5160     5165       +5     
Flag Coverage Δ
unit 70.62% <ø> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 5 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/meteor/server/api/ApiClass.ts">

<violation number="1" location="apps/meteor/server/api/ApiClass.ts:905">
P2: `rooms.changeArchivationState` can now emit 403 for its archive/unarchive permission check, but its declared responses omit 403. Add the forbidden response schema for this and other routes that propagate `error-not-authorized`, so test validation and generated API contracts match runtime behavior.</violation>

<violation number="2" location="apps/meteor/server/api/ApiClass.ts:907">
P1: Authorization failures thrown as native `Error` still return 400 in 9.0.0 because `switch (e.error)` cannot match their message. Normalize the error code from `e.error` or `e.message` before this switch so these existing REST authorization paths reach 403.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

case 'error-unauthorized':
return api.forbidden(typeof e === 'string' ? e : e.message);
case 'not-authorized':
case 'error-not-authorized':

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Authorization failures thrown as native Error still return 400 in 9.0.0 because switch (e.error) cannot match their message. Normalize the error code from e.error or e.message before this switch so these existing REST authorization paths reach 403.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/meteor/server/api/ApiClass.ts, line 907:

<comment>Authorization failures thrown as native `Error` still return 400 in 9.0.0 because `switch (e.error)` cannot match their message. Normalize the error code from `e.error` or `e.message` before this switch so these existing REST authorization paths reach 403.</comment>

<file context>
@@ -898,12 +898,17 @@ export class APIClass<TBasePath extends string = '', TOperations extends Record<
 									case 'error-unauthorized':
+										return api.forbidden(typeof e === 'string' ? e : e.message);
+									case 'not-authorized':
+									case 'error-not-authorized':
 										if (applyBreakingChanges) {
-											return api.unauthorized(typeof e === 'string' ? e : e.message);
</file context>

Comment thread apps/meteor/server/api/ApiClass.ts Outdated
// so they map to 403; 401 is reserved for a missing or invalid session
case 'unauthorized':
case 'error-unauthorized':
return api.forbidden(typeof e === 'string' ? e : e.message);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: rooms.changeArchivationState can now emit 403 for its archive/unarchive permission check, but its declared responses omit 403. Add the forbidden response schema for this and other routes that propagate error-not-authorized, so test validation and generated API contracts match runtime behavior.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/meteor/server/api/ApiClass.ts, line 905:

<comment>`rooms.changeArchivationState` can now emit 403 for its archive/unarchive permission check, but its declared responses omit 403. Add the forbidden response schema for this and other routes that propagate `error-not-authorized`, so test validation and generated API contracts match runtime behavior.</comment>

<file context>
@@ -898,12 +898,17 @@ export class APIClass<TBasePath extends string = '', TOperations extends Record<
+									// so they map to 403; 401 is reserved for a missing or invalid session
 									case 'unauthorized':
 									case 'error-unauthorized':
+										return api.forbidden(typeof e === 'string' ? e : e.message);
+									case 'not-authorized':
+									case 'error-not-authorized':
</file context>

@ggazzo
ggazzo marked this pull request as draft July 27, 2026 17:58
…sion

Drops the `applyBreakingChanges` gating and applies the change directly
instead of deferring it to the 9.0.0 flag.

- `error-not-authorized` / `not-authorized` now map to 403 instead of
  falling through to `API.v1.failure()` (400)
- rooms.membersOrderedByRole, rooms.hide and rooms.bannedUsers return
  403 unconditionally
- the permissions middleware answers 401 for a missing session instead
  of 403 with `[error-unauthorized]` in the message

Changeset bumped to major.

BREAKING CHANGE: REST endpoints that denied a request on a permission or
room-access check answered 400 or 401 and now answer 403; routes with
`permissionsRequired` and no `authRequired` answer 401 instead of 403
when called without a session.
dionisio-bot[bot]
dionisio-bot Bot previously requested changes Jul 27, 2026

@dionisio-bot dionisio-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changeset mismatch

A changeset declares a major bump, but the PR title does not indicate a breaking change (use type!: ... or type(scope)!: ...).

Please align the PR title, milestone and changesets.

dionisio-bot[bot]
dionisio-bot Bot previously requested changes Jul 27, 2026

@dionisio-bot dionisio-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changeset mismatch

A changeset declares a major bump, but the PR title does not indicate a breaking change (use type!: ... or type(scope)!: ...).

Please align the PR title, milestone and changesets.

@dionisio-bot dionisio-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changeset mismatch

A changeset declares a major bump, but the PR title does not indicate a breaking change (use type!: ... or type(scope)!: ...).

Please align the PR title, milestone and changesets.

@dionisio-bot dionisio-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changeset mismatch

A changeset declares a major bump, but the PR title does not indicate a breaking change (use type!: ... or type(scope)!: ...).

Please align the PR title, milestone and changesets.

@dionisio-bot dionisio-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changeset mismatch

A changeset declares a major bump, but the PR title does not indicate a breaking change (use type!: ... or type(scope)!: ...).

Please align the PR title, milestone and changesets.

@ggazzo ggazzo changed the title fix(api): reserve HTTP 401 for unauthenticated requests fix(api)!: return 403 for authorization failures, reserve 401 for missing session Jul 27, 2026
@dionisio-bot
dionisio-bot Bot dismissed their stale review July 27, 2026 17:59

Changesets now match the title and milestone

@ggazzo ggazzo added this to the 9.0.0 milestone Jul 27, 2026
@dionisio-bot
dionisio-bot Bot dismissed their stale review July 27, 2026 18:06

Changesets now match the title and milestone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant