Skip to content

Commit 62272a2

Browse files
authored
Merge pull request #9573 from adobe-commerce-tier-4/ACP2E-3643-1
2 parents 276e0ac + 10832bf commit 62272a2

File tree

4 files changed

+77
-12
lines changed

4 files changed

+77
-12
lines changed

dev/tests/api-functional/framework/Magento/TestFramework/Authentication/Rest/OauthClient/Signature.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\TestFramework\Authentication\Rest\OauthClient;
@@ -42,13 +42,8 @@ function ($carry, $item) {
4242
[]
4343
);
4444

45-
$signatureData = [];
46-
foreach (array_merge($queryStringData, $params) as $key => $value) {
47-
$signatureData[rawurldecode($key)] = rawurlencode($value);
48-
}
49-
5045
return $this->helper->sign(
51-
$signatureData,
46+
array_merge($queryStringData, $params),
5247
$this->algorithm,
5348
$this->credentials->getConsumerSecret(),
5449
$this->tokenSecret,
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Api;
9+
10+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
11+
use Magento\TestFramework\Fixture\DataFixture;
12+
use Magento\TestFramework\TestCase\WebapiAbstract;
13+
14+
class ProductSkuTest extends WebapiAbstract
15+
{
16+
private const RESOURCE_PATH = '/V1/products/';
17+
18+
/**
19+
* @return void
20+
*/
21+
#[
22+
DataFixture(ProductFixture::class, [
23+
'sku' => 'SKU:@&=$\,;1234',
24+
'name' => 'Test product 1'
25+
])
26+
]
27+
public function testGetProductDetailsWithSpecialCharsSKUAndQueryParams(): void
28+
{
29+
$this->_markTestAsRestOnly();
30+
31+
$sku = 'SKU:@&=$\,;1234';
32+
$requestData = [
33+
'assetId' => 'urn:aaid:aeme47fc635-c87e-4a7e-8eb1-f74b4b77866c' . $sku
34+
];
35+
$serviceInfo = [
36+
'rest' => [
37+
'resourcePath' => self::RESOURCE_PATH . $sku . '?' . http_build_query($requestData),
38+
'httpMethod' => 'GET',
39+
],
40+
];
41+
$response = $this->_webApiCall($serviceInfo);
42+
self::assertArrayHasKey('id', $response);
43+
self::assertArrayHasKey('sku', $response);
44+
self::assertEquals($sku, $response['sku']);
45+
}
46+
}

lib/internal/Magento/Framework/Oauth/Helper/Uri/Http.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected static function normalizePath($path): string
1919
return self::encodePath(
2020
self::decodeUrlEncodedChars(
2121
self::removePathDotSegments($path),
22-
'/[' . self::CHAR_UNRESERVED . ':@&=\+\$,;%]/'
22+
'/[' . self::CHAR_UNRESERVED . ']/'
2323
)
2424
);
2525
}

lib/internal/Magento/Framework/Oauth/Oauth.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2013 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Framework\Oauth;
@@ -189,7 +189,7 @@ protected function _validateSignature($params, $consumerSecret, $httpMethod, $re
189189
}
190190

191191
$calculatedSign = $this->httpUtility->sign(
192-
$params,
192+
$this->processNonRequiredParams($params),
193193
$params['oauth_signature_method'],
194194
$consumerSecret,
195195
$tokenSecret,
@@ -202,6 +202,30 @@ protected function _validateSignature($params, $consumerSecret, $httpMethod, $re
202202
}
203203
}
204204

205+
/**
206+
* Avoid double encoding for query param values
207+
*
208+
* @param array $params
209+
* @return array
210+
*/
211+
private function processNonRequiredParams(array $params): array
212+
{
213+
$requiredParams = [
214+
"oauth_consumer_key",
215+
"oauth_consumer_secret",
216+
"oauth_token",
217+
"oauth_token_secret",
218+
"oauth_signature"
219+
];
220+
foreach ($params as $key => $value) {
221+
if (!in_array($key, $requiredParams)) {
222+
$params[$key] = urldecode($value);
223+
}
224+
}
225+
226+
return $params;
227+
}
228+
205229
/**
206230
* Validate oauth version.
207231
*

0 commit comments

Comments
 (0)