Skip to content

Sanitize HTML icon options in Chips and NavOverflow - #42805

Open
aljojoby9 wants to merge 2 commits into
twbs:v6-devfrom
aljojoby9:fix/sanitize-icon-html-options
Open

Sanitize HTML icon options in Chips and NavOverflow#42805
aljojoby9 wants to merge 2 commits into
twbs:v6-devfrom
aljojoby9:fix/sanitize-icon-html-options

Conversation

@aljojoby9

Copy link
Copy Markdown

Description

Chips and NavOverflow accept HTML for their icon options, and those values can also come from the data API. They were written straight into the DOM with innerHTML / string templates, so a crafted dismissIcon, moreIcon, moreText, menuPlacement, or [data-bs-overflow-icon] value could inject markup.

  • Route dismissIcon, moreIcon, and [data-bs-overflow-icon] HTML through a new DefaultIconAllowlist in the sanitizer (covers the default SVGs and common icon markup)
  • Build the NavOverflow overflow toggle with DOM APIs instead of an HTML string template
  • Insert moreText with textContent and set menuPlacement with setAttribute
  • Document the icon allowlist and note sanitization on the Chips / NavOverflow option tables
  • Add unit coverage for the XSS-style payloads and for the default SVG icons still rendering

Checklist

dismissIcon, moreIcon, and [data-bs-overflow-icon] markup were inserted
via innerHTML without going through the sanitizer. moreText and
menuPlacement were also interpolated into HTML string templates.

Route icon HTML through a dedicated DefaultIconAllowlist, insert
moreText with textContent, and build the NavOverflow toggle with DOM
APIs so those values cannot break out of their slots.
@aljojoby9
aljojoby9 requested a review from a team as a code owner August 6, 2026 19:14
Copilot AI lite review requested due to automatic review settings August 6, 2026 19:14
The icon allowlist and sanitizer calls in Chips and NavOverflow push the
gzipped min builds a few dozen bytes over the previous caps.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces XSS risk in Bootstrap v6 by sanitizing icon HTML options in Chips and NavOverflow.

Changes:

  • Add a new DefaultIconAllowlist for icon-related HTML sanitization.
  • Replace NavOverflow toggle string templates with DOM API construction, and insert moreText as plain text.
  • Add docs and unit tests for XSS-style payloads and for default SVG icon rendering.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
site/src/content/docs/getting-started/javascript.mdx Document the icon allowlist and clarify sanitizer scope.
site/src/content/docs/forms/chips.mdx Note that dismissIcon is sanitized before DOM insertion.
site/src/content/docs/components/nav-overflow.mdx Note that moreText is plain text and moreIcon / markup icons are sanitized.
js/tests/unit/util/sanitizer.spec.js Add tests for DefaultIconAllowlist SVG retention and XSS stripping.
js/tests/unit/nav-overflow.spec.js Add tests for moreText, moreIcon, menuPlacement, and markup icon sanitization.
js/tests/unit/chips.spec.js Add tests for default dismiss SVG retention and dismissIcon sanitization (JS and data API).
js/src/util/sanitizer.ts Introduce DefaultIconAllowlist and expose it for docs and components.
js/src/nav-overflow.ts Build the overflow toggle with DOM APIs and sanitize icon HTML before insertion.
js/src/chips.ts Sanitize dismissIcon HTML before inserting it into the dismiss button.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants