Skip to content

[WIP] - Fix HMAC verification failure when query params contain spaces#3102

Open
byrichardpowell wants to merge 1 commit intomainfrom
fix/issue-2701-hmac-space-encoding
Open

[WIP] - Fix HMAC verification failure when query params contain spaces#3102
byrichardpowell wants to merge 1 commit intomainfrom
fix/issue-2701-hmac-space-encoding

Conversation

@byrichardpowell
Copy link
Contributor

WHY are these changes introduced?

Fixes #2701

URLSearchParams.toString() encodes spaces as + (application/x-www-form-urlencoded format), but Shopify generates its HMAC signature using percent-encoding (%20). This mismatch caused api.utils.validateHmac() to return false for any valid OAuth request where a query parameter value contained a space.

WHAT is this pull request doing?

  • In ProcessedQuery.stringify(), replaces + with %20 after calling URLSearchParams.toString() so the canonical query string matches Shopify's signing format.
  • Updates existing test expectations from + to %20 in hardcoded expected query strings.
  • Adds a regression test: 'spaces in param values are percent-encoded (%20), not plus-encoded'.

Type of change

  • Patch: Bug (non-breaking change which fixes an issue)

Checklist

  • I have used pnpm changeset to create a draft changelog entry (do NOT update the CHANGELOG.md files manually)
  • I have added/updated tests for this change
  • I have documented new APIs/updated the documentation for modified APIs (for public APIs)

URLSearchParams.toString() encodes spaces as '+' (application/x-www-form-urlencoded)
but Shopify signs using percent-encoding ('%20'), causing validateHmac() to return
false for valid OAuth requests containing space-containing parameter values.

Fixes #2701

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@byrichardpowell
Copy link
Contributor Author

Marking as WIP as I need to test this

@byrichardpowell byrichardpowell changed the title Fix HMAC verification failure when query params contain spaces [WIP] - Fix HMAC verification failure when query params contain spaces Mar 13, 2026
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.

HMAC mismatch when query contains spaces — URLSearchParams encodes spaces differently than Shopify expects

1 participant