-
Notifications
You must be signed in to change notification settings - Fork 553
Try to fix access to S3 object that has question mark in the object name #1155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -14,7 +14,7 @@ defmodule ExAws.Request.Url do | |||
|> convert_port_to_integer | |||
|> (&struct(URI, &1)).() | |||
|> URI.to_string() | |||
|> String.trim_trailing("?") | |||
|> String.replace_suffix("?", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to support text.txt?
object, since if the object name ends with the question mark, the URI.to_string
will add another question mark and the String.trim_trailing/2
will remove both.
config = %{ | ||
http_client: ExAws.Request.HttpMock, | ||
json_codec: JSX, | ||
access_key_id: "AKIAIOSFODNN7EXAMPLE", | ||
secret_access_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", | ||
region: "us-east-1", | ||
retries: [ | ||
max_attempts: 5, | ||
base_backoff_in_ms: 1, | ||
max_backoff_in_ms: 20 | ||
], | ||
normalize_path: false, | ||
scheme: "https://", | ||
host: "s3.amazonaws.com", | ||
virtual_host: true, | ||
port: 443 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was put together just to check if the test is valid. This should be improved and moved to a separate test.
Hi @speeddragon! Thanks for taking a look at this. I'm not across the docs enough to know what the "correct" behaviour for cases like this is. In terms of whether you should continue work on it, the two relevant questions are: 1) What existing stuff (if any) will it break, and 2) What do the official (boto) libraries do in the same case? |
Thanks for replying @bernardd. To answer to your questions:
|
During a cleanup of my files (stored in DigitalOcean Spaces, equivalent to S3), I've noticed some issues accessing files with question marks (?) in the object name. E.g.:
test.jpg?id=3
andtest.jpg?
.I'm not sure if the best solution here would be avoiding storing files with special characters, like mentioned on AWS documentation, but also found similar issues in the past, like #660 so I wanted to come up a solution for this case, but I think there would still be some other edge cases to explore regarding this.
To solve this, under the
perform/2
function inExAws.Operation.S3
, I've encoded the object path.To avoid the double encoding, I needed to remove
Url.uri_encode/1
under:ExAws.Auth.signature/8
ExAws.Request.Url.query/1
I'm not familiar with other AWS services and how they handle the query params, but I believe I also would need to add
uri_encode/1
to the otherExAws.Operation
modules (JSON
,Query
,RestQuery
).Probably exist some other valid cases to not encode every query parameter, I believe(This is fixed in the second commit)versionId
would be one of them, but I think there should be more.I'm also not sure if DigitalOcean Spaces mimics 100% the same S3 behaviour.
I would like some guidance on whether I should invest more time in this or drop it. Maybe we shouldn't support this kind of functionality due to the complexity versus the benefits.