Add Subresource Integrity (SRI) verification for remote stylesheets #190
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 295 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.340
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #190"
general
weight: 0.35
grosser
What
Adds an
integrity:option toParser#load_uri!that verifies a fetched remote stylesheet against a Subresource Integrity value before it's parsed — the same value an HTML<link integrity="...">attribute carries.sha256/sha384/sha512, multiple space-separated values in oneintegrity:string (exactly like the HTML attribute), and the spec's "agility" rule: when a value lists more than one algorithm, only the strongest present one is actually checked, and every weaker one is ignored outright — e.g.sha256-... sha384-...only checks the sha384 value. When several values are given for that same strongest algorithm (e.g. during a planned key/stylesheet rotation), matching any one of them is enough.CssParser::RemoteFileErrorwhenio_exceptionsis enabled, otherwise loads nothing.Why
Consumers of this gem that already know the expected digest of a linked stylesheet (for example, because it came from an HTML
<link integrity="...">attribute they're processing) currently have no way to askload_uri!to verify it — the fetched body is trusted unconditionally regardless of what the caller expected. This gives callers an opt-in way to fail closed instead.Testing
test/test_css_parser_integrity.rb, covering: normal pass-through when the option is omitted, all three supported algorithms, mismatch handling (with and withoutio_exceptions), the multi-algorithm "agility" rule in both directions (weaker-correct+stronger-wrong fails, weaker-wrong+stronger-correct passes), multiple acceptable values for one algorithm, and the unsupported-algorithm-is-unverifiable case.bundle exec rake test) — no behavior change whenintegrity:isn't passed.bundle exec rubocopclean on the changed files.Happy to adjust the option name/shape or add doc updates elsewhere if you'd rather it live somewhere other than
load_uri!.