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

fix: XSS injection with Querybook RichTextEditor #1412

Merged
merged 1 commit into from
Feb 21, 2024
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "querybook",
"version": "3.31.0",
"version": "3.31.1",
"description": "A Big Data Webapp",
"private": true,
"scripts": {
Expand Down
22 changes: 19 additions & 3 deletions querybook/webapp/lib/richtext/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as DraftJs from 'draft-js';
import type { Stack } from 'immutable';
import React from 'react';
import React, { useMemo } from 'react';

import { Link } from 'ui/Link/Link';

Expand All @@ -10,9 +10,25 @@ interface IUrlLinkProps {
}

const UrlLink: React.FunctionComponent<IUrlLinkProps> = (props) => {
const { url } = props.contentState.getEntity(props.entityKey).getData();
const { url }: { url: string } = props.contentState
.getEntity(props.entityKey)
.getData();
const sanitizedUrl = useMemo(() => {
// sanitize URL to prevent XSS
try {
const urlObj = new URL(url);
if (['http:', 'https:'].includes(urlObj.protocol)) {
return urlObj.href;
} else {
return undefined;
}
} catch (error) {
return undefined;
}
}, [url]);

return (
<Link to={url} newTab>
<Link to={sanitizedUrl ?? 'about:blank'} newTab>
{props.children}
</Link>
);
Expand Down
Loading