GeezerVison is showing github.com — fix(matrix-sync): require auth + session ownership for /matrix/sync/register (Finding A) by Storypapst · Pull Request #305 · OpenResilienceInitiative/ORISO-UserService
Conversation
Fixes Finding A from the Test Quality Audit 2026-07-04, item 5 — MatrixSyncController is fully unauthenticated.
Verified exploit
adapters/web/controller/MatrixSyncController.java exposes POST/DELETE /matrix/sync/register/{sessionId} (and /service/… variants) with three overlapping open-access vectors and no ownership check:
SecurityConfig permitAll() for /matrix/sync/**, /service/matrix/sync/**.
WebSecurityCustomizer.web.ignoring() — bypasses the entire filter chain, including the oauth2ResourceServer JWT filter, so no token is ever decoded and the injected AuthenticatedUser stays unpopulated.
csrf.whitelist.configUris in application.properties lists /matrix/sync/**, and those configUris are themselves permitAll()'d in SecurityConfig (line ~98).
Result:
POST /register/{sessionId} — looks up any sessionId and returns {success, roomId, userCount}: an unauthenticated IDOR that enumerates sessionIds to harvest Matrix room ids + participant counts, plus an anonymous state change (registers the room for live-event sync).
DELETE /register/{sessionId} — an anonymous caller can unregister any session's room from sync → denial-of-function (kills live-event notifications for that session).
Caller analysis (verify-first)
The endpoint has ZERO callers anywhere today:
- ORISO-Frontend: no code calls
matrix/sync/register. Its endpoints.ts defines only matrixAccessToken → /service/matrix/me/token; the 'sync' strings in the FE are matrix-js-sdk client sync-state listeners (the browser syncs directly with Synapse), not this backend endpoint.
- ORISO-UserService internal:
matrixEventListenerService.registerRoom/unregisterRoom are called only from this controller — no @Scheduled job, no RestTemplate/WebClient, no Matrix appservice callback.
- Sibling services: no matches for
matrix/sync/register.
It is orphaned code left from the Matrix migration. The /service/ prefix is the ingress / inter-service path convention, not a privileged service-to-service channel — both path variants resolve to the same method with identical (missing) auth, so they are locked together.
Fix (safe default, mirrors sibling MatrixMessageController)
MatrixMessageController (same @RequestMapping({"/matrix","/service/matrix"}), same sessionId path var) already authorizes every session endpoint with sessionService.assertUserHasAccess(sessionId, authenticatedUser). This PR applies the same pattern:
SecurityConfig / properties — remove /matrix/sync/** + /service/matrix/sync/** from all three open-access vectors:
- the
permitAll() rule,
- the
web.ignoring() customizer,
- the
csrf.whitelist.configUris list.
They now fall under the existing "/matrix/**", "/service/matrix/**" matcher → hasAnyAuthority(USER_DEFAULT, CONSULTANT_DEFAULT), so the JWT resource-server filter and StatelessCsrfFilter apply, exactly like the sibling Matrix message endpoints.
Controller — call sessionService.assertUserHasAccess(sessionId, authenticatedUser) at the top of both methods, outside the try/catch, so ForbiddenException (403) / NotFoundException (404) reach the global exception handler instead of being swallowed into a 500. This closes the IDOR: an authenticated caller can only touch a session they own (asker) or are assigned to (consultant/agency).
Because no caller exists today, nothing legitimate breaks. This is the safe default the audit calls for: authentication + session-ownership authorization.
Minor, acceptable behavior change: DELETE for a genuinely missing session now returns 404 (was an idempotent 200). This stops anonymous session probing; the only intended caller (frontend on session close) always references a session it participates in.
Test evidence (TDD, red → green)
New MatrixSyncControllerTest (JUnit5 + Mockito, matching MatrixMessageControllerTest):
registerRoomForSync_ShouldThrowForbiddenBeforeRegistering_WhenSessionAccessIsDenied — red before fix ("Expected ForbiddenException … nothing was thrown"), green after; asserts verifyNoInteractions(matrixEventListenerService) (no leak).
unregisterRoomFromSync_ShouldThrowForbiddenBeforeUnregistering_WhenSessionAccessIsDenied — same.
registerRoomForSync_ShouldRegisterRoom_WhenAuthorizedParticipant — red before ("200 expected but 404"), green after; authorized participant still registers the room (200).
Tests run: 3, Failures: 0. Existing MatrixMessageControllerTest still green (4/4). Full module test-compile clean, spotless:check clean. JDK 21.
Residual risk / callers to update
- No caller must change today (none exists).
- If a future frontend feature needs to drive room sync, it must call these endpoints as an authenticated user (asker/consultant on that session) with the CSRF token — the same contract as every other
/matrix/** endpoint. Documented here so the contract is explicit.
- Alternatively, if this is genuinely dead code, a follow-up can delete the controller outright; this PR conservatively secures it rather than removing behavior.
🤖 Generated with Claude Code
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
sentry[bot] reacted with hooray emoji
…egister
Test Quality Audit 2026-07-04, item 5 (Finding A).
MatrixSyncController's POST/DELETE /register/{sessionId} (and the /service/
variants) were fully unauthenticated: the paths were permitAll(), excluded from
the entire Spring Security filter chain via web.ignoring(), AND listed in the
CSRF configUris whitelist (which is itself permitAll()'d). No JWT was ever
parsed, so the injected AuthenticatedUser was never populated and the controller
never checked session ownership.
Impact:
- POST /register/{sessionId} looked up ANY sessionId and returned
{success, roomId, userCount} -> unauthenticated IDOR harvesting Matrix room
ids + participant counts, plus an anonymous state change (registers the room
for sync).
- DELETE /register/{sessionId} let an anonymous caller unregister ANY session's
room from live-event sync -> denial-of-function.
Caller analysis: the endpoint has ZERO callers today — not ORISO-Frontend (its
endpoints.ts defines no sync-register URL; the browser only calls
/service/matrix/me/token), not any internal job, scheduled task, sibling
service, or Matrix appservice callback. It is orphaned code from the Matrix
migration. The /service/ prefix is just the ingress/inter-service path, not a
privileged channel — both variants share one method with identical (missing)
auth and must be locked together.
Fix (safe default that closes the external leak, mirrors sibling
MatrixMessageController exactly):
- Remove /matrix/sync/** + /service/matrix/sync/** from the permitAll() rule,
from web.ignoring(), and from csrf.whitelist.configUris. They now fall under
the existing "/matrix/**", "/service/matrix/**" rule requiring USER_DEFAULT or
CONSULTANT_DEFAULT, so the JWT filter and StatelessCsrfFilter apply.
- In the controller, call sessionService.assertUserHasAccess(sessionId,
authenticatedUser) at the top of each method, OUTSIDE the try/catch, so the
ForbiddenException (403) / NotFoundException (404) reach the global exception
handler instead of being swallowed into a 500. This closes the IDOR: an
authenticated caller can only touch a session they own (asker) or are assigned
to (consultant).
Because no caller exists today, nothing legitimate breaks. Minor behavior
change: DELETE for a genuinely missing session now returns 404 (was an
idempotent 200) — acceptable, and it stops anonymous session probing.
TDD (MatrixSyncControllerTest, matching MatrixMessageControllerTest style):
red before the fix (both deny paths threw nothing; authorized path returned
404), green after — register/unregister throw ForbiddenException before any
MatrixEventListenerService interaction, and an authorized participant still
registers the room (200). Tests run: 3, Failures: 0. Existing
MatrixMessageControllerTest still green (4/4). spotless:check clean. JDK 21.
Co-Authored-By: Claude Fable 5 <[email protected]>
|
Bugbot is not enabled for your account, so this pull request was not reviewed.
Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Important
Review skipped
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cae3425d-3340-4689-9823-108ee3927830
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Commit unit tests in branch
fix/userservice-auth-item5
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
Hassan9215
Awaiting requested review from Hassan9215
Shirloin
Awaiting requested review from Shirloin
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|