File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed
querybook/webapp/lib/richtext Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " querybook" ,
3
- "version" : " 3.31.0 " ,
3
+ "version" : " 3.31.1 " ,
4
4
"description" : " A Big Data Webapp" ,
5
5
"private" : true ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change 1
1
import * as DraftJs from 'draft-js' ;
2
2
import type { Stack } from 'immutable' ;
3
- import React from 'react' ;
3
+ import React , { useMemo } from 'react' ;
4
4
5
5
import { Link } from 'ui/Link/Link' ;
6
6
@@ -10,9 +10,25 @@ interface IUrlLinkProps {
10
10
}
11
11
12
12
const UrlLink : React . FunctionComponent < IUrlLinkProps > = ( props ) => {
13
- const { url } = props . contentState . getEntity ( props . entityKey ) . getData ( ) ;
13
+ const { url } : { url : string } = props . contentState
14
+ . getEntity ( props . entityKey )
15
+ . getData ( ) ;
16
+ const sanitizedUrl = useMemo ( ( ) => {
17
+ // sanitize URL to prevent XSS
18
+ try {
19
+ const urlObj = new URL ( url ) ;
20
+ if ( [ 'http:' , 'https:' ] . includes ( urlObj . protocol ) ) {
21
+ return urlObj . href ;
22
+ } else {
23
+ return undefined ;
24
+ }
25
+ } catch ( error ) {
26
+ return undefined ;
27
+ }
28
+ } , [ url ] ) ;
29
+
14
30
return (
15
- < Link to = { url } newTab >
31
+ < Link to = { sanitizedUrl ?? 'about:blank' } newTab >
16
32
{ props . children }
17
33
</ Link >
18
34
) ;
You can’t perform that action at this time.
0 commit comments