My issue
I created a new site today: https://til-alexwlchan.netlify.app
I copied a bunch of config from another Netlify site I’ve had running for a long time, including the CSP:
[[headers]]
for = "/*"
[headers.values]
content-security-policy = """\
default-src 'self'; \
style-src 'self' 'unsafe-inline' https://alexwlchan.net; \
script-src 'self' 'unsafe-inline'; \
connect-src https://analytics.alexwlchan.net; \
img-src 'self' 'unsafe-inline' https://alexwlchan.net;
"""
I’m building the site manually and deploying it through the Netlify CLI.
When I look in the generated HTML, the <img>
tag has been replaced with a URL pointing at CloudFront:
<img src="https://d33wubrfki0l68.cloudfront.net/9c03ebb826fa11a2217bb090135ac6f8a628f59c/3eee9/notebook.png">
This causes the images not to load, because that URL isn’t in my CSP.
I would like my images not to be rewritten, so I get a plain link directly to the image on my domain, i.e.
<img src="/notebook.png">
which is how I’m loading images on all my other Netlify sites.
You can see an example of a broken deployment here: https://65b2cbb53880fd338987fc90--til-alexwlchan.netlify.app
(I’m going to temporarily relax the CSP, so the main URL should soon be fixed, but I think that permanent deployment URL should stay broken?)
Similar issues, all with a common cause?
This isn’t the first time this has happened:
- Images are served directly from Amazon CloudFront servers for branch deployments (yesterday!)
- Asset optimization still enabled and ignoring configuration which disables it (two broken sites, December 2023)
On both occasions Netlify support engineer hrishikesh has come along and fixed the problem, so I’m hoping somebody can do the same here.
Looking further back in the forum, these CloudFront URLs do seem to be related to the now-deprecated Asset Optimization feature. But I created my website earlier today, long after that feature was apparently switched off. Maybe there’s a setting stuck somewhere?
I’ve tried deploying with config that disables Asset Optimization, even though that config is allegedly disabled – no joy, the image URLs are still being rewritten.
Please can somebody from Netlify help me get these URLs fixed on my site?