refactor(oauth): add Zod validation for OAuth responses by betegon · Pull Request #22 · getsentry/cli · GitHub
Skip to content

refactor(oauth): add Zod validation for OAuth responses#22

Merged
betegon merged 1 commit into
mainfrom
refactor/oauth-zod-validation
Jan 19, 2026
Merged

refactor(oauth): add Zod validation for OAuth responses#22
betegon merged 1 commit into
mainfrom
refactor/oauth-zod-validation

Conversation

@betegon

@betegon betegon commented Jan 19, 2026

Copy link
Copy Markdown
Member

Summary

Adds runtime validation for OAuth device flow responses using Zod schemas. Previously, responses were cast with as type assertions which could hide malformed data. Now validation errors are caught and reported with helpful messages.

Changes

  • Add Zod schemas for all OAuth response types (DeviceCodeResponse, TokenResponse, TokenErrorResponse)
  • Replace type assertions with safeParse for proper validation
  • Wrap validation failures in ApiError with clear error messages
  • Replace plain Error throws with proper error classes (ConfigError, ApiError, DeviceFlowError)
  • Add .passthrough() to schemas so extra API fields don't cause failures

Test plan

  • Run bun run typecheck - passes
  • Run bun test - existing tests pass (171 pass, failures are pre-existing config test issues)
  • Manual: sentry auth login still works with valid OAuth server responses

🤖 Generated with Claude Code

Replace unsafe type assertions with runtime Zod validation for OAuth
device flow responses. This ensures malformed responses from the OAuth
server are caught and reported with helpful error messages.

Changes:
- Add Zod schemas for DeviceCodeResponse, TokenResponse, TokenErrorResponse
- Use safeParse for discriminating success/error responses in pollForToken
- Wrap validation errors in ApiError for user-friendly messages
- Replace plain Error throws with ConfigError, ApiError, DeviceFlowError
- Add .passthrough() to schemas for API resilience
- Improve JSDoc with @returns and @throws documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@betegon betegon marked this pull request as ready for review January 19, 2026 19:42
@betegon betegon merged commit d224457 into main Jan 19, 2026
2 checks passed
@betegon betegon deleted the refactor/oauth-zod-validation branch January 19, 2026 19:42
BYK added a commit that referenced this pull request Jun 23, 2026
Fixes 5 open Dependabot alerts:

| Alert | Package | Severity | Fix |
|-------|---------|----------|-----|
| #10 | vite@8.0.13 (fs.deny bypass) | High | → 8.0.16 |
| #9 | vite@8.0.13 (NTLM hash leak) | Moderate | → 8.0.16 |
| #22 | form-data@4.0.5 (CRLF injection) | Moderate | → 4.0.6 |
| #14 | js-yaml@4.1.1 docs (DoS) | Moderate | → 4.2.0 |
| #13 | @babel/core@7.29.0 docs (arbitrary file read) | Low | → 7.29.6 |

**Accepted as tolerable risk:**
- Alert #21: js-yaml@3.14.2 in main lockfile — `gray-matter` pins
`^3.13.1` with no v3 patch backport; dev-only transitive dep used at
build time

All patches applied via `pnpm.overrides` in respective `package.json`
files. `check:deps` ✓, `lint` ✓, `typecheck` has a pre-existing
unrelated error in `src/commands/api.ts`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant