🚨 Error: [AMP cache] access-control-allow-origin CORS errors
Details: Images/SVGs are allowing access to only one website and not other if its used in other domain. In our case https://visualstories.com is a tool to create web stories in users own domain. Tool allows user to use Images and SVGs for free. https://pets-visualstories-com.cdn.ampproject.org/v/s/pets.visualstories.com/reasons-why-cats-are-better-than-dogs?amp_js_v=0.1#origin=https%3A%2F%2Fvisualstories.com&viewerUrl=https%3A%2F%2Fvisualstories.com%2F&cap=navigateTo%2Cswipe See the attached story URL this will throw CORS errors now hit https://media-visualstories-com.cdn.ampproject.org/i/s/media.visualstories.com/uploads/svges/9304945.svg this SVG URL in new tab of the browser when you are hitting open the network tab from developer tool to see request/response headers, You'll see access-control-allow-origin is allowing to only one website it means when an another website is accessing the same SVG this will throw CORS error to that web story. Currently I'm facing this error when I see same SVGs used in different domains. This may affect on rankings.
Frequency: Daily
Reporting this issue from @visualstories to improve AMP technology.
@newmuis @gmajoulet Can you please look into this. The bug is causing us issues when using Google AMP cache in our feeds like
- https://visualstories.com/?app=pwa
- https://visualstories.com/feed/quizgame
- https://visualstories.com/feed/showcase
Can you try adding a crossorigin attribute on your images/svgs? I think that should fix it.
cf: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-crossorigin
@gmajoulet Ok we we will add crossorigin attribute and let you know if it works.
@gmajoulet
We already added access-control-allow-origin: * and I verified again.
PFA screenshots and see this is original path and
this is AMP cache URL where
access-control-allow-origin: https://pets-visualstories-com.cdn.ampproject.org This may get update if a person see a story from different website where this this SVG is used.
We used same SVG for image masking in various websites.
See below stories from original path all works as expected. images are visible in both stories. https://pets.visualstories.com/reasons-why-cats-are-better-than-dogs#page=page8 8th slide
https://travel.visualstories.com/most-beautiful-medieval-towns-that-still-exist#page=page6 6th slide
See same stories from AMP cache you'll see image in either first or second story. https://pets-visualstories-com.cdn.ampproject.org/v/s/pets.visualstories.com/reasons-why-cats-are-better-than-dogs?amp_js_v=0.1#origin=https://visualstories.com&viewerUrl=https://visualstories.com/&cap=navigateTo,swipe&page=page8 8th slide
https://travel-visualstories-com.cdn.ampproject.org/v/s/travel.visualstories.com/most-beautiful-medieval-towns-that-still-exist?amp_js_v=0.1#origin=https%3A%2F%2Fvisualstories.com&viewerUrl=https%3A%2F%2Fvisualstories.com%2F&cap=navigateTo%2Cswipe&page=page6 6th slide
This is happening in our hundreds of web stories. To check see https://visualstories.com/?app=pwa
@gmajoulet Hi please help me with this issue.
The response headers are great but the request headers are not. Please try adding a crossorigin parameter to your svg/img, that will fix it.
Repeating the link from above if you want to learn more about how this works: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-crossorigin
@gmajoulet Hi Gabriel,
There is one SVG being used by 2 stories:
- Original story 1: https://pets.visualstories.com/reasons-why-cats-are-better-than-dogs
- Original story 2: https://travel.visualstories.com/most-beautiful-medieval-towns-that-still-exist
- Original SVG: https://media.visualstories.com/uploads/svges/9304945.svg
- original SVG has access-control-allow-origin: *
While it works fine on original story URLs, AMP cache version of the stories are facing this problem:
In the AMP cache, one story is getting access to the SVG but other is not.
- AMP cache story 1 URL: pets-visualstories-com.cdn.ampproject.org
- AMP cache story 2 URL: travel-visualstories-com.cdn.ampproject.org
- AMP cache SVG URL: https://media-visualstories-com.cdn.ampproject.org/i/s/media.visualstories.com/uploads/svges/9304945.svg
- access-control-allow-origin: https://pets-visualstories-com.cdn.ampproject.org
Notice how AMP cache version of the SVG is restricting access-control-allow-origin only to pets-visualstories-com.cdn.ampproject.org. So when the story on travel-visualstories-com.cdn.ampproject.org is trying to use the SVG it gives this error:
It means the story that gets crawled first is getting the access.
CCing myself to this thread, I'm going to look into it tonight.
Investigated this, and it's an Google AMP Cache issue. It's easily visible by doing:
- Open new tab: https://thrilling--bubble--feast-glitch-me.cdn.ampproject.org/c/s/thrilling-bubble-feast.glitch.me
- Hard refresh
- Observe the page has a black circle with white text, and that the 9304945.svg image is cached in network panel with
access-control-allow-origin: https://thrilling--bubble--feast-glitch-me.cdn.ampproject.org - Navigate to: https://mixolydian--humorous--boa-glitch-me.cdn.ampproject.org/c/s/mixolydian-humorous-boa.glitch.me
- Observe the page is blank, and there's a blocked request to the same 9304945.svg.
This is because we've tightened the ACAO header from * to https://thrilling--bubble--feast-glitch-me.cdn.ampproject.org in during the initial request to 9304945.svg, which is then cached. When you open the second page, it is making a request to the same image, and the browser reuses the cached response. That response does not allow https://mixolydian--humorous--boa-glitch-me.cdn.ampproject.org Origin, and so the response request is rejected.
Unfortunately when we added this tightening, we failed to consider the request from multiple Cached Origins, and that the response would be reused across those multiple origins. I'm opening an internal bug to have this fixed.
The good news is that the fix is simple (we need to add a Vary: Origin to our response, which will inform the browser it needs to re-request the image since it's requesting with a new Origin header when it's on the second page). The bad news is the fix won't be able to roll out until next Thursday at the earliest.
Internal bug: b/186585381
@jridgewell Thanks for helping to understand issue.
cl/370994902 (Google internal pull request) has been merged, so we should see this fix roll out next Thurs.
@jridgewell It seems this issue haven't fixed yet. Open the attached page URL and open console you will see some ACAO header issues.
https://animals-visualstories-com.cdn.ampproject.org/v/s/animals.visualstories.com/why-are-flamingos-pink?amp_js_v=0.1
The server push that was supposed to happen last week was reverted due to an unrelated bug. We're still waiting for this week's push, which should happen again on Thursday.
The server push is live now, and my tests pages are passing.