fix: sanitize <script> in __FRSH_STATE state (#739)
This commit escapes `<` `>` and related characters in the serialized state that is encoded into the `<script id=__FRSH_STATE>` tag. This prevents XSS attack occuring through injection of a `</script>` string in island props.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { htmlEscapeJsonString } from "./htmlescape.ts";
|
||||
import { assertEquals } from "../../tests/deps.ts";
|
||||
|
||||
Deno.test("with angle brackets should escape", () => {
|
||||
const evilObj = { evil: "<script></script>" };
|
||||
assertEquals(
|
||||
htmlEscapeJsonString(JSON.stringify(evilObj)),
|
||||
'{"evil":"\\u003cscript\\u003e\\u003c/script\\u003e"}',
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("with angle brackets should parse back", () => {
|
||||
const evilObj = { evil: "<script></script>" };
|
||||
assertEquals(
|
||||
JSON.parse(htmlEscapeJsonString(JSON.stringify(evilObj))),
|
||||
evilObj,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user