Security
security/sri-cdn
Versioned files from a public CDN carry Subresource Integrity (integrity plus crossorigin), or are self-hosted.
moderatestaticfe-security
Why
A script from a CDN runs with the full rights of your page. If the CDN or the package is compromised, every site that loads the file runs the attacker's code. With an integrity hash, the browser refuses a file that changed.
Fix
Add integrity="sha384-…" (the hash the CDN or openssl dgst -sha384 -binary file | openssl base64 -A gives) and crossorigin="anonymous". Better: install the package and let the build bundle it, so it is served from your origin. URLs without a fixed version (tag managers, latest) cannot use SRI; keep them to a minimum.
Examples
<!-- bad -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<!-- good -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha384-…" crossorigin="anonymous"></script>Sources
Facts
- Id
security/sri-cdn- Severity
- moderate
- Check
- static checked in the source by
audit - Applies to
htmlvuesvelteastrojsx- Taught by the skill
fe-securityFront-end security- Since version
- 0.1.0
Read it in the terminal
npx github:dawidolko/frontend-skills explain security/sri-cdn