Magento2: REST API unable to make requests with slash (/) in SKU

Created on 20 Feb 2017  路  11Comments  路  Source: magento/magento2

Inside the REST API, it is impossible to access a resource that requires an SKU if the SKU contains a forward slash.

Preconditions

  1. Tested in CE 2.1.2 and CE 2.1.3. No indication of fix in 2.1.4 release notes

Steps to reproduce

  1. Fresh install
  2. Create product (of any type) with SKU containing /, e.g. "CLE-056621/6"
  3. Make REST request with encoded SKU (as Swagger does) e.g. "V1/products/CLE-056621%2F6", "/V1/products/CLE-056621%2F6/media"

Expected result

  1. Should be possible to make a request with encoded SKU, or by product ID

Actual result

  1. A request with a slash ("CLE-056621/6") returns "Not found" 404
  2. A request with encoded SKU ("CLE-056621%2F6") returns
    { "message": "Requested product doesn't exist" }
FrameworWebapi Fixed in 2.2.x Confirmed Format is valid Ready for Work Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x bug report

Most helpful comment

Working on this.

All 11 comments

Thanks for reporting - internal issue number is MAGETWO-60899.

It appears that this is an issue with Apache rather than Magento. You might have noticed that the 404 response codes are Apache generated instead of the usual Magento 404 pages. This is because, by default, forward slashes cannot be encoded in URLs without getting rejected. Add the option "AllowEncodedSlashes On" in either your global or virtual host config (or maybe in the Magento .htaccess, though this could be a security risk for users who would never make requests with encoded forward slashes).

This worked for me. Good luck.

@mplccp, thank you for your report.
We've created internal ticket(s) MAGETWO-60899 to track progress on the issue.

@AirmanAJK can you share your .htaccess or apache config? I'm trying to set AllowEncodedSlashes On, but this results in a 500 server error.

It seems to be resolved somehow or version 2.1.9 is not affected. I've been able to successfully create and update a product with slashes in the sku. Encode the slash using '%2f'

For the update I used the following example API call:

PUT: /rest/all/V1/products/article%2fwith%2fslash%2fin%2fsku
JSON: {
"product": {
"status": 1,
"type_id": "simple",
"name": "Test article is updated..."
}
}

Working on this.

Hi @mplccp
The issue has been fixed and delivered in 2.2-develop branch. Will be available with upcoming patch release.

Has their been progress on this as still getting this issue in 2.2.3

We are still experiencing this issue in 2.3.3.

@stephenbori @JaredAllen1
Are you using Apache? If yes - did you tried to to set following option in virtualhost?

AllowEncodedSlashes NoDecode

Ref: https://github.com/magento/magento2/issues/13343#issuecomment-362783825

Was this page helpful?
0 / 5 - 0 ratings