Skip to content

Commit

Permalink
fix: XSS injection with Querybook RichTextEditor (#1412)
Browse files Browse the repository at this point in the history
  • Loading branch information
czgu authored Feb 21, 2024
1 parent 34cb6d3 commit bc620da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
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

0 comments on commit bc620da

Please sign in to comment.