Skip to content

Read the extra rich-text attributes from appsettings, with id opt-in - #1119

Merged
KrzysztofPajak merged 2 commits into
developfrom
fix/sanitizer-allow-id
Nov 24, 2026
Merged

KrzysztofPajak merged 2 commits into
developfrom
fix/sanitizer-allow-id

Conversation

@KrzysztofPajak

@KrzysztofPajak KrzysztofPajak commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

A product description, page, blog post or news item with an id on an element could not be saved: the rich-text allowlist (HtmlSanitizer defaults plus class and the iframe embed attributes) has no id, so [SanitizeHtml] rejected the whole field with "contains HTML markup that is not allowed". The only way around it was turning EnableHtmlSanitization off.

Allowing id everywhere is not safe as a default: the storefront scripts look elements and globals up by id, so content can take those names over. <span id="vmorder"> in a vendor description turns window.vmorder into an element, add-to-cart throws after setLoadWaiting(true) and every cart button on the page stays locked; id="catalog-products" or id="product-details-form-<variant>" in a category or grouped-product description is found before the real element.

Changes

  • SecurityConfig.SanitizerAllowedAttributes: the attributes allowed on top of the sanitizer defaults now come from appsettings, like SanitizerAllowedIframeHosts. Unset = built-in defaults, [] = none.
  • The default list is the one the code had: class, allowfullscreen, frameborder, allow, loading. id is not in it; an installation that needs in-page anchors (a table of contents) adds "id" to the list.
  • All four appsettings.json files list the defaults, with a comment on when to add id and what must never be listed (event handlers, data-*, Vue directives).

Notes

  • The setting is trusted like EnableHtmlSanitization: whoever edits appsettings can already switch sanitization off, so the list is not validated.
  • With id allowed, Vue bindings of it (:id, v-bind:id) are still rejected.

Tests

  • HtmlSanitizationServiceTests: id rejected by default; configured attributes accepted (trimmed, case-insensitive); [] rejects class; :id and v-bind:id rejected even when id is allowed.
  • Grand.Infrastructure.Tests (400) and the import tests in Grand.Business.Catalog.Tests (175) pass.

Product descriptions, pages and blog posts with an id on an element (an in-page anchor target) could not be saved: the sanitizer allowlist had no id, so [SanitizeHtml] rejected the whole field.
Copilot AI balanced review requested due to automatic review settings November 23, 2026 19:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Allowing id for every installation let content take over ids and globals the storefront scripts look up (window.vmorder, #catalog-products, #product-details-form-*), which can lock the cart buttons on a page. The attributes allowed on top of the sanitizer defaults now come from SecurityConfig.SanitizerAllowedAttributes; the default list is the one the code had before (class and the iframe embed attributes), and an installation that needs in-page anchors adds "id" there.
@KrzysztofPajak KrzysztofPajak changed the title Accept id attributes in rich-text content Read the extra rich-text attributes from appsettings, with id opt-in Nov 24, 2026
@KrzysztofPajak
KrzysztofPajak merged commit e5e4368 into develop Nov 24, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the fix/sanitizer-allow-id branch November 25, 2026 09:08
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