Hi Adam,
100%, CDNs are an invitation for supply chain attacks. At least with integrity hashes, it’s probably equally as secure as npmjs. To be fair, both npm and PyPi have put serious effort into fixing this with 2FA and OIDC trust chains. There are also CDNs that only build from GitHub directly, making dist injections less likely.
Anyhow, I always vendor my dependencies too, but the second you use a CDN (which you might need to), supply chain integrity becomes an issue again.
Now to the how:
First, Safari doesn’t support the header yet… of course it doesn’t… but the integrity argument on script tags and importmaps has baseline support.
Yes, Django’s ManifestStaticFilesStorage already creates hashes, but md5. This would need to be at least sha384 or better sha512. They compute a little slower, but nothing compared to Brotli compression. Anyhow, static file collection is certainly the best place to generate lock integrity hashes.
So my best guess, without having done the actual work yet, would be a new middleware and an extension of the staticfile backends. Something like this StaticFilesStorage.integrity(name: str)
We could EAFP the new method for very gentle backwards compatibility. Meaning, if the backend provides an integrity method, it’s rendered into form media, otherwise it isn’t.
Most of this could be done in a separate package, except for the actual rendering part. Maybe that’s a good place to start. Only implement the if the backend has an integrity we render it and leave the rest for 3rd parties for now until more maturity is reached.
Those would be my two cents about this.
Best
Joe