Sanitize user rich-text HTML server-side with nh3 (security-private#26) #1200
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.60) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.60 · 217 lines diff across 2 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.322
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.060
Real PR Conversation Timeline
1 comments
"Review active on #1200"
general
weight: 0.35
eshellman
Fixes the stored-XSS surface tracked in EbookFoundation/security-private#26: user-authored rich text (
Campaign.description/details,Work.description, edition descriptions — all authored via CKEditor) is rendered on public pages with{{ ... |safe }}and no server-side sanitization. CKEditor's own filtering runs only in the browser and is bypassable, so it is not a security boundary.What this does
regluit/utils/html.py—sanitize_html()using nh3 (maintained Rust/ammonia binding;bleachis deprecated). Allow-list mirrors what the CKEditor toolbar can produce (bold/italic, lists, blockquote, links, images,hr), plus common paste tags. Strips<script>,<style>, event handlers,javascript:URLs, etc.sanitizetemplate filter (frontend/templatetags/sanitizer.py).|safewith|sanitizeon the browser-rendered rich-text fields:home.html,work.html,download.html,bypub_list.html.nh3inrequirements.txt.SanitizeRichTextTeststofrontend/tests.py.Why output-sanitization (not just input)
Sanitizing at render time is editor-independent and also neutralizes any already-stored markup, so no data migration is needed. It remains correct even if the editor is later swapped (e.g. the eventual CKEditor 5 migration).
Scope notes
pdf/ask.html,epub/ask.xhtml) are intentionally left as-is — not a browser-XSS vector, and changing them risks document validity.onerror/javascript:/allowed-formatting cases; the full Django test suite runs in CI/staging.Ref: security-private#26 (private — has the full surface analysis).