Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize docs content to prevent XSS #6670

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/docs-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@blueprintjs/select": "workspace:^",
"@documentalist/client": "^5.0.0",
"classnames": "^2.3.1",
"dompurify": "^3.0.8",
"fuzzaldrin-plus": "^0.6.0",
"tslib": "~2.6.2"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/docs-theme/src/components/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as React from "react";
import { Classes, Code, H3 } from "@blueprintjs/core";

import type { TagRendererMap } from "../tags";
import DOMPurify from "dompurify";

export function renderBlock(
/** the block to render */
Expand All @@ -36,7 +37,8 @@ export function renderBlock(
const textClasses = classNames(Classes.RUNNING_TEXT, textClassName);
const contents = block.contents.map((node, i) => {
if (typeof node === "string") {
return <div className={textClasses} key={i} dangerouslySetInnerHTML={{ __html: node }} />;
const sanitizedNode = DOMPurify.sanitize(node);
return <div className={textClasses} key={i} dangerouslySetInnerHTML={{ __html: sanitizedNode }} />;
}
try {
const renderer = tagRenderers[node.tag];
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ __metadata:
"@documentalist/client": "npm:^5.0.0"
"@types/fuzzaldrin-plus": "npm:~0.6.5"
classnames: "npm:^2.3.1"
dompurify: "npm:^3.0.8"
fuzzaldrin-plus: "npm:^0.6.0"
npm-run-all: "npm:^4.1.5"
react: "npm:^16.14.0"
Expand Down Expand Up @@ -6436,6 +6437,13 @@ __metadata:
languageName: node
linkType: hard

"dompurify@npm:^3.0.8":
version: 3.0.8
resolution: "dompurify@npm:3.0.8"
checksum: e89e03d3dbd99abd64cd90705ce2cdfbc60ee9726ee53f9860e8a2d91b828ef2c173e7031529f9a3aa169ad0fbb76115c6a6683b545bf1ac5d94cc6176fb2a50
languageName: node
linkType: hard

"domutils@npm:^1.7.0":
version: 1.7.0
resolution: "domutils@npm:1.7.0"
Expand Down