Skip to content

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

@mohammadbharmal

Description

@mohammadbharmal

Preconditions and environment

  • Magento 2.4.6-p1

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

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

Labels

Issue: needs updateAdditional information is require, waiting for responseReported on 2.4.6-p1Indicates original Magento version for the Issue report.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions