Skip to content

Commit c416542

Browse files
committed
Add stricter CSP to DOM render
1 parent 2a50756 commit c416542

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

assets/js/ezxss4.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,16 @@ const EzXSS = {
642642
handleDOMRender() {
643643
try {
644644
const domContent = $('#dom').val();
645-
const byteCharacters = unescape(encodeURIComponent(domContent));
645+
const parser = new DOMParser();
646+
const doc = parser.parseFromString(domContent, 'text/html');
647+
const meta = doc.createElement('meta');
648+
meta.httpEquiv = 'Content-Security-Policy';
649+
meta.content = "default-src 'none'; script-src 'none'; connect-src 'none'; img-src data:; style-src 'unsafe-inline';";
650+
doc.head.appendChild(meta);
651+
652+
const serializer = new XMLSerializer();
653+
const safeContent = serializer.serializeToString(doc);
654+
const byteCharacters = unescape(encodeURIComponent(safeContent));
646655
const byteArrays = [];
647656

648657
for (let offset = 0; offset < byteCharacters.length; offset += 1024) {

0 commit comments

Comments
 (0)