Repository navigation
Srcdoc escaping - #425
Closed
vrana wants to merge 3 commits into
Closed
Srcdoc escaping#425vrana wants to merge 3 commits into
vrana wants to merge 3 commits into
Conversation
…boolean attributes (BC break)
None of them is a boolean attribute in HTML; they are enumerated ones, so
rendering them as a bare name was wrong in three separate ways:
- a string 'false' is truthy in PHP, so contenteditable={$s} rendered the
attribute present, i.e. the exact opposite of what was asked for
- the empty value is not a keyword of draggable, it maps to the invalid value
default 'auto', so draggable=true could not be expressed at all
- 'attribute missing' and 'attribute false' are different states; the false
value is what disables editing inside a contenteditable region, and dropping
the attribute silently inherited from the parent instead
Two new categories replace them. 'tristate' (contenteditable, draggable,
spellcheck, writingsuggestions) maps bool to the true/false keywords, exactly
like aria-* already does, so formatAriaAttribute now delegates to it. The
'valuedBool' one (hidden, popover) stays a flag but keeps a non-empty value,
so hidden="until-found" survives. Falsy values are tested first there: hidden
with a '0' coming from a database must not render hidden="0", which is an
invalid value and would map back to the hidden state.
…BC break)
The value of srcdoc is an HTML document: the browser attribute-decodes it and
then parses the result as HTML. Latte escaped it like any other attribute, so
<iframe srcdoc="<p>{$x}</p>"> with $x = '<script>...</script>' rendered
<script>, which decodes to a live <script>. An iframe without sandbox
shares the parent's origin, so this was an XSS.
srcdoc now gets its own html/attr/html context: a value is escaped as HTML text
first and as an attribute second (HtmlHelpers::escapeHtmlAttr). This covers the
static attribute, the dynamic attribute srcdoc={$x}, n:attr and blocks or
templates included into srcdoc.
An Html object is encoded only once, so trusted markup keeps its tags;
previously they were stripped.
BC break: trusted HTML passed as a plain string is now displayed as text. Wrap
it in Latte\Runtime\Html (or use |noescape).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ly rendered as HTML
With Feature::MigrationWarnings, a plain srcdoc value that renders as a different
document now than before (it contains '<' or a character reference) triggers
a warning suggesting to wrap trusted HTML in Latte\Runtime\Html. Text such as
'a & b' renders the same document as before and stays quiet; so does an Html
object, whose tags were stripped before and are kept now. |accept silences it.
It covers dynamic attributes (srcdoc={$x}, srcdoc="{$x}") and n:attr. A mixed
value like srcdoc="<p>{$x}</p>" is escaped by code the Escaper emits, which has
no access to feature flags, so it does not warn.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dg
force-pushed
the
master
branch
2 times, most recently
from
October 22, 2026 00:10
02b2c13 to
c169e13
Compare
Member
|
Thanks, merged! |
dg
pushed a commit
that referenced
this pull request
Nov 17, 2026
…BC break) (#425) The value of srcdoc is an HTML document: the browser attribute-decodes it and then parses the result as HTML. Latte escaped it like any other attribute, so <iframe srcdoc="<p>{$x}</p>"> with $x = '<script>...</script>' rendered <script>, which decodes to a live <script>. An iframe without sandbox shares the parent's origin, so this was an XSS. srcdoc now gets its own html/attr/html context: a value is escaped twice as an attribute value (HtmlHelpers::escapeHtmlAttr). Latte does not parse the document, so the value may land in its text as well as in one of its attributes, as in <iframe srcdoc="<p title="{$x}">">, where an unescaped quote would let it add an event handler. This covers the static attribute, the dynamic attribute srcdoc={$x}, n:attr and blocks or templates included into srcdoc. An Html object is encoded only once, so trusted markup keeps its tags; previously they were stripped. BC break: trusted HTML passed as a plain string is now displayed as text. Wrap it in Latte\Runtime\Html (or use |noescape).
dg
pushed a commit
that referenced
this pull request
Nov 17, 2026
…ly rendered as HTML (#425) With Feature::MigrationWarnings, a plain srcdoc value that renders as a different document now than before (it contains a tag or a character reference, also one that browsers decode without a semicolon) triggers a warning suggesting to wrap trusted HTML in Latte\Runtime\Html. Text such as 'a & b' or 'a < b' renders the same document as before and stays quiet; so does an Html object, whose tags were stripped before and are kept now. |accept silences it. It covers dynamic attributes (srcdoc={$x}, srcdoc="{$x}") and n:attr. A mixed value like srcdoc="<p>{$x}</p>" is escaped by code the Escaper emits, which has no access to feature flags, so it does not warn.
dg
pushed a commit
that referenced
this pull request
Nov 18, 2026
…BC break) (#425) The value of srcdoc is an HTML document: the browser attribute-decodes it and then parses the result as HTML. Latte escaped it like any other attribute, so <iframe srcdoc="<p>{$x}</p>"> with $x = '<script>...</script>' rendered <script>, which decodes to a live <script>. An iframe without sandbox shares the parent's origin, so this was an XSS. srcdoc now gets its own html/attr/html context: a value is escaped twice as an attribute value (HtmlHelpers::escapeHtmlAttr). Latte does not parse the document, so the value may land in its text as well as in one of its attributes, as in <iframe srcdoc="<p title="{$x}">">, where an unescaped quote would let it add an event handler. This covers the static attribute, the dynamic attribute srcdoc={$x}, n:attr and blocks or templates included into srcdoc. An Html object, and a value printed with |noescape, is encoded only once, so trusted markup keeps its tags; previously an Html object lost them and |noescape escaped only quotes, so an escaped <script> in it came alive. A block defined in srcdoc becomes HTML by one attribute decoding, so it can be included elsewhere and overridden by a block of an HTML template, and |stripHtml and |stripTags accept it. Both work on the document, so |stripTags also removes tags the attribute holds as entities. A block from an ordinary attribute is included into srcdoc as text. BC break: trusted HTML passed as a plain string is now displayed as text. Wrap it in Latte\Runtime\Html (or use |noescape).
dg
pushed a commit
that referenced
this pull request
Nov 18, 2026
…ly rendered as HTML (#425) With Feature::MigrationWarnings, a plain srcdoc value that renders as a different document now than before (it contains a tag or a character reference, also one that browsers decode without a semicolon) triggers a warning suggesting to wrap trusted HTML in Latte\Runtime\Html. Text such as 'a & b' or 'a < b' renders the same document as before and stays quiet; so does an Html object, whose tags were stripped before and are kept now. |accept silences it. It covers dynamic attributes (srcdoc={$x}, srcdoc="{$x}") and n:attr. A mixed value like srcdoc="<p>{$x}</p>" is escaped by code the Escaper emits, which has no access to feature flags, so it does not warn.
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.
Uh oh!
There was an error while loading. Please reload this page.