You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot Set CORS Headers Due to Improper Handling of requestOptions['headers'] #426
There is currently no way to set actual CORS headers (e.g., Access-Control-Allow-Origin) on objects, at least, using the SDK, due to two compounding issues in how headers are handled.
Problem
Metadata-based headers are prefixed
Using the metadata option when creating or updating objects results in all custom headers being prefixed, e.g.:
X-Object-Meta-Access-Control-Allow-Origin: *
This prevents these headers from functioning as proper CORS headers, which must be actual HTTP response headers (e.g., Access-Control-Allow-Origin).
requestOptions['headers'] are ignored
When attempting to pass headers via requestOptions, they are silently ignored due to this code pattern:
$options += $userValues['requestOptions'];
Since $options['headers'] is already set (even as an empty array) in the sendRequest method of the OperatorTrait, PHP's array union operator (+) causes user-supplied headers to be discarded — because the key already exists.
Suggested Fix
A minimal and backward-compatible fix we applied in our fork is the following:
thank you for the issue. I just fixed the headers key so it would be merged with options. It might make sense to replace += with some deep merge function, but I guess it should be good as is.
Activity
k0ka commentedon May 30, 2025
Hello,
thank you for the issue. I just fixed the
headerskey so it would be merged with options. It might make sense to replace+=with some deep merge function, but I guess it should be good as is.Released in https://github.com/php-opencloud/openstack/releases/tag/v3.14.0
pedrodotvu commentedon May 30, 2025
Hi k0ka,
Thank you for the very quick turnover :) really appreciate it!
Best regards,
Pedro