Skip to content

feat(cli): Send login_hint with sentry auth login <email> - #1580

Merged
BYK merged 2 commits into
mainfrom
feat/cli-device-login-hint
Nov 9, 2026
Merged

BYK merged 2 commits into
mainfrom
feat/cli-device-login-hint

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

sentry auth login <email> now sends the email as login_hint in the device authorization request. Sentry adds support for this in getsentry/sentry#128458. With it, the verification page refuses approval from a different signed-in user up front and asks them to switch accounts. Today the user approves, and only then does the CLI throw the token away.

  • deviceCodeRequestBody (toolkit-core) takes an optional loginHint and adds login_hint only when one is given. Callers that don't pass it, such as the MCP stdio flow, send the same body as before.
  • performDeviceFlow / requestDeviceCode pass the hint through. runInteractiveLogin sends expectedEmail.
  • The existing assertExpectedLoginEmail check stays. Servers that predate the parameter ignore it, including self-hosted instances and sentry.io until #128458 deploys. On those, the browser's user can still approve, and the CLI-side check is what catches a mismatch.
  • The auth login help text and the auth docs fragment are updated to match.

Re-authorizing a stored account by accountId (scope recovery) doesn't send a hint. That check matches by user id, and the stored email could be stale.

Checks run locally

  • vitest passes for test/lib/interactive-login.test.ts, test/lib/oauth.test.ts, test/commands/auth/* and toolkit-core/src/oauth-device.test.ts.
  • pnpm run lint passes.
  • tsc --noEmit is clean for toolkit-core and mcp-server. In the CLI, the only errors are missing generated files.
  • The CLI's full typecheck script couldn't finish here because generate:banner crashes in this sandbox's Node 22.22.2 (the pin is 22.23.4). CI should cover it.

via BYK.

--

View Junior Session in Sentry

@vercel

vercel Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
sentry-local Ready Ready Preview Nov 9, 2026 12:31pm UTC

Request Review

@BYK BYK left a comment

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.

Resolve merge conflicts please

Pass the requested email as the device flow's login_hint so Sentry
refuses approval from a different signed-in user up front, instead of
the CLI discarding the token after the fact. The local email check
stays for servers that ignore the hint.

Server side: getsentry/sentry#128458

Co-Authored-By: BYK <[email protected]>
@sentry-junior
sentry-junior Bot force-pushed the feat/cli-device-login-hint branch from d17f1be to e630c99 Compare October 27, 2026 21:44
BYK added a commit to getsentry/sentry that referenced this pull request Oct 28, 2026
…8458)

The Sentry CLI's `sentry auth login <email>` (getsentry/toolkit
multi-account mode) has no way to tell the device flow which account it
expects. Whoever is signed in to the browser approves the request, and
the CLI can only throw the token away afterwards. By then the server has
already issued it.

This PR adds an optional `login_hint` to `POST /oauth/device/code/`. RFC
8628 §3.1 allows extension parameters, and the name comes from OpenID
Connect. The hint is an email. It is stored on `ApiDeviceCode` and
checked on the verification endpoint:

- `GET /api/0/oauth/device/` (consent preparation) returns 403 if the
signed-in user's primary email doesn't match the hint,
case-insensitively. Consent is not bound to the session. The `detail`
names the expected account.
- `POST /api/0/oauth/device/` checks again before approving or denying,
so a prepared session can't get around it.

Without a hint, everything works as before.

**Why 403 and the primary email**
- The device page already treats a 403 on consent from an authenticated
session as "this account can't authorize the request." It shows the
error and keeps the switch-account control. So the user sees "This
request is for [email protected]. Sign in as that account to continue."
with no frontend change needed.
- The CLI checks `user.email` from the token response. Matching only the
primary email keeps the server and the CLI in agreement.

**Notes for review**
- Migration `1245` adds a nullable `varchar(200)` column to
`sentry_apidevicecode`. The length matches `User.email`. A hint over 200
characters gets `invalid_request`.
- The hint is sanitized with `set_email` during relocation, and the
exhaustive backup fixture now sets it.
- The hint is not logged. Only a `has_login_hint` metric tag is added.

The CLI side is getsentry/toolkit#1580.

Fixes #127918
Fixes ENG-8835

<!-- junior-request-attribution:start -->
via **BYK**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:local%3Aweb%3A7f8efa11623b9416987ceb44 -->

--

[View Junior Session in
Sentry](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A7f8efa11623b9416987ceb44/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>
@BYK
BYK enabled auto-merge (squash) November 9, 2026 12:23
Resolve the conflict in packages/cli/src/lib/oauth.ts: keep main's
requestDeviceCode (no withHttpSpan wrapper) and re-apply the loginHint
parameter passed to deviceCodeRequestBody.

Co-Authored-By: BYK <[email protected]>
@BYK
BYK merged commit 12aded5 into main Nov 9, 2026
33 checks passed
@BYK
BYK deleted the feat/cli-device-login-hint branch November 9, 2026 12:41
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
…, url-parser) (getsentry#1580)

## Summary

Fix 3 grandfathered silent catch blocks by adding `log.debug()` calls to
surface errors that were previously swallowed silently. Each fix follows
the project's established pattern from AGENTS.md and the
`no-silent-catch` Biome plugin (getsentry#1531).

## Changes

### 1. `src/lib/resolve-team.ts` — `fetchOrgListHint()`

**Root cause:** When `listOrganizations()` fails during team resolution
(used by `project create` and `init`), the error was silently swallowed.
Users got a generic fallback hint with no indication of what went wrong
(expired token, network issue, 403, etc.).

**Reproduction:** Any scenario where `listOrganizations()` fails during
team resolution — e.g., run `sentry project create` with an expired
token.

**Fix:** Add `log.debug("Failed to fetch org list for hint", error)` and
remove the `biome-ignore` comment.

### 2. `src/lib/trace-target.ts` — `recoveryContextFromTargetArg()`

**Root cause:** When `parseOrgProjectArg` threw on a malformed target
string during trace ID recovery, the error was silently swallowed and
recovery proceeded with empty context. This hid parse errors that could
help debug user input issues in `trace view`, `span view`, `span list`.

**Reproduction:** Run `sentry trace view --h/nothex` — the slug
validation error from `parseOrgProjectArg` is silently swallowed.

**Fix:** Add `log.debug("Failed to parse target arg for recovery
context", error)`, promote the logger to module scope, and rename the
shadowed local in `warnIfNormalized` to fix the `noShadow` lint error.

### 3. `src/lib/sentry-url-parser.ts` — `parseSentryUrl()`

**Root cause:** When a URL-looking string (starts with `http://` or
`https://`) failed to parse via `new URL()`, the error was silently
swallowed. This function is used by dashboard, event, trace, and other
commands to detect pasted Sentry URLs.

**Reproduction:** Pass a malformed URL like `https://[invalid` to any
command that accepts Sentry URLs.

**Fix:** Add `log.debug("Failed to parse URL", input, error)` and remove
the `biome-ignore` comment.

## Testing

- All existing tests pass (resolve-team: 1 test, trace-target: 19 tests,
sentry-url-parser: 84 tests)
- Lint passes clean (`biome check` — 0 errors)

<div><a
href="https://cursor.com/agents/bc-259f34b1-c9e3-4d43-a65c-4138f0f6d5ca?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/automations/95624600-485e-4461-829e-6b76f086c473"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/view-automation-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/view-automation-light.png"><img
alt="View Automation" width="141" height="28"
src="https://cursor.com/assets/images/view-automation-dark.png"></picture></a>&nbsp;</div>

---------

Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: Miguel Betegón <[email protected]>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
…, url-parser) (getsentry#1580)

## Summary

Fix 3 grandfathered silent catch blocks by adding `log.debug()` calls to
surface errors that were previously swallowed silently. Each fix follows
the project's established pattern from AGENTS.md and the
`no-silent-catch` Biome plugin (getsentry#1531).

## Changes

### 1. `src/lib/resolve-team.ts` — `fetchOrgListHint()`

**Root cause:** When `listOrganizations()` fails during team resolution
(used by `project create` and `init`), the error was silently swallowed.
Users got a generic fallback hint with no indication of what went wrong
(expired token, network issue, 403, etc.).

**Reproduction:** Any scenario where `listOrganizations()` fails during
team resolution — e.g., run `sentry project create` with an expired
token.

**Fix:** Add `log.debug("Failed to fetch org list for hint", error)` and
remove the `biome-ignore` comment.

### 2. `src/lib/trace-target.ts` — `recoveryContextFromTargetArg()`

**Root cause:** When `parseOrgProjectArg` threw on a malformed target
string during trace ID recovery, the error was silently swallowed and
recovery proceeded with empty context. This hid parse errors that could
help debug user input issues in `trace view`, `span view`, `span list`.

**Reproduction:** Run `sentry trace view --h/nothex` — the slug
validation error from `parseOrgProjectArg` is silently swallowed.

**Fix:** Add `log.debug("Failed to parse target arg for recovery
context", error)`, promote the logger to module scope, and rename the
shadowed local in `warnIfNormalized` to fix the `noShadow` lint error.

### 3. `src/lib/sentry-url-parser.ts` — `parseSentryUrl()`

**Root cause:** When a URL-looking string (starts with `http://` or
`https://`) failed to parse via `new URL()`, the error was silently
swallowed. This function is used by dashboard, event, trace, and other
commands to detect pasted Sentry URLs.

**Reproduction:** Pass a malformed URL like `https://[invalid` to any
command that accepts Sentry URLs.

**Fix:** Add `log.debug("Failed to parse URL", input, error)` and remove
the `biome-ignore` comment.

## Testing

- All existing tests pass (resolve-team: 1 test, trace-target: 19 tests,
sentry-url-parser: 84 tests)
- Lint passes clean (`biome check` — 0 errors)

<div><a
href="https://cursor.com/agents/bc-259f34b1-c9e3-4d43-a65c-4138f0f6d5ca?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/automations/95624600-485e-4461-829e-6b76f086c473"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/view-automation-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/view-automation-light.png"><img
alt="View Automation" width="141" height="28"
src="https://cursor.com/assets/images/view-automation-dark.png"></picture></a>&nbsp;</div>

---------

Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: Miguel Betegón <[email protected]>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
…, url-parser) (getsentry#1580)

## Summary

Fix 3 grandfathered silent catch blocks by adding `log.debug()` calls to
surface errors that were previously swallowed silently. Each fix follows
the project's established pattern from AGENTS.md and the
`no-silent-catch` Biome plugin (getsentry#1531).

## Changes

### 1. `src/lib/resolve-team.ts` — `fetchOrgListHint()`

**Root cause:** When `listOrganizations()` fails during team resolution
(used by `project create` and `init`), the error was silently swallowed.
Users got a generic fallback hint with no indication of what went wrong
(expired token, network issue, 403, etc.).

**Reproduction:** Any scenario where `listOrganizations()` fails during
team resolution — e.g., run `sentry project create` with an expired
token.

**Fix:** Add `log.debug("Failed to fetch org list for hint", error)` and
remove the `biome-ignore` comment.

### 2. `src/lib/trace-target.ts` — `recoveryContextFromTargetArg()`

**Root cause:** When `parseOrgProjectArg` threw on a malformed target
string during trace ID recovery, the error was silently swallowed and
recovery proceeded with empty context. This hid parse errors that could
help debug user input issues in `trace view`, `span view`, `span list`.

**Reproduction:** Run `sentry trace view --h/nothex` — the slug
validation error from `parseOrgProjectArg` is silently swallowed.

**Fix:** Add `log.debug("Failed to parse target arg for recovery
context", error)`, promote the logger to module scope, and rename the
shadowed local in `warnIfNormalized` to fix the `noShadow` lint error.

### 3. `src/lib/sentry-url-parser.ts` — `parseSentryUrl()`

**Root cause:** When a URL-looking string (starts with `http://` or
`https://`) failed to parse via `new URL()`, the error was silently
swallowed. This function is used by dashboard, event, trace, and other
commands to detect pasted Sentry URLs.

**Reproduction:** Pass a malformed URL like `https://[invalid` to any
command that accepts Sentry URLs.

**Fix:** Add `log.debug("Failed to parse URL", input, error)` and remove
the `biome-ignore` comment.

## Testing

- All existing tests pass (resolve-team: 1 test, trace-target: 19 tests,
sentry-url-parser: 84 tests)
- Lint passes clean (`biome check` — 0 errors)

<div><a
href="https://cursor.com/agents/bc-259f34b1-c9e3-4d43-a65c-4138f0f6d5ca?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/automations/95624600-485e-4461-829e-6b76f086c473"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/view-automation-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/view-automation-light.png"><img
alt="View Automation" width="141" height="28"
src="https://cursor.com/assets/images/view-automation-dark.png"></picture></a>&nbsp;</div>

---------

Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: Miguel Betegón <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — 35f72f91 Deployed Nov 9, 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