Repository navigation
HTMLEncode: escape single quotes, size the result exactly - #569
Merged
Merged
Conversation
HTMLEncode escaped only < > & and ", so application code that used it for a single-quoted attribute value could be broken out of with a ' (XSS). The framework's own three uses put the value in element text and were unaffected. - Escape ' as '. - Size the result exactly in a first pass instead of allocating six times the input; return the input unchanged when nothing needs escaping. - Doc comment: safe for element text and quoted attribute values, not for unquoted attributes or JavaScript/CSS/URL contexts. - Tests: single quote, the attribute break-out from the issue, text with nothing to escape (including a non-ASCII character). - SECURITY.md "Output encoding" updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Closes #562.
djGlobal.HTMLEncodeescaped only<,>,&and". Application code that used it for a single-quoted attribute value could be broken out of:The framework's own uses (the 404 page and the development-mode 500 page) put the value in element text and were not affected.
Changes
'is now escaped as'. This only adds escaping, so existing output stays valid HTML.SetLength(Result, Length(AData) * 6). When nothing needs escaping, the input is returned as-is, with no new allocation.SECURITY.md"Output encoding" is updated to match.Tests
djGlobalTestsadds:'on its own;The consecutive-characters test now includes
', and the widest-escape test's comment now describes the exact sizing.run-fpc.cmd): 215 tests, 0 errors, 0 failures; heap trace at the clean baseline (6 blocks / 744 bytes).run-delphi.cmd): OK, 215 tests.Both were run before the rebase onto the merged #568, which touches none of these files.
🤖 Generated with Claude Code