Skip to content

fix(mcp): Check events, traces and replays an ID alone names against the session's project - #2541

Merged
BYK merged 5 commits into
fix/mcp-commands-numeric-issue-scopefrom
fix/mcp-commands-opaque-id-scope
Nov 29, 2026
Merged

BYK merged 5 commits into
fix/mcp-commands-numeric-issue-scopefrom
fix/mcp-commands-opaque-id-scope

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #2527 for #2237. Stacked on #2527.

#2527 checks issues. In a project-scoped sentry mcp --commands session (acme/web), events, traces and replays fetched by an opaque ID still reached other projects:

  • event view <event-id> 404s in acme/web, then its fallback finds the event org-wide (/eventids/) and shows it. The same happens with event 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 new assertProjectInScope(org, projectSlug, subject) covers anything with a project slug. assertIssueInScope now uses it.
  • Events. getEvent refuses a project outside the scope before the request. resolveEventInOrg refuses another org before the request and another project after it. event view used to swallow every non-auth error in its same-org fallback. It now passes a scope refusal through.
  • Traces. getDetailedTrace refuses 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 view and the span tree in event view all read traces through it.
  • Replays. resolveReplay refuses another org. validateReplayProjectScope, which replay view and replay download already 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]

@sentry-junior
sentry-junior Bot added this pull request to stack #1926 November 26, 2026 19:30
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Nov 28, 2026 1:45am UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 28, 2026 1:45am UTC

Request Review

@BYK
BYK marked this pull request as ready for review November 26, 2026 23:07
@BYK
BYK requested a review from a team as a code owner November 26, 2026 23:07
@github-actions github-actions Bot added the risk: medium PR risk score: medium label 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>

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

Stale Bugbot comment from a previous run.

Comment thread packages/cli/src/lib/target-scope.ts Resolved
…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

@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 using default effort and found 1 potential issue.

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 719d201. Configure here.

Comment thread packages/cli/src/lib/target-scope.ts Resolved
`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
@BYK
BYK added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit aa7a1a3 Nov 29, 2026
29 checks passed
@BYK
BYK deleted the fix/mcp-commands-opaque-id-scope branch November 29, 2026 20:19
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

1 active and 1 inactive deployments
Preview – cli — db0f660e Deployed Nov 28, 2026 by vercel[bot]
Preview – sentry-local — db0f660e Deployed Nov 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant