File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import './lib/renderer/lightbox'
28
28
import { renderCSVPreview } from './lib/renderer/csvpreview'
29
29
30
30
import { escapeAttrValue } from './render'
31
+ import { sanitizeUrl } from './utils'
31
32
32
33
import markdownit from 'markdown-it'
33
34
import markdownitContainer from 'markdown-it-container'
@@ -630,10 +631,11 @@ export function finishView (view) {
630
631
view . find ( 'div.pdf.raw' ) . removeClass ( 'raw' )
631
632
. each ( function ( key , value ) {
632
633
const url = $ ( value ) . attr ( 'data-pdfurl' )
634
+ const cleanUrl = sanitizeUrl ( url )
633
635
const inner = $ ( '<div></div>' )
634
636
$ ( this ) . append ( inner )
635
637
setTimeout ( ( ) => {
636
- PDFObject . embed ( url , inner , {
638
+ PDFObject . embed ( cleanUrl , inner , {
637
639
height : '400px'
638
640
} )
639
641
} , 1 )
Original file line number Diff line number Diff line change @@ -26,3 +26,23 @@ export function decodeNoteId (encodedId) {
26
26
idParts . push ( id . substr ( 20 , 12 ) )
27
27
return idParts . join ( '-' )
28
28
}
29
+
30
+ /**
31
+ * sanitize url to prevent XSS
32
+ * @see {@link https://github.com/braintree/sanitize-url/issues/52#issue-1593777166 }
33
+ *
34
+ * @param {string } rawUrl
35
+ * @returns {string } sanitized url
36
+ */
37
+ export function sanitizeUrl ( rawUrl ) {
38
+ try {
39
+ const url = new URL ( rawUrl )
40
+ if ( url . protocol === 'http:' || url . protocol === 'https:' ) {
41
+ return url . toString ( )
42
+ }
43
+
44
+ throw new Error ( 'Invalid protocol' )
45
+ } catch ( error ) {
46
+ return 'about:blank'
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments