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 HTML messages #25

Closed
coyotte508 opened this issue Apr 19, 2023 · 1 comment · Fixed by #40
Closed

Sanitize HTML messages #25

coyotte508 opened this issue Apr 19, 2023 · 1 comment · Fixed by #40
Assignees
Labels

Comments

@coyotte508
Copy link
Member

coyotte508 commented Apr 19, 2023

Either before or after the call to marked.

We probably need to load something like jsdom on the backend (but not the frontend) for dompurify to work.

Inspiration from hub code:

let purify: createDOMPurify.DOMPurifyI;

async function loadDOMPurify() {
	if (purify) {
		return;
	}
	if (typeof window === "undefined") {
		/// To avoid needing the dependency on the frontend, we load it dynamically on the backend
		// eslint-disable-next-line @typescript-eslint/no-shadow
		const { JSDOM } = await import("jsdom");
		purify = createDOMPurify(new JSDOM().window as unknown as Window);
	} else {
		purify = createDOMPurify(window);
	}
@coyotte508
Copy link
Member Author

coyotte508 commented Apr 20, 2023

(maybe simply replacing all < by &lt; before markdown would be enough, IDK)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants