Skip to content

Commit 389efca

Browse files
authored
Merge pull request #71 from silverDuy/validate-for-webhook-get-request
`WebhookAuthenticator::authenticateGetRequest` now also consider `location-id` and `privileges`
2 parents 6bb9024 + 7eb70d2 commit 389efca

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
99
- Added EndPointTrait for supporting to remove the unnecessary last slashes of an endpoint
1010
- Updated `AdminAuthenticator` and `Context` to remove the unnecessary last slashes of the provided endpoint
1111
- [Fix Call to a member function getSource() on null](https://github.com/vienthuong/shopware-php-sdk/issues/65)
12+
- `WebhookAuthenticator::authenticateGetRequest` now also consider `location-id` and `privileges`
13+
- [Fix GET Requests of Webhook are not validated correctly](https://github.com/vienthuong/shopware-php-sdk/issues/61)
1214

1315
### 1.7.3
1416
- [Fix Schema caching](https://github.com/vienthuong/shopware-php-sdk/pull/62)

src/Service/WebhookAuthenticator.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,32 @@ public static function authenticateGetRequest(string $shopSecret): bool
5959

6060
$shop = new Shop($queries['shop-id'], $queries['shop-url'], $shopSecret);
6161

62-
$queryString = sprintf(
63-
'shop-id=%s&shop-url=%s&timestamp=%s&sw-version=%s',
64-
$shop->getShopId(),
65-
$shop->getShopUrl(),
66-
$queries['timestamp'] ?? null,
67-
$queries['sw-version'] ?? null,
68-
);
69-
70-
if (array_key_exists('sw-context-language', $queries) && array_key_exists('sw-context-language', $queries)) {
71-
$queryString = sprintf(
72-
'shop-id=%s&shop-url=%s&timestamp=%s&sw-version=%s&sw-context-language=%s&sw-user-language=%s',
73-
$shop->getShopId(),
74-
$shop->getShopUrl(),
75-
$queries['timestamp'],
76-
$queries['sw-version'],
77-
$queries['sw-context-language'],
78-
$queries['sw-user-language'],
79-
);
62+
$queryParams = [
63+
'shop-id' => $shop->getShopId(),
64+
'shop-url' => $shop->getShopUrl(),
65+
'timestamp' => $queries['timestamp'],
66+
'sw-version' => $queries['sw-version'],
67+
];
68+
69+
if (array_key_exists('sw-context-language', $queries)) {
70+
$queryParams['sw-context-language'] = $queries['sw-context-language'];
8071
}
8172

73+
if (array_key_exists('sw-user-language', $queries)) {
74+
$queryParams['sw-user-language'] = $queries['sw-user-language'];
75+
}
76+
77+
if (array_key_exists('location-id', $queries)) {
78+
$queryParams['location-id'] = $queries['location-id'];
79+
}
80+
81+
if (array_key_exists('privileges', $queries)) {
82+
$queryParams['privileges'] = urlencode($queries['privileges']);
83+
}
84+
85+
$queryString = http_build_query($queryParams);
86+
87+
8288
$hmac = \hash_hmac('sha256', htmlspecialchars_decode($queryString), $shopSecret);
8389

8490
return hash_equals($hmac, $queries['shopware-shop-signature']);

0 commit comments

Comments
 (0)