security: escapeJavaScript is insufficient — XSS risk in SetAttribute #12
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Parent: #2
Description
In
node.go:107-113,escapeJavaScript()only escapes\and'characters:This is missing escapes for:
\n,\r) — can break the string literal\0) — can terminate strings early</script>sequences — could break out of script tags") — while not used in the current template, defensive escaping is good practiceIf user-controlled input flows through
SetAttribute, this could allow JavaScript injection in the browser context.Fix
Replace with a proper JavaScript string escaper:
Or better yet, pass
nameandvalueas PlaywrightEvaluatearguments instead of string interpolation:Starting work on this. Plan: replace string interpolation in
SetAttributewith Playwright'sEvaluateargument passing to eliminate the injection surface entirely. Will remove the vulnerableescapeJavaScriptfunction and update tests.Work finished. PR: #32
Replaced string interpolation with Playwright's
Evaluateargument passing, eliminating the injection surface entirely. Removed the vulnerableescapeJavaScripthelper.