dvonlehman / s3-proxy

4front plugin to proxy read calls to S3
50 stars 29 forks source link

Fix for "s3 key with url like `/?foo=bar` with query on `/` path, leads to error when reading .createReadStream()" #23

Open jplwood opened 3 years ago

jplwood commented 3 years ago

If I have a defaultKey such as index.html, and I request a / route with a query string, e.g., /?foo=bar. If i do this, that first if statement thats supposed to replace "" with defaultKey, s3Key will be ?foo=bar and my defaultKey will not be used. The code continues and removes the query string from the s3Key making it s3Key = "". If my s3Key is passed to the s3Params as a blank string, which is passed to s3Request and finally when we call s3Request.createReadStream(), a 500 error is thrown by aws param_validator: UriParameterError: Expected uri parameter to have length >= 1, but found "" for params.Key. \n\n this fix removes the query string first since there is really nouse for it, to have the if that replaces "/" with defaultKey will work even if there is a query string.

jplwood commented 3 years ago

This is a fix for the issue I opened https://github.com/dvonlehman/s3-proxy/issues/22