In the S3 client library, the code uses the Drupal url() function for generating the URL to call S3 with. While this is the correct way to do it in Drupal, it introduces some unwanted effects.

The url-function calls drupal_alter('url_outbound', ...);, and that opens up for the possibility to rewrite the URL that the client library uses.

We have implemented the hook_url_outbound_alter function in our custom module. The responsibility for that function is to rewrite urls that end up on the frontend, so that we never expose a S3 url. This, however, also means that URLs in the S3 client library gets rewritten, and this breaks the client library.
There is no way of detecting whether or not to rewrite the url in our alter-hook, as far as i can see.

Basically, it does not make sense to make URLs in client libraries open for alters. I propose that storage_api does not use the url-function, but instead adds the query-parameters itself.

If the possibility for altering the URL should be maintained, one could add a new alter-hook that can be used. I can add this if requested.

Comments

mian3010’s picture

Added patch with proposed solution

mian3010’s picture

Status: Active » Needs review
perignon’s picture

Good catch and I agree with your logic. Nothing should be able to alter the URLs for S3 functions or it could break web service calls to those URLs. I need to check the Cloudfront functions for the same thing.