Skip to content

response-content-disposition as a query param does not work because of spaces not escaped properly #7655

@cfactolerin

Description

@cfactolerin

Environment details

  • OS: Mac OS Catalina v10.15.3
  • Ruby version: ruby 2.6.5p114
  • Gem name and version: google-cloud-storage

Steps to reproduce

  1. Pass "response-content-disposition" => "attachment; filename=\"test 1.txt\"" as a query parameter with a file name that has space in between.
  2. You will get a SignatureDoesNotMatchThe request signature we calculated does not match the signature you provided error.

Code example

storage = Google::Cloud::Storage.new(project_id: 'xxx-project-id, credentials: 'credentials_path/config.json')
bucket = storage.bucket('my-bucket-name)
bucket.signed_url('filepath/filename.txt', version: :v4, expires: 3600, headers: nil, query: {"response-content-disposition"=>"attachment; filename=\"test 1.txt\""}, method: :GET)

Full backtrace

No back trace because it still provides you a signed url. It's just that when you use the url you will seem something like:

SignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.

The issue is that CGI.escape converts the spaces into '+' which is not the %XX UTF-8 style that you guys expected.
Your test cases pass because you guys used URI to parse the url. URI uses %20 for spaces.

I did a quick fork on the master branch to try out fixing it and it works. Do have a look and let me know if I should do a PR for it. cfactolerin@90cf55c

Thanks!

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.priority: p3Desirable enhancement or fix. May not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions