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

Đang mở
#31 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
backend-api-design

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
PHP
Star
62
Fork
5
Merge trung bình
4 giờ 39 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Shopify/shopify-app-php

Tất cả issue của Shopify/shopify-app-php

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.