Skip to content

ref(api): Narrow request.user in token, app, auth and broadcast endpoints - #129414

Merged
gricha merged 1 commit into
ref/typing-shared-principalfrom
ref/sa-narrow-api-a
Nov 3, 2026
Merged

gricha merged 1 commit into
ref/typing-shared-principalfrom
ref/sa-narrow-api-a

Conversation

@gricha

@gricha gricha commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Reads of request.user in 14 API endpoints (API tokens, applications, authorizations, auth index, assistant, broadcasts, invites, project transfer, attachments, internal mail) go through sentry.auth.principal:

  • "Mine" lookups (apps, authorizations, guides, seen broadcasts) use owned_by_acting_user().
  • Logs, analytics and the nullable Activity/Broadcast creator use acting_user_id().
  • Personal writes and user-only reads (tokens, assistant state, invite accept, transfer, email, 2FA) use require_user().

Users, agents and token callers see no change. A service account gets empty personal state on reads and 403 user-required on personal writes; most of these endpoints are control-silo, where service accounts don't authenticate yet.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 31, 2026
@gricha
gricha added this pull request to stack #129364 October 31, 2026 02:27
@gricha
gricha removed this pull request from stack #129364 November 1, 2026 04:24
@gricha
gricha force-pushed the ref/sa-narrow-api-a branch from 6443968 to 6a1400a Compare November 1, 2026 04:24
@gricha
gricha added this pull request to stack #129440 November 1, 2026 04:24
@sentry

sentry Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Sentry Snapshot Testing

Name Added Removed Changed Renamed Unchanged Skipped Status
sentry-frontend
sentry-frontend
0 0 0 0 780 0 ✅ Unchanged

⚙️ sentry-frontend Snapshot Settings

@gricha
gricha force-pushed the ref/sa-narrow-api-a branch from 6a1400a to 7213368 Compare November 2, 2026 19:55
@gricha
gricha marked this pull request as ready for review November 2, 2026 20:12
@gricha
gricha requested review from a team as code owners November 2, 2026 20:12
@gricha
gricha requested review from azulus, cvxluo and skaasten November 2, 2026 20:25
@gricha
gricha removed this pull request from stack #129440 November 2, 2026 21:45
@gricha
gricha added this pull request to stack #129572 November 2, 2026 21:45
@gricha
gricha force-pushed the ref/sa-narrow-api-a branch from 7213368 to c74c6bd Compare November 2, 2026 22:08
unseen_queryset = queryset.exclude(
id__in=queryset.filter(broadcastseen__user_id=request.user.id).values("id")
id__in=queryset.filter(
owned_by_acting_user(request.user, "broadcastseen__user_id")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should this string be a const or linted somewhere? is that a thing?

@gricha
gricha force-pushed the ref/sa-narrow-api-a branch 2 times, most recently from 4f15d46 to 02a0ff5 Compare November 2, 2026 23:08

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 02a0ff5. Configure here.

):
warnings.append(
f"Your account ({request.user.email}) is not a member of the "
f"Your account ({require_user(request).email}) is not a member of the "

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.

Login config 403s non-user callers

Low Severity

require_user is used only to interpolate an email into a warning on this public GET. For an authenticated caller with no user, such as a service account, that raises user-required and fails the whole login-config response instead of returning empty personal state.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 02a0ff5. Configure here.

def get(self, request: Request) -> Response:
if request.user.is_authenticated:
user = User.objects.get(id=request.user.id)
user = User.objects.get(id=require_user(request).id)

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.

API index 403s non-user reads

Low Severity

The API index GET treats a missing acting user as a hard require_user failure. An authenticated service account now gets 403 instead of {user: null} plus auth scopes, which is the empty personal state this read already returns for anonymous callers.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 02a0ff5. Configure here.

@gricha
gricha force-pushed the ref/sa-narrow-api-a branch from 02a0ff5 to 1e44633 Compare November 2, 2026 23:18
…ints

Reads of `request.user` in 14 API endpoints (API tokens, applications, authorizations, auth index, assistant, broadcasts, invites, project transfer, attachments, internal mail) go through `sentry.auth.principal`:

- "Mine" lookups (apps, authorizations, guides, seen broadcasts) use `owned_by_acting_user()`.
- Logs, analytics and the nullable Activity/Broadcast creator use `acting_user_id()`.
- Personal writes and user-only reads (tokens, assistant state, invite accept, transfer, email, 2FA) use `require_user()`.

Users, agents and token callers see no change. A service account gets empty personal state on reads and 403 `user-required` on personal writes; most of these endpoints are control-silo, where service accounts don't authenticate yet.
@gricha
gricha force-pushed the ref/sa-narrow-api-a branch from 1e44633 to 7eff818 Compare November 2, 2026 23:31
@gricha
gricha merged commit e39c07b into master Nov 3, 2026
76 checks passed
@gricha
gricha deleted the ref/sa-narrow-api-a branch November 3, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants