Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/lib/browser/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,23 @@
return await promiseWithTimeout(
(async (): Promise<string | null> => {
const start = Date.now();
const content = await this.#ref?.content();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const content = await this.#ref?.evaluate(() => {
const doctype = document.doctype
? new XMLSerializer().serializeToString(document.doctype)
: '';
// https://html.spec.whatwg.org/#dom-parsing-and-serialization
if (!('getHTML' in Element.prototype)) {
return `${doctype}${document.documentElement.outerHTML}`;
}
const body = (document.body as any).getHTML({ serializableShadowRoots: true });
const uid = crypto.randomUUID();
document.body.innerHTML = uid;

Check failure on line 284 in src/lib/browser/Page.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/lib/browser/Page.ts#L284

User controlled data in a `document.body.innerHTML` is an anti-pattern that can lead to XSS vulnerabilities

Check failure on line 284 in src/lib/browser/Page.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/lib/browser/Page.ts#L284

User controlled data in methods like `innerHTML`, `outerHTML` or `document.write` is an anti-pattern that can lead to XSS vulnerabilities
return `${doctype}${document.documentElement.outerHTML.replace(
uid,
body
)}`;
});

stats.timing('renderscript.renderBody', Date.now() - start, {
browser: this.#engine as string,
});
Expand Down