Security rules
NGB045: Missing subresource integrity
Reports third-party scripts and stylesheets loaded from another origin without an integrity attribute: <script src="https://cdn…"> and <link rel="stylesheet" href="https://…"> in index.html, and <script> elements created in code (document.createElement('script'), Renderer2.createElement('script')) whose constant external src is set without integrity.
| Property | Value |
|---|---|
| Rule ID | NGB045 |
| Category | Supply chain |
| Default severity | medium |
| CWE | CWE-353, CWE-829 |
| Built-in presets | recommended: warn, strict: error |
Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.
What it checks
Reports third-party scripts and stylesheets loaded from another origin without an integrity attribute: <script src="https://cdn…"> and <link rel="stylesheet" href="https://…"> in index.html, and <script> elements created in code (document.createElement('script'), Renderer2.createElement('script')) whose constant external src is set without integrity. Providers that serve evolving scripts at a fixed URL (tag managers, payment SDKs, maps, captcha) are reported with low confidence because SRI cannot be applied to them.
Why it matters
A script from a CDN runs with full access to your page. If the CDN, the package on it, or the connection is compromised, every visitor runs the attacker's code (polyfill.io in 2024 is the textbook case). integrity="sha384-…" makes the browser refuse a file that differs from the one you reviewed.
Detection behavior and supported patterns
- index.html:
<script src>with an absolute / protocol-relative URL and nointegrity(medium severity);<link rel="stylesheet" href>likewise (low severity) - Code:
const s = document.createElement('script'); s.src = 'https://cdn…'withouts.integrity = …/setAttribute('integrity', …)in the same scope (low confidence) - Known evolving providers (Google Tag Manager / Analytics, Stripe.js, Google Maps / Fonts, reCAPTCHA, PayPal, Braintree, Segment, Intercom, Cloudflare) are reported with low confidence and low severity
Example
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js"></script>Safer alternative
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js" integrity="sha384-…" crossorigin="anonymous"></script>Remediation
Prefer bundling dependencies through npm. For CDN files, pin an exact version and add integrity="sha384-…" crossorigin="anonymous". For providers that cannot support SRI, restrict them with a strict CSP allowlist and keep them off sensitive pages (checkout, login).
False-positive considerations
- Version-pinned URLs on a CDN you control are still reported; SRI is cheap insurance there too.
Known limitations
- Scripts injected by tag managers or other scripts at runtime are not visible.
- Whether the
integrityhash matches the current file is not verified. - Dynamic script URLs are handled by NGB005 (untrusted script loading).
References
Run it
ngbastion explain NGB045