Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.

Commit 01fbe30

Browse files
Merge pull request #121 from sauravbhattacharya001/fix/xss-script-breakout-diff-exporter
fix(security): prevent XSS via script breakout in GraphDiffHtmlExporter
2 parents 49a8d04 + 36f3af5 commit 01fbe30

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

Gvisual/src/gvisual/GraphDiffHtmlExporter.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,21 @@ private static String escapeHtml(String s) {
363363
return s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;");
364364
}
365365

366+
/**
367+
* Escapes a string for safe embedding inside a JavaScript string literal
368+
* within an HTML {@code <script>} block.
369+
*
370+
* <p>In addition to standard JS escapes (backslash, quote, newlines),
371+
* this method encodes {@code <} and {@code >} as hex escapes to prevent
372+
* a malicious vertex/label name containing {@code </script>} from
373+
* breaking out of the script context (CWE-79 / XSS via script breakout).
374+
*/
366375
private static String escapeJs(String s) {
367-
return s.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n").replace("\r", "");
376+
return s.replace("\\", "\\\\")
377+
.replace("\"", "\\\"")
378+
.replace("\n", "\\n")
379+
.replace("\r", "")
380+
.replace("<", "\\x3c")
381+
.replace(">", "\\x3e");
368382
}
369383
}

0 commit comments

Comments
 (0)