Repository navigation
Escape props bound to child attributes in folded components - #244
Merged
Merged
Conversation
Contributor
Benchmark Result: Default
Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 17.91s total To run a specific benchmark, comment |
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.
The scenario
A folded wrapper passes a prop to a Flux input's error attribute, and the quotes reach the HTML unescaped.
The wrapper looks harmless. Marking a prop as safe when it's only passed through to another component is a natural thing to do.
The problem
Placeholders record how a value enters the folded component: a
PROPplaceholder is restored raw and anATTRplaceholder is restored escaped. Blade changes this along the way. A prop bound to a child component's attribute gets escaped, so it's no longer raw.While folding, that escaping does nothing to a placeholder string:
$errorLabelholds aPROPplaceholder.:error:aria-label="$errorLabel"passes it throughsanitizeComponentAttribute(), which leaves it unchanged.with-fieldpasses the error attributes through@unblaze(scope: ...).PROPplaceholder in the scope as the raw$errorLabel.Placeholders that end up in HTML are always restored escaped, so only
@unblazescopes are affected. In Flux these are the error attributes of fields and the avatar attributes of Flux Pro select options.The solution
While folding, escaping an attribute turns its
PROPplaceholder into theATTRplaceholder of the same attribute. The existing restoration then outputs it escaped, like Blade.A value wrapped in
HtmlStringkeeps itsPROPplaceholder, since Blade doesn't escape trusted HTML either.Foldablealso registers anATTRplaceholder with the same index for everyPROPplaceholder, so a converted placeholder always has an attribute to restore.sanitizeComponentAttribute()with this method. It runs after component tags are compiled, so it covers attributes of Blaze components, their slots, and plain Blade components.mergeAttributes()uses the method as well when a non-bag value is passed as:attributes.Restoration, the HTML output and existing test expectations don't change.