Use consistent HTML escaping in error details fragment - #3466
Open
iliaal wants to merge 2 commits into
Open
Conversation
The exception message and trace in renderExceptionFragment() used bare htmlentities(), whose default flags differ across PHP versions and inherit the default_charset ini, while the title and description are escaped with explicit ENT_QUOTES | ENT_SUBSTITUTE flags and a pinned UTF-8 charset. Align the fragment escaping with the same explicit call so behavior is identical on every supported PHP version.
odan
reviewed
Aug 23, 2026
| htmlspecialchars($exception->getMessage(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') | ||
| ); | ||
|
|
||
| $html .= sprintf('<div><strong>File:</strong> %s</div>', $exception->getFile()); |
Contributor
There was a problem hiding this comment.
File is still emitted without HTML escaping
Author
There was a problem hiding this comment.
Agreed. getFile() is string and a path can contain <>&"'. I'll escape it with the same htmlspecialchars(..., ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') call as message and trace.
odan
reviewed
Aug 23, 2026
|
|
||
| $html .= sprintf('<div><strong>File:</strong> %s</div>', $exception->getFile()); | ||
|
|
||
| $html .= sprintf('<div><strong>Line:</strong> %s</div>', $exception->getLine()); |
Contributor
There was a problem hiding this comment.
Is still emitted without HTML escaping
Author
There was a problem hiding this comment.
getLine() is int, so escaping is a no-op. I'll still add it for uniformity.
The real sibling is Type: anonymous class names embed the file path. I'll escape Type (and Code, which has no return type on Throwable) in the same pass.
File, Type, Code, and Line were interpolated into the details fragment without escaping. File paths and anonymous class names can contain HTML metacharacters, and Throwable::getCode() is untyped. Route every fragment field through the same htmlspecialchars() flags as title and description.
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.
HtmlErrorRenderer::renderExceptionFragment()escapes the exception message and stack trace with barehtmlentities(), while the title and description are escaped with explicithtmlspecialchars(..., ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'). The two escape sites therefore behave differently across the supported PHP range:htmlentities()default flags gainedENT_QUOTESonly in PHP 8.1, so on 7.4/8.0 single quotes in the message pass through unescaped, and the charset is inherited from thedefault_charsetini rather than pinned to UTF-8.This aligns the fragment escaping with the same explicit call used everywhere else in the renderer, making behavior identical on every supported PHP version.