Skip to content

Remove jose from cli-kit (inline guarded JWT decode)#7730

Draft
amcaplan wants to merge 1 commit into
mainfrom
remove-dep/jose
Draft

Remove jose from cli-kit (inline guarded JWT decode)#7730
amcaplan wants to merge 1 commit into
mainfrom
remove-dep/jose

Conversation

@amcaplan
Copy link
Copy Markdown
Contributor

@amcaplan amcaplan commented Jun 5, 2026

Remove jose from @shopify/cli-kit

Why: Part of an initiative to cut low-value dependency churn (13 Dependabot bumps / 24 months). Notably, this code path only ever decoded an id_token payload — it never verified signatures, so the full jose library was overkill.

Replacement: A guarded inline base64url JWT-payload decoder.

  • Sole site: packages/cli-kit/src/private/node/session/exchange.tsjose.decodeJwt(result.id_token).subgetJwtSubject(idToken).
  • Guards (security-relevant): requires exactly 3 JWT segments; decodes the payload with Buffer.from(payload, 'base64url') (engines.node ≥ 22.12); JSON.parse wrapped in try/catch; rejects non-object / array / empty-object payloads before reading .sub (avoids the String.prototype.sub hazard a string payload would trigger).
  • Returns string | undefined; the existing caller's if (!userId) throw new BugError(...) already handles a missing subject — safer than the prior .sub! non-null assertion.

Tests: The decode path was previously untested. Added coverage in exchange.test.ts for exchangeDeviceCodeForAccessToken without an existingUserId (the path that triggers the decode) plus malformed-token guard cases.

Validation: type-check ✅, lint ✅, vitest ✅ (1 file, 19 tests, 0 failed).

🤖 AI-generated draft — needs human review before merge.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the Area: @shopify/cli @shopify/cli package issues label Jun 5, 2026
@amcaplan amcaplan added the dependency-removal Removes a dependency to cut Dependabot churn (cleanup initiative) label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: @shopify/cli @shopify/cli package issues dependency-removal Removes a dependency to cut Dependabot churn (cleanup initiative)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant