README's Laravel/Symfony request examples pass header value arrays; verifyAppHomeReq and verifyWebhookReq throw TypeError

未关闭
#31 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
php

调研方向

Read Headers::normalize() and the verifier paths in src/Internal/Verify/AppHomeReq.php and src/Internal/Verify/BodyHmacInHeader.php; compare their expected header values with the arrays returned by Laravel and Symfony. Check how AdminUIExt, PosUIExt, and NonExchangeableIdToken use Authorization headers. Reproduce both reported TypeErrors, then verify that array-valued headers are handled and scalar headers still produce the expected results.

由索引模型根据 Issue 内容生成。

描述

devtools-gardener

The "Converting a request" section of the README shows Laravel and Symfony examples that build the request array with $request->headers->all(). Symfony's HeaderBag::all() (which Laravel's request uses too) returns ['name' => ['value', …]], one list of values per header. Headers::normalize() only lowercases the keys, so the verifiers receive arrays where they expect strings:

  • verifyAppHomeReq with an Authorization: Bearer … header (every App Bridge fetch()) throws TypeError: strpos(): Argument #1 ($haystack) must be of type string, array given at src/Internal/Verify/AppHomeReq.php:182.
  • verifyWebhookReq with a correctly signed webhook throws TypeError: hash_equals(): Argument #2 ($user_string) must be of type string, array given in src/Internal/Verify/BodyHmacInHeader.php.

The initial page request works because its ID token is in the query string, so an app that follows the README sees this on its first API call or its first webhook. AdminUIExt, PosUIExt and NonExchangeableIdToken read the Authorization header the same way.

Reproduction with the package alone, v1.0.2 on PHP 8.5 (the same code is on main as of 9 Oct 2026):

$app = new Shopify\App\ShopifyApp(
    clientId: 'test-client-id',
    clientSecret: 'test-client-secret-at-least-32-bytes-long',
);

$app->verifyAppHomeReq([
    'method' => 'GET',
    'headers' => ['authorization' => ['Bearer x.y.z']],
    'url' => 'https://example.test/api/shop',
    'body' => '',
], appHomePatchIdTokenPath: '/auth/patch-id-token');
// TypeError: strpos(): Argument #1 ($haystack) must be of type string, array given

$body = '{"domain":"test-shop.myshopify.com"}';
$hmac = base64_encode(hash_hmac('sha256', $body, 'test-client-secret-at-least-32-bytes-long', true));
$app->verifyWebhookReq([
    'method' => 'POST',
    'headers' => ['x-shopify-hmac-sha256' => [$hmac], 'x-shopify-shop-domain' => ['test-shop.myshopify.com']],
    'url' => 'https://example.test/api/webhooks',
    'body' => $body,
]);
// TypeError: hash_equals(): Argument #2 ($user_string) must be of type string, array given

With string values both calls behave normally (invalid_id_token for the fake token, verified for the webhook).

Two possible fixes: change the README examples to join the values, e.g. array_map(fn ($v) => implode(', ', $v), $request->headers->all()); or have Headers::normalize() accept arrays and join them, which would also cover other frameworks that return value lists. Happy to open a PR for either.

主要语言
PHP
星标
62
派生
5
平均合并
4 小时 39 分钟
30 天内合并 PR
1

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Shopify/shopify-app-php 的其他 Issue

查看 Shopify/shopify-app-php 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。