Skip to content

Should ObjectIdentifier take care of replacing Key s with special chars #1876

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

Closed
pscheit opened this issue Apr 9, 2025 · 2 comments
Closed

Comments

@pscheit
Copy link

pscheit commented Apr 9, 2025

the DocBlock of ObjectIdentifier says:

    /**
     * Key name of the object.
     *
     * ! Replacement must be made for object keys containing special characters (such as carriage returns) when using XML
     * ! requests. For more information, see XML related object key constraints [^1].
     *
     * [^1]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints
     *
     * @var string
     */
    private $key;

So sounds to me the plan was to let the user adjust this?

So instead of

new ObjectIdentifier(['Key' => 'dev-&.zip']),

the user needs to:

new ObjectIdentifier(['Key' => htmlentities('dev-&.zip')]),

Was this the idea?

I think This is a bit confusing, because other libraries might easily skip this docblock and fall into the trap.

E.g.:
https://github.com/thephpleague/flysystem/blob/3.x/src/AsyncAwsS3/AsyncAwsS3Adapter.php#L191

As far as I understood the issue here at least & needs be converted into xml entities?

So just wondering if we fix it here or in the AsyncAwsS3Adapter.

Thank you!

@jderusse
Copy link
Member

jderusse commented Apr 9, 2025

This doc bloc is generated by AWS. You have the same sentence in all SDK.

For example javascript: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-s3/Interface/ObjectIdentifier/

From the official documentation, https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-guidelines AWS recommends not using special chars, in case some applications tries to re-use the object's identifier.

You can use any UTF-8 character in an object key name. However, using certain characters in key names can cause problems with some applications and protocols

So, from AsyncAws point of view, it's perfectly fine to not encode. But it might broke other applications.

My personal take is: If it brake another application, then it's a bug in that application that does not deal with special characters.

@pscheit
Copy link
Author

pscheit commented Apr 9, 2025

Gotya, thank you!

@pscheit pscheit closed this as completed Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants