Repository navigation
fix(messaging): enforce target ownership in createSubscriber - #14019
Conversation
A session or JWT caller could pass any user's targetId to POST /messaging/topics/:topicId/subscribers. The handler loaded the target with authorization skipped and never checked ownership, so an authenticated user could bind another user's email, SMS or push target to a topic and the 201 response disclosed the victim's identifier. Inject the current user and require the target's userId to match the caller, mirroring account.updatePushTarget. Admin console and API key callers act for the project and stay exempt. Non-owners now get a 404 (USER_TARGET_NOT_FOUND), which also avoids a target-existence oracle and closes the identifier disclosure. The subscriber document keeps deriving its userId, permissions and userName from the target owner.
🟢 Tier S · Ready to merge
The pull request restricts subscriber creation to targets owned by the authenticated user, while preserving API-key and privileged-console access. Subscriber metadata and permissions remain tied to the target owner. Shared E2E coverage checks foreign-target denial, identifier non-disclosure, and privileged success; existing messaging fixtures now use API keys when subscribing targets belonging to separately created users. Latest changes: The newest commits switch cross-user subscriber setup in messaging delivery tests and fixtures to explicit API-key requests, matching the new ownership restriction.
📂 Walkthrough · 2
Reviewed the commits since |
|
| $this->assertEquals(201, $response['headers']['status-code']); | ||
| $this->assertEquals($victimTarget['body']['$id'], $response['body']['target']['$id']); |
There was a problem hiding this comment.
Subscriber ownership goes untested The privileged branch checks only that creation succeeds and the response contains the requested target ID. The handler also changes the subscriber's owner, permissions, and user name, so those fields could regress while this test still passes. Please check that the subscriber belongs to the target's owner and that the owner can read or delete it.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/e2e/Services/Messaging/MessagingBase.php
Line: 1782-1783
Comment:
**Subscriber ownership goes untested** The privileged branch checks only that creation succeeds and the response contains the requested target ID. The handler also changes the subscriber's owner, permissions, and user name, so those fields could regress while this test still passes. Please check that the subscriber belongs to the target's owner and that the owner can read or delete it.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
The push, email-attachment, reply-to and sub-query tests, plus the SMS, push and email send-setup helpers, subscribed a target owned by a freshly created user while calling as the session user. That only passed because createSubscriber skipped the ownership check; with the check in place the session caller correctly gets a 404. These calls only need the subscription to exist, so make them server (API key) calls, which act for the project and may subscribe any user's target. The owner-path and side-specific subscriber tests keep using the session.
Brings in main's OAuth2 state and nonce validation (#14012), which cloud needs, along with the realtime origin alignment (#14020), subscriber target ownership (#14019), GitLab primary email (#14010), impersonation MFA (#14017), write-only webhook passwords (#14016), chunked-upload resume ownership (#14014), preview authorize validation (#14013), nightly forcing (#14015) and scheduled-function enqueue checks (#14011). The merge had no textual conflicts, and main left composer.json and composer.lock unchanged. So the lock keeps the branch's database and async pins. Main's assertResumeAllowed() in Storage Buckets/Files/Create checks Input(Database::PERMISSION_UPDATE, ...). utopia-php/database 8 has no PERMISSION_* constants, so every chunked resume would fail with an undefined-constant error. It now passes PermissionType::Update, as the rest of that action already does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
Fixes an authorization flaw in
createSubscriber(POST /v1/messaging/topics/:topicId/subscribers) reported privately by Alpesh Bhagwatkar.An authenticated session or JWT caller could pass any user's
targetId. The handler loaded the target with authorization skipped and never checked ownership, so a normal project user could bind another user's email, SMS or push target to a topic they can subscribe to. The 201 response also returned the victim'starget.identifier(email address, phone number or push token) anduserName, disclosing that data to the attacker.The only preconditions are the default
subscribers.writescope, a topic whosesubscribeallowsusers/any, and knowledge of the victim'stargetId(custom push target IDs can be predictable).Fix
The current user is now injected into the action. Unless the caller is an API key or admin console request, the target's
userIdmust match the caller — the same ownership ruleaccount.updatePushTargetalready enforces. Non-owners get404 USER_TARGET_NOT_FOUND, which both avoids a target-existence oracle and closes the identifier disclosure since a non-owner never reaches the response. The subscriber document keeps deriving itsuserId, permissions anduserNamefrom the target owner, so API key / admin subscriptions on behalf of a user are unchanged.Note: the reporter suggested returning 401. I used 404 to match the existing
account.updatePushTargetconvention and to avoid confirming that a target exists.Test
testCreateSubscriberForeignTargetDeniedinMessagingBase:Verified red→green against a live stack: before the change the cross-user call returned 201 with the victim's email in the body; after it returns 404 with no leak, while the owner path and the API-key path still return 201 with the subscriber correctly owned by the target owner.
Have you read the Contributing Guidelines on issues?
Yes.