Repository navigation
fix(mcp): Check an issue an ID alone names against the session's project - #2527
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
BYK
left a comment
There was a problem hiding this comment.
Follow-up: events, traces and replays fetched by an opaque ID (event view , trace view , replay view ) are not checked against the session's project yet. This PR covers issue lookups only (Feedback included).
We should do this right away in a follow up PR>
The SDK's fake process started with `exitCode: 0`. Stricli records a failure with `exitCode ??= code`, which a 0 swallows, so `sdk.run()` resolved `undefined` for a command that failed, such as one whose API request returned 404. The exit code now starts unset, as on Node's own `process`. Ported from the same fix in #1922, which the scope checks in this stack need: a refused request has to reach the caller as an error. Refs #2237 Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
In a project-scoped `sentry mcp --commands` session, the command surface checks the targets a call names, but a numeric issue ID, an issue URL, a share link, a selector (`@latest`), or search text names no project, so `issue view 12345` or `issue resolve 12345` reached an issue in another project of the same organization. The stdio runner now passes `limitToTarget` to the CLI SDK, which makes the session's org and project a limit instead of a default. Issue lookups check the issue they find before a command reads or changes it: `getIssueInOrg` and `getIssueByShortId` refuse another organization before the request and another project after it, the issue and Feedback selectors and issue search look only in the session's project, and `event view` checks a numeric issue before it reads the issue's events. Fixes #2237 Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
`limitToTarget` now defaults to `true`: with `org` (and `project`) set,
`createSentrySDK()` refuses an issue outside them, including one an ID
alone names (`issue view 12345`, `@latest`). Pass `limitToTarget: false`
to use `org` and `project` only as defaults, as before.
`sentry mcp --commands` still passes `limitToTarget: true` explicitly, so
its sessions don't depend on the default.
BREAKING CHANGE: `createSentrySDK({ org, project })` no longer reads or
changes issues outside `org`/`project`. Callers that use them only to skip
typing the slug and look up issues elsewhere must pass
`limitToTarget: false`.
Refs #2237
Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
d76215d to
25e63d8
Compare
|
This PR is too large for Bugbot to review. It changes 50,402 lines and 3,791,240 characters. Split the change into smaller pull requests to get a review. |
|
bugbot run |
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 c77ff29. Configure here.
In a project-scoped session, the issue search runs in that project alone, so the no-match and several-match errors name it, and their recovery command lists that project's issues.
…the session's project (getsentry#2541) Follow-up to getsentry#2527 for getsentry#2237. Stacked on getsentry#2527. getsentry#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. <!-- 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>
) 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>

Refs #2237. Based on
main.In a project-scoped
sentry mcp --commandssession (acme/web), the command surface checks the targets a call names. Some identifiers name no project: a numeric issue ID, an issue URL, a share link, a selector such as@latest, or search text. The session's org and project reached the CLI only as defaults (SENTRY_ORG/SENTRY_PROJECT), so nothing compared the issue the CLI found with the session. Examples that got through:issue view 12345read an issue in another project.issue resolve 12345changed an issue in another project.issue view @latestandfeedback view @latestpicked the newest issue in the whole organization.event view https://acme.sentry.io/issues/12345/read another project's events.As proposed in the issue, the CLI now checks the issue after it looks it up and before a command reads or changes anything.
Changes
SentryOptions.limitToTargetmakesorg/projecta limit instead of a default. It defaults totrue, andlimitToTarget: falseopts out. The SDK passes it to the invocation as the internal env varsSENTRY_CLI_SCOPE_ORG/SENTRY_CLI_SCOPE_PROJECT. Thesentry mcp --commandsrunner wiring that sets it now lives in fix(mcp): Limit sentry mcp --commands sessions to their target #2554.lib/target-scope.tsrefuses an issue in another organization or project with aResolutionError. In a project scope, an issue whose project is unknown is refused too.getIssueInOrgandgetIssueByShortIdrefuse another organization before the request and another project after it. Every lookup by ID goes through these two: numeric,<org>/<id>, URL, share link, short ID and alias.findSelectorIssue, issue search and the Feedback@latestselector look only in the session's project, then check the result.event view. For a numeric issue or an issue URL, it checks the issue before it reads the issue's events. Before, its project lookup was best-effort, and it was skipped when the call named a project.library-usage.md) now describes the limit. The--commandsnotes (docs/architecture/overview.md, mcp-coreconstraints.ts) now live in fix(mcp): Limit sentry mcp --commands sessions to their target #2554.Breaking change:
createSentrySDK({ org, project })callers now getorg/projectas a limit, not just a default, so a command that reaches another organization or project fails. PasslimitToTarget: falseto keep the old behavior.Follow-up: events, traces and replays fetched by an opaque ID (
event view <event-id>,trace view <trace-id>,replay view <replay-id>) are not checked against the session's project yet. This PR covers issue lookups only (Feedback included).via @BYK.
--
View Session [Sentry]