Skip to content

fix: escape HTML content before embedding in JavaScript string in editor_insert_html#1329

Merged
karlkleinpaste merged 1 commit into
crosswire:masterfrom
hyder365:pr-0003-fix-js-injection
Jun 19, 2026
Merged

fix: escape HTML content before embedding in JavaScript string in editor_insert_html#1329
karlkleinpaste merged 1 commit into
crosswire:masterfrom
hyder365:pr-0003-fix-js-injection

Conversation

@hyder365

Copy link
Copy Markdown
Contributor

editor_insert_html() embeds user-controlled HTML (e.g. the link text
from the link dialog) into a JavaScript string literal that is then
executed via webkit_web_view_execute_script():

document.execCommand('insertHTML', null, '%s');

Neither single quotes nor backslashes were escaped, so a single quote
in the input broke out of the JS string and allowed arbitrary script
execution in the editor's WebKit context.

Escape the content with g_strescape() before embedding. g_strescape()
escapes backslashes, double quotes and control characters, but it does
NOT escape single quotes -- so the JS string literal is changed from
single-quoted to double-quoted to match what g_strescape() actually
escapes. This blocks both ' and " breakout while preserving legitimate
HTML markup (e.g. quoted href attributes).

…tor_insert_html

editor_insert_html() embeds user-controlled HTML (e.g. the link text from
the link dialog) into a JavaScript string literal that is then executed via
webkit_web_view_execute_script():

    document.execCommand('insertHTML', null, '%s');

Neither single quotes nor backslashes were escaped, so a single quote in the
input broke out of the JS string and allowed arbitrary script execution in
the editor's WebKit context.

Escape the content with g_strescape() before embedding.  g_strescape()
escapes backslashes, double quotes and control characters, but it does NOT
escape single quotes -- so the JS string literal is changed from
single-quoted to double-quoted to match what g_strescape() actually escapes.
This blocks both ' and " breakout while preserving legitimate HTML markup
(e.g. quoted href attributes).
@karlkleinpaste karlkleinpaste merged commit 9288b26 into crosswire:master Jun 19, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants