Repository navigation
fix(mcp): Check events, traces and replays an ID alone names against the session's project - #2541
Merged
BYK merged 5 commits intoNov 29, 2026
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
BYK
approved these changes
Nov 26, 2026
…the session's project A project-scoped `sentry mcp --commands` session still reached other projects through IDs that name no project. `event view <event-id>` fell back to the org-wide event ID lookup, `trace view <trace-id>` reads a trace org-wide, and `replay view <replay-id>` checked the replay's project only when the call named one. The scope checks in `target-scope.ts` now take what they check (`Issue 123`, `Event abc`), and `assertProjectInScope` covers anything with a project slug: - `getEvent` and `resolveEventInOrg` refuse an event outside the scope, and `event view` no longer swallows that refusal in its fallbacks. - `getDetailedTrace` refuses a trace with no span in the session's project. A trace that has one keeps the spans of the projects it calls into. - `resolveReplay` refuses another organization, and the replay project check also compares the replay with the session's project. A replay without a project is refused in a project scope. Refs #2237 Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
sentry-junior
Bot
force-pushed
the
fix/mcp-commands-opaque-id-scope
branch
from
November 27, 2026 11:56
59db38d to
4ee3341
Compare
…t list `replay view --web` opened the replay before `validateReplayProjectScope` ran, so a project-scoped session could open another project's replay that an ID alone names. The scope check now runs first. A refused event, trace or replay suggested `issue list`. The hint now names the list command of what was refused (`event list acme/web`). Refs #2237
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 719d201. Configure here.
`event list` takes an issue, not a project, and `trace list` needs a project. A refused event now suggests `issue list`, and a refused trace suggests `trace list` only in a project scope. Refs #2237
…ands-opaque-id-scope
…ands-opaque-id-scope
BYK
approved these changes
Nov 28, 2026
github-actions Bot
pushed a commit
to Fields-Education/sentry-mcp
that referenced
this pull request
Nov 30, 2026
) Refs getsentry#2237. Stacked on getsentry#2541 (→ getsentry#2527 → `main`). getsentry#2527 and getsentry#2541 checked the `limitToTarget` scope call by call, one assert per lookup and one project filter per list caller. Anything they missed wasn't checked at all, for example: - `trace logs <trace-id>`: Sentry's `trace-logs` and `trace-meta` ignore the `project` filter. - `sentry api organizations/<other>/...`. - The two preprod downloads that send the token around the transport. This PR moves the check into the transport, so a new code path can't skip it. **What already existed.** Nothing enforced the scope centrally. - `assertCredentialScope` in `prepareHeaders` checks only the host, and it runs after the transport's cache lookup. - `sdk-invoke.ts` only turns `limitToTarget` into the `SENTRY_CLI_SCOPE_*` env vars. The new check reads those env vars (`getTargetScope()`) and runs in the same authenticated fetch, before the cache. **How it works** `scopeRequest` (`lib/target-scope.ts`) runs in `createAuthenticatedFetch` before `transport.request`. That covers SDK calls, `apiRequestToRegion`, raw `sentry api` and cached responses. `withTargetScope()` applies the same check to the share-link fetch and the preprod downloads. With no scope, nothing changes. A scoped invocation fails closed: a request that matches no rule in `lib/target-scope-rules.ts` is refused before it is sent. - **Paths.** `organizations|projects|teams|customers/<org>/…` must name the scope's org. In a project scope, `projects/<org>/<project>/…` must also name its project, by slug or ID. - **Project filter** (project scope). `issues/` (including bulk PUT/DELETE), `events/`, `events-timeseries/`, `events-dropped/`, `trace-items/attributes/`, `replays/`, `replay-count/`, `monitors/`, `detectors/`, `workflows/`, `releases/` and `agents/conversations/` get filtered to the scope's project. A missing `project` or `-1` is replaced with the scope project's ID, looked up once per process. Any other project is refused. - **Checked by the response** (project scope). `issues/<id>/`, `shortids/<id>/`, `shared/issues/<id>/`, `eventids/<id>/`, `replays/<id>/`, `monitors/<id>/`, `detectors/<id>/`, `releases/<version>/` and `trace/<id>/`. A trace with one span in the project counts as in scope, as in getsentry#2541. - **Looked up first** (project scope). A request on what an ID names first runs the matching response check, once per process. This covers `PUT issues/<id>/`, `issues/<id>/events/…`, monitor and detector writes, release sub-resource reads, `trace-meta/<id>/` and `trace-logs/?traceId=`. - **Allowlist.** - Any scope: `GET /api/0/`, `auth/` and `users/me/`. - Project scope, org settings with no project data: org details, `projects/`, `teams/`, `members/`, `environments/`, `integrations/`, `repos/`, `sentry-app-components/`, and reads of `dashboards/…` and `workflows/<id>/`. The asserts and project filters from getsentry#2527 and getsentry#2541 are removed. One piece stays: `event view`'s fallback still rethrows `ResolutionError`. That catch-all would otherwise turn a refusal into a search across other orgs. The repo has no `design/` directory, so the rule is written in `docs/architecture/overview.md` and in the `limitToTarget` row of `library-usage.md`. **Open questions** - `limitToTarget` defaults to `true` since getsentry#2527, so every `createSentrySDK({ org, project })` caller now fails closed too, not just `--commands` sessions. Refused in a project scope today: - org-level writes other than issues, monitors and detectors: dashboard writes, release writes (a release spans projects), workflow writes, team and project creation, org auth tokens, code mappings, artifact bundles and chunk uploads; - `sentry-app-installations/…`, used for issue links; - `customers/…`, used for trials; - `dsn-lookup/`, `project-keys/`, preprod endpoints and `agents/conversations/<id>/`; - the org list. Should fail-closed apply only when `sentry mcp --commands` sets the scope, with plain SDK callers keeping only the ID checks? - Spans from other projects in an in-scope trace are still returned. Their details (`projects/<other>/trace-items/…`) are now refused, so `trace view` lists them without details. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A30387dbb15a73c1ea95ce25e5f09b56a --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A30387dbb15a73c1ea95ce25e5f09b56a) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A30387dbb15a73c1ea95ce25e5f09b56a/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <126780+BYK@users.noreply.github.com>
This branch was successfully 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.

Follow-up to #2527 for #2237. Stacked on #2527.
#2527 checks issues. In a project-scoped
sentry mcp --commandssession (acme/web), events, traces and replays fetched by an opaque ID still reached other projects:event view <event-id>404s inacme/web, then its fallback finds the event org-wide (/eventids/) and shows it. The same happens withevent view acme/ <event-id>.trace view <trace-id>reads the trace org-wide.replay view <replay-id>checked the replay's project only when the call named a project.Changes
target-scope.ts. The checks now take what they check (Issue 123,Event abc) for the error. The newassertProjectInScope(org, projectSlug, subject)covers anything with a project slug.assertIssueInScopenow uses it.getEventrefuses a project outside the scope before the request.resolveEventInOrgrefuses another org before the request and another project after it.event viewused to swallow every non-auth error in its same-org fallback. It now passes a scope refusal through.getDetailedTracerefuses another org. In a project scope, it also refuses a trace with no span in the session's project, at any depth.trace view,span viewand the span tree inevent viewall read traces through it.resolveReplayrefuses another org.validateReplayProjectScope, whichreplay viewandreplay downloadalready run, now also compares the replay with the session's project. A replay without a project, such as an archived one, is refused in a project scope.Open question: a trace that has a span in the session's project is returned whole, including spans from the other projects it calls into. Sentry's trace view works the same way, and a distributed trace isn't useful cut down to one project. If the session should only ever see its own project's spans, the next step is to filter spans instead of checking the trace.
via @BYK.
--
View Session [Sentry]