fix: prevent </script> breakout in HtmlOutput anchor JS literal#1340
Merged
karlkleinpaste merged 1 commit intoJul 1, 2026
Merged
Conversation
Contributor
|
reproducer.c: you named them the same thing, and now i don't know if i should bother keeping the (small) one in this PR. |
g_strescape() escapes backslash, double-quote, and C0 control bytes but leaves '<', '>', and '/' untouched, so a sword:// fragment of "</script><script>PAYLOAD</script>" passes through unchanged when interpolated into the inline <script> block in HtmlOutput(). WebKit's HTML parser ends the <script> block at the literal '</script>' and starts a new <script>PAYLOAD</script> block, which executes arbitrary JavaScript in the file:// origin that wk_html_set_base_uri() hardcodes. The fragment can originate from any BibleSync UDP multicast peer on the LAN (biblesync_glue.cc:179 constructs the sword:// URL from peer-supplied bible and ref), from argv[1], or from a sword:// href click inside a malicious SWORD module. Substitute '</' with '<\/' in the already-escaped anchor (OWASP recommendation) so the HTML parser can no longer see the end of the script block. g_strescape is kept in place to also handle the backslash-and-quote break-out case from the prior fix (crosswire#1337).
0d7c0c2 to
d62cddc
Compare
Contributor
Author
|
Dropped the reproducer. |
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.
g_strescape()escapes backslash, double-quote, and C0 control bytes but leaves<,>, and/untouched, so a sword:// fragment of</script><script>PAYLOAD</script>passes through unchanged when interpolated into the inline<script>block inHtmlOutput(). WebKit's HTML parser ends the<script>block at the literal</script>and starts a new<script>PAYLOAD</script>block, which executes arbitrary JavaScript in thefile://origin thatwk_html_set_base_uri()hardcodes.The fragment can originate from any BibleSync UDP multicast peer on the LAN (
biblesync_glue.cc:179constructs the sword:// URL from peer-suppliedbibleandref), fromargv[1], or from a sword:// href click inside a malicious SWORD module.Substitute
</with<\/in the already-escaped anchor (OWASP recommendation) so the HTML parser can no longer see the end of the script block.g_strescapeis kept in place to also handle the backslash-and-quote break-out case from #1337.A self-contained reproducer is in
poc/reproducer.cin this branch: it shows thatg_strescape("</script><script>alert(1)</script>")returns the input unchanged.Follow-up to #1337.