Cannot include localhost in cloudfront CORS policy

0

Hi all,

I want to include a CORS policy in Cloudfront, but the UI will not allow me to add https://localhost. I get the following error: "The parameter Access-Control-Allow-Origin contains https://localhost which is not a valid URL."

I can set this in other CORS policies (such as S3) so think this should be allowed.

Does anyone know if this is considered a bug? Is there a workaround?

Many thanks

Azbola
已提問 2 年前檢視次數 4598 次
1 個回答
0

Hi there,

Thank you for reporting this behavior when attempting to add "https://localhost" to the "Access-Control-Allow-Origin" section of a Response Header Policy. I have communicated this behavior to the CloudFront service team and they are investigating it further.

There are a few possible workarounds. If you can customize the response from your origin, you can configure CloudFront to forward the "Origin" header in the origin request and have your origin return this header in its response with the desired "https://localhost" value. As noted, S3 can be configured to return this value in its CORS configuration if you're using S3 as your origin.

Another approach is utilizing CloudFront Functions to add the "Access-Control-Allow-Origin: https://localhost" header to the response. An example function that can be adapted to accomplish this can be found here: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/example-function-add-cors-header-response.html

支援工程師
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南