Skip to content

fix: validate refresh token exchange response at runtime - #26

Merged
marcusolsson merged 1 commit into
mainfrom
fix/issue-12-unchecked-type-assertion-refresh
May 21, 2026
Merged

fix: validate refresh token exchange response at runtime#26
marcusolsson merged 1 commit into
mainfrom
fix/issue-12-unchecked-type-assertion-refresh

Conversation

@marcusolsson

Copy link
Copy Markdown
Contributor

Issue 12 from TODO.md

The refreshAccessTokenInternal function used an unchecked TypeScript as cast after parsing the refresh response. If the Berget /v1/auth/refresh endpoint (or a proxy) returns a 200 OK with a malformed body, the plugin stores undefined as the new access token and overwrites the previously valid token in OpenCode's persistent storage.

Changes

  • Replaces the as cast with explicit typeof runtime validation for token and expires_in.
  • Returns {success: false, reason: 'Invalid token response from refresh endpoint'} on malformed bodies.
  • Uses typeof data.refresh_token === 'string' to safely extract rotated refresh tokens.
  • Adds 3 regression tests for missing token, wrong expires_in type, and proxy-wrapped error body.

Refs: TODO.md Issue 3 (same pattern) / Issue 12

@marcusolsson
marcusolsson merged commit 03e8783 into main May 21, 2026
@marcusolsson
marcusolsson deleted the fix/issue-12-unchecked-type-assertion-refresh branch May 21, 2026 09:49
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