Repository navigation
Read the extra rich-text attributes from appsettings, with id opt-in - #1119
Merged
Merged
Conversation
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.
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.
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.
A product description, page, blog post or news item with an
idon an element could not be saved: the rich-text allowlist (HtmlSanitizer defaults plusclassand the iframe embed attributes) has noid, so[SanitizeHtml]rejected the whole field with "contains HTML markup that is not allowed". The only way around it was turningEnableHtmlSanitizationoff.Allowing
ideverywhere 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 turnswindow.vmorderinto an element, add-to-cart throws aftersetLoadWaiting(true)and every cart button on the page stays locked;id="catalog-products"orid="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, likeSanitizerAllowedIframeHosts. Unset = built-in defaults,[]= none.class,allowfullscreen,frameborder,allow,loading.idis not in it; an installation that needs in-page anchors (a table of contents) adds"id"to the list.appsettings.jsonfiles list the defaults, with a comment on when to addidand what must never be listed (event handlers,data-*, Vue directives).Notes
EnableHtmlSanitization: whoever edits appsettings can already switch sanitization off, so the list is not validated.idallowed, Vue bindings of it (:id,v-bind:id) are still rejected.Tests
HtmlSanitizationServiceTests:idrejected by default; configured attributes accepted (trimmed, case-insensitive);[]rejectsclass;:idandv-bind:idrejected even whenidis allowed.Grand.Infrastructure.Tests(400) and the import tests inGrand.Business.Catalog.Tests(175) pass.