missing-subresource-integrity
A script or style sheet loaded from another host without an integrity hash.
- Group
- Code
- Runs
- Runs under ur scan:
ur scan --rule missing-subresource-integrity - Level
- warning
- Reads
- Every file
- Fix
- None: the hash is of the file the host serves, which Ur does not fetch
Why
A view or HTML page loads a script or a style sheet from a CDN or another host, by a URL that names a fixed file, without an integrity attribute, so the browser runs whatever that host serves: whoever takes over the host, or the path to it, runs code in every page that loads it. Add integrity="sha384-..." with the file's hash, and crossorigin="anonymous", or serve the file from the application. Rails' javascript_include_tag and stylesheet_link_tag take integrity: too. Services whose files change, as analytics, maps, and payment scripts, are not reported, since no hash can pin them.
The fix, as Ur suggests it: add integrity="sha384-..." and crossorigin="anonymous".
For agents
Load every script and style sheet from another host with an integrity hash, or serve it from the application.
Example
app/views/layouts/application.html.erb<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<%= javascript_include_tag "application" %>
</head>
<body><%= yield %></body>
</html>
$ ur scan --rule missing-subresource-integrity
warning[missing-subresource-integrity]: script from `cdn.jsdelivr.net` loaded without `integrity`, and 1 more in this file
--> ./app/views/layouts/application.html.erb:4:3 script from cdn.jsdelivr.net
--> ./app/views/layouts/application.html.erb:5:3 style sheet from cdn.jsdelivr.net
= hint: add integrity="sha384-..." and crossorigin="anonymous"
= see: Subresource Integrity, W3C Recommendation (2016-06-23), https://www.w3.org/TR/SRI/
scanned 1 file (no framework recognized)
missing-subresource-integrity: 1 high, 0 medium
1 finding and 0 of medium confidence
Source
Subresource Integrity, W3C Recommendation (2016-06-23).