Conversation
There was a problem hiding this comment.
Pull request overview
This PR restores support for the documented Font Awesome icon pattern in Box as_html content by allowing a tightly-scoped subset of <link rel="stylesheet"> tags to survive sanitization, without broadly reopening external stylesheet injection.
Changes:
- Added extraction and reinsertion of allowlisted HTTPS stylesheet
<link>tags (exact host match) around the DOMPurify sanitization pass. - Rebuilds kept
<link>tags from scratch to preserve onlyrel,href,integrity, andcrossorigin. - Added Jest coverage for the allowlist behavior (positive case + rejection guards) and regression coverage for previously documented Box HTML/CSS patterns.
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| theSrc/scripts/sanitizeHtml.js | Extracts <link> tags before DOMPurify and reinserts only HTTPS stylesheet links to an exact-match host allowlist, rebuilt with a minimal safe attribute set. |
| theSrc/scripts/sanitizeHtml.jest.test.js | Adds tests ensuring Font Awesome CDN links survive with SRI/CORS preserved, and that non-allowlisted/unsafe <link> variants are rejected; includes regression checks for documented Box features. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… fail closed) Addresses PR #54 review (Kevin Huang): - LINK_TAG now matches '>' only outside quoted attribute values, so a link with e.g. title="a > b" is no longer truncated and dropped. - Strip HTML comments before <link> extraction so a commented-out (inert) link is not revived by the raw-text match. - Wrap extractAllowedStylesheetLink in try/catch (fail closed) so a runtime without <template> support drops the one link instead of aborting all sanitisation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RS-22478 added
theSrc/scripts/sanitizeHtml.js, which sanitisesas_htmlBox content through DOMPurify and strips<link>. That silently broke the documented Font Awesome icon pattern taught in the Displayr help centre (articles 360004283115 and "Adding Icons to Dashboards Using Font Awesome"):The
<i class="fas …">classes survive, but render blank because the CDN stylesheet/webfont that draws the glyphs — loaded by the stripped<link>— never arrives.This PR restores that pattern without re-opening arbitrary external stylesheets.
Change
Extract
<link>tags before DOMPurify (mirroring the existing<style>handling insanitizeHtml.js) and re-insert only links that are:rel="stylesheet", andhttps:, anduse.fontawesome.com).Each kept link is rebuilt from scratch, preserving only
rel/href/integrity/crossorigin— soonload/other attributes can't ride along, andouterHTMLescaping prevents attribute-injection breakout. The allowlist is theSTYLESHEET_HOST_ALLOWLISTconstant (extend by adding hosts).Why host-scope
<link>(and not just re-allow it)External CSS is a higher-risk vector than
<img>(which Displayr already permits from arbitrary hosts per help article 360004368515): a stylesheet can exfiltrate page state via attribute-selector +background: url(...)tricks, whereas an image cannot. So<link>stays scoped to the Font Awesome CDN.integrity(SRI) is preserved, so even the allowlisted host can't serve tampered CSS.No
q/CSP change needed:/Dashboardemits nostyle-src/font-src/default-src, so the CDN stylesheet + webfont load once the sanitiser lets the<link>through.Testing
node_modules/.bin/jest theSrc/scripts/sanitizeHtml.jest.test.js→ 30/30 passing:<link>survives withintegrity/crossoriginpreserved.use.fontawesome.com.evil.com), non-stylesheetrel,http:,javascript:,onloadstripped, case/whitespace normalised.<img>/<style>).Notes
🤖 Generated with Claude Code