Repository navigation
fix: escape the field name in the field row - #296
Merged
Merged
Conversation
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 custom fields management page now shows a field's name as text. Before, the name went into the page as raw HTML in two places on each field row: the edit link label and its tooltip attribute. A name holding markup ran as script for anyone who opened the page with sections on, which is the package default.
What changed
resources/views/livewire/manage-custom-field.blade.phppassese($field->name)to both theHtmlStringlabel and thex-tooltip.rawattribute.Why this way
The label stays an
HtmlStringbecause it wraps the name in atruncatespan. Escaping the name inside it keeps the markup and makes the name text.The tooltip needs its own escape. Filament's link merges extra attributes with
escape: false, and Laravel's attribute bag then only backslash-escapes quotes. A backslash does not end an HTML attribute, so">broke out of it. Escaping only the label left this second sink open, and the test fails in that state. The browser decodes the entities before Alpine reads the attribute, and the tooltip has no.htmlmodifier, so it shows the real name as text.Behavior to know about
A name with
&,<or quotes now displays as typed in both places. No migration, no config key.Tests
tests/Feature/Admin/Pages/CustomFieldsFieldManagementTest.php: "renders the field name as text in the field row" renders a field named"><img src=x onerror=alert(1)>and asserts the raw tag is absent and both the label and the tooltip carry the escaped name.Checked
At 927c573: the new test fails on 3.x as it stands, fails with only the label escaped, and passes with both. The test file passes (52 passed, 1 todo). Pint, rector and the arch tests pass.
Not checked
The tooltip in a real browser. The escaped attribute value is asserted, not rendered.