Shopify / Shopify/shopify-api-php

`Utils::validateHmac` fails if the query params contains non url-safe characters.

Open
#412 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
473
Forks
193
Avg merge
5h 8m
Merged PRs (30d)
1

Description

Issue summary

Utils::validateHmac fails if the query params contains non url-safe characters. For example, for a oauth authorization callback, if the state is a base64-encoded string, the trailing = character will make the HMAC validation fail. After talking with the Shopify support, I was told that the HMAC sent from Shopify is computed based on the original query params, instead of the URL-encoded version.

Expected behavior

HMAC validation should still work if the HMAC comes for a URL containing encoded characters

Actual behavior

Utils::validateHmac returns false, even if I can manually confirm that the HMAC is correct

Steps to reproduce the problem

  1. Initiate an OAuth autorization request. For the state, use non url-safe characters (i.e. JSON, Base64, or colons :). In my case, I use an app I'm developping, and requesting access for that app to a test shop.
  2. When the autorization request is accepted, the user is redirected to your redirect_uri with the resulting query parameters. Save those for next step
  3. use Utils::validateHmac to validate the callback. It will fail if the state indeed contains encoded characters.

Reduced test case

The best way to get your bug fixed is to provide a reduced test case.


Checklist

  • I have described this issue in a way that is actionable (if possible)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Utils::validateHmac and reproduce the OAuth callback with a state containing encoded characters such as Base64 or JSON. Trace how the callback query parameters are handled before HMAC validation; done means validation returns true for a correctly signed URL containing those characters.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
authentication, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.