Skip to content

Storage: Make HTTP-Method in signed url in upper case (and validate) #6107

Closed
@StefMa

Description

@StefMa
  1. Specify the API at the beginning of the title (for example, "BigQuery: ...")
    General, Core, and Other are also allowed as types
  2. OS type and version
    I use the Storage lib inside a Cloud Function (Python Beta runntime)
  3. Python version and virtual environment information python --version
    3.7
  4. google-cloud-python version pip show google-cloud, pip show google-<service> or pip freeze
    1.12.0
  5. Stacktrace if available
  6. Steps to reproduce
  7. Code example
    👇

Hey guys 👋
currently I experiment a little bit with the Cloud Storage library inside a Cloud Function.
For testing I want to make an already uploaded file available via Blob#generate_signed_url.
The thing is - it works. I have no issues.
But Yesterday I spend at least 6 hours for testing it because the method in the generated_signed_url needs to be in uppercase.
Meaning the following does not work:

blob.generate_signed_url(timedelta(minutes=5), "get")

but this works:

blob.generate_signed_url(timedelta(minutes=5), "GET")

After a quick look into your code I found out that you "just put" the string into the generated URL. Without validating if that is a valid HTTP-Method!
https://github.com/GoogleCloudPlatform/google-cloud-python/blob/81bc5ef11d1918580f41e9f8ee2c9be2529b1169/storage/google/cloud/storage/_signing.py#L189

I would recommend (or request with this issue 🙃 ) to either:

  • Check if the given string is a valid HTTP-Method (POST, GET, PUT etc.) and make the string to uppercase!
  • Or better (but leads to breaking changes (maybe 😃)) make an ENUM of it and only allow to put an enum-value into the method.

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.priority: p2Moderately-important priority. 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