magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

Magento 2 REST API Issue: Unable to Handle Product SKU with Slash Value in stockItems Endpoint #37830

Closed mohammadbharmal closed 1 year ago

mohammadbharmal commented 1 year ago

Preconditions and environment

Magento 2 REST API Endpoint /V1/stockItems/:productSku is encountering a bug specifically when using OAuth 1.0 authentication. The issue arises when the product SKU contains special characters such as slashes (/) or ampersands (&). This results in an incorrect OAuth signature being generated, leading to errors in the authentication process.

The error is being triggered from the class Magento\Framework\Oauth\Oauth::_validateSignature() at line number 207. The root cause of the problem lies in the signature generation process, which is performed by the Laminas library. The library generates different signatures for SKUs containing slashes or ampersands, causing inconsistencies in the authentication flow.

Example: Working URL: https://test.com/test-sku Not Working URL: https://test.com/test-sku%2F123

The correct OAuth signature generation for the product SKU is not taking into account the special characters, leading to an incorrect signature that fails the authentication process.

To fix this issue, adjustments need to be made in the OAuth signature generation logic, ensuring that it properly handles SKUs with special characters and produces consistent signatures for all SKU variations.

Please see below screenshot for more reference.

image image

Steps to reproduce

  1. Login to Magento admin.
  2. Navigate to System > Extensions > Integrations > Add New Integration.
  3. Activate Added Integration from the Integration grid with all rights.
  4. Go to the Catalog > Product.
  5. Add or edit product.
  6. Keep sku name "demo-test/1234" or demo-test&1234
  7. Save product.
  8. Go to Postman
  9. Set Get Request with endpoint rest/V1/stockItems ex:- https://your-domain/index.php/rest/V1/stockItems/demo-test%2F1234
  10. Set Oauth 1.0
  11. Set Add authorization data to Request Headers.
  12. Set Integration details in the OAuth request like consumer key, Access Token etc etc.
  13. Send request

Expected result

Should be return stock data of the sku

Actual result

returning error "The signature is invalid. Verify and try again."

Additional information

I have tested this with an postman

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @mohammadbharmal. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

mohammadbharmal commented 1 year ago

@magento I am working on this

m2-assistant[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

mohammadbharmal commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @mohammadbharmal. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @mohammadbharmal, here is your Magento Instance: https://94a8c4219b018f25698d274a8f585b17.instances-prod.magento-community.engineering Admin access: https://94a8c4219b018f25698d274a8f585b17.instances-prod.magento-community.engineering/admin_8055 Login: addfe0f6 Password: 1faf6919087a

mohammadbharmal commented 1 year ago

I have generated tried to generate same case on the develop instance.

it's returning normal sku data, but not working with slash or ampersands.

Issue has been generated.

SKU :- this-teste&787

URL:- https://94a8c4219b018f25698d274a8f585b17.instances-prod.magento-community.engineering/rest/V1/stockItems/this-teste%26787

image

mohammadbharmal commented 1 year ago

@engcom-Bravo , have you checked this issue ?

engcom-Bravo commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo, here is your Magento Instance: https://94a8c4219b018f25698d274a8f585b17.instances-prod.magento-community.engineering Admin access: https://94a8c4219b018f25698d274a8f585b17.instances-prod.magento-community.engineering/admin_1109 Login: b7747885 Password: b49592fe9349

engcom-Bravo commented 1 year ago

Hi @mohammadbharmal,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop instance and the issue is not reproducible.Kindly refer the screenshots.

Steps to reproduce

We are getting stock data for the SKU.

Screenshot 2023-08-07 at 5 51 05 PM Screenshot 2023-08-07 at 5 50 58 PM

If Apache you also need to make sure you set AllowEncodedSlashes NoDecode as per this https://httpd.apache.org/docs/2.4/mod/core.html#allowencodedslashes.

Screenshot 2023-08-07 at 5 53 36 PM

Kindly recheck the behaviour on Magento 2.4-develop instance and elaborate steps to reproduce if the issue is still reproducible.

Thanks.

mohammadbharmal commented 1 year ago

@engcom-Bravo , Thank you for the update,

How we can configure AllowEncodedSlashes NoDecode for the nginx ?

engcom-Bravo commented 1 year ago

Hi @mohammadbharmal,

Thanks for your update.

Could you please refer this document http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass and let us know if you are still facing any issue.

Thanks.

mohammadbharmal commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @mohammadbharmal. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @mohammadbharmal, here is your Magento Instance: https://94a8c4219b018f25698d274a8f585b17.instances-prod.magento-community.engineering Admin access: https://94a8c4219b018f25698d274a8f585b17.instances-prod.magento-community.engineering/admin_7b23 Login: 59ba5dcf Password: 39094367113a

engcom-Bravo commented 1 year ago

Hi @mohammadbharmal,

We have noticed that this issue has not been updated since long time.
Hence we assume that this issue is fixed now, so we are closing it. Please feel to raise a fresh ticket or reopen this ticket if you need more assistance on this.

Thanks.

mohammadbharmal commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @mohammadbharmal. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @mohammadbharmal, here is your Magento Instance: https://94a8c4219b018f25698d274a8f585b17.instances-prod.magento-community.engineering Admin access: https://94a8c4219b018f25698d274a8f585b17.instances-prod.magento-community.engineering/admin_18d1 Login: 894e6e2c Password: 9037c2c6c5a0

mohammadbharmal commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @mohammadbharmal. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @mohammadbharmal, here is your Magento Instance: https://94a8c4219b018f25698d274a8f585b17.instances-prod.magento-community.engineering Admin access: https://94a8c4219b018f25698d274a8f585b17.instances-prod.magento-community.engineering/admin_cabf Login: b63918ef Password: f5bb3e031b17

mohammadbharmal commented 1 year ago

admin is not correct

mohammadbharmal commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @mohammadbharmal. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @mohammadbharmal, here is your Magento Instance: https://94a8c4219b018f25698d274a8f585b17.instances-prod.magento-community.engineering Admin access: https://94a8c4219b018f25698d274a8f585b17.instances-prod.magento-community.engineering/admin_63a7 Login: e951a36c Password: 7ae5452c82d6

jorgb90 commented 2 months ago

Indeed still not fixed.. https://github.com/magento/magento2/issues/37278