Repository navigation
fix(oauth): Request only skill-derived scopes from Sentry - #1546
Closed
sentry-junior[bot] wants to merge 4 commits into
Closed
sentry-junior[bot] wants to merge 4 commits into
sentry-junior[bot] wants to merge 4 commits into
Conversation
The approval POST redirects to Sentry's /oauth/authorize/ with every scope in SCOPES, regardless of which skills the user selected. Selecting only 'inspect' still requests project/team/event/alerts write scopes. These tests compare the write scopes requested upstream against getScopesForSkills() for the selected skills. They fail on main and pass once redirectToUpstream requests skill-derived scopes. Co-Authored-By: Shaun Kaasten <shaun.kaasten@sentry.io>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Check the full scope list sent to Sentry rather than only the absence of extra write scopes. Inspect-only must request exactly event:read, org:read, project:read, and team:read; other skill sets must request exactly getScopesForSkills(selected). Co-Authored-By: Shaun Kaasten <shaun.kaasten@sentry.io>
The approval POST redirected to Sentry's /oauth/authorize/ with every
scope in SCOPES, so the consent screen and the upstream token included
project/team/event/alerts write access even when only read-only skills
were selected.
Compute the upstream scope from the approved skills with
getScopesForSkills(). Inspect-only now requests
event:read org:read project:read team:read.
analyze_issue_with_seer declared no required scopes, but starting an
autofix run POSTs to /issues/{id}/autofix/, which Sentry gates on
event:write (GroupAiPermission). Declare event:write so the Seer skill
keeps working with the narrower upstream token.
Update docs/operations/security.md to describe skill-derived upstream
scopes.
Co-Authored-By: Shaun Kaasten <shaun.kaasten@sentry.io>
skaasten
marked this pull request as ready for review
October 19, 2026 19:36
Contributor
There was a problem hiding this comment.
I suspect we still need some more scopes to make the tools actual useful, and i think we'll need to go through all these tools to make sure the scopes are correct. For example for search_traces: I believe a lot of the tracing actually requires org:read and not event:read https://docs.sentry.io/api/discover/retrieve-a-trace/, and https://docs.sentry.io/api/explore/query-explore-events-in-table-format/ are examples
Trace, trace-meta, events, events-timeseries, events/validate, and trace-items/attributes all inherit OrganizationEventsEndpointBase, which uses OrganizationPermission (GET requires org:read), not event:read. - get_trace_details / get_span_details: org:read - search_events and dataset search tools (searchToolBase): org:read + project:read (project lookup via ProjectDetailsEndpoint) No change to requested OAuth scopes: DEFAULT_SCOPES already includes org:read and project:read. This makes the per-tool declarations accurate.
Contributor
|
Decided the benefits are not worth the maintenance effort to keep these scopes in sync with api calls. |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Requests only the Sentry scopes the selected skills need, instead of always requesting write access.
Background: why every scope was requested
redirectToUpstream(packages/mcp-cloudflare/src/server/oauth/routes/authorize.ts) always requested every scope inSCOPES,org:read project:write team:write event:write alerts:write, whatever skills were selected. This was intentional.docs/operations/security.mdgave three reasons:The actual permission boundary was the MCP-side skill gating, not the Sentry token. As a result, a user who approved only Inspect Issues & Events still saw Sentry's consent screen ask for read and write access to teams, projects, events, and alerts, and the server-side token had that access.
Was it necessary?
As far as I can tell, no. None of the three reasons requires write scopes for read-only skills:
requiredScopes, andgetScopesForSkills()turns a set of skills into the scopes those tools need. It was only used after consent (callback.ts, stored asgrantedScopes) and never sent to Sentry.getScopesForSkills(selected)gives a token that covers every tool those skills enable.The one real dependency was hidden: a tool whose declared
requiredScopeswas wrong.analyze_issue_with_seerdeclared[], but starting an autofix run is aPOST /organizations/{org}/issues/{id}/autofix/, and Sentry gates that onevent:write(GroupAiPermission). It only worked because the token always hadevent:write. This PR fixes that declaration.Changes
authorize.ts: build the upstreamscopefrom the approved skills withgetScopesForSkills(parseSkills(skills).valid). Inspect-only now requestsevent:read org:read project:read team:read.analyze-issue-with-seer.ts:requiredScopes: ["event:write"]. The generatedtoolDefinitions.jsonandskillDefinitions.jsonare regenerated.docs/operations/security.md: describe skill-derived upstream scopes instead of a fixed set.authorize.test.ts: assert the exactscope=sent to Sentry, reads included:inspectgets exactlyevent:read org:read project:read team:readinspect+seeraddsevent:writeinspect,+seer,+triage,+project-managementeach equalgetScopesForSkills(selected)Audit
I checked every tool that calls a write endpoint (POST, PUT, or DELETE) against the scopes Sentry requires for that endpoint in getsentry/sentry:
event:write, which the skill grants.project:write,team:write, oralerts:write, which the skill grants.org:read.event:write, which was missing and is fixed hereget_issue_details,GET .../autofix/) needsevent:readorg:readRead-only tools are covered because the default read scopes (
org:read project:read team:read event:read) are always requested.Not in this PR
routes/chat-oauth.ts(the separate chat sign-in) still requests the fullSCOPESset. It doesn't use skills.Testing
@sentry/mcp-cloudflare: 438/438 pass@sentry/mcp-core: 1823 pass (6 skipped);validate-skillspassesmainwithout the fix, the new scope tests fail. Every case requestsalerts:write event:write org:read project:write team:write.via shaun.kaasten.
--
View Junior Session [Sentry]