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'
2828import { renderCSVPreview } from './lib/renderer/csvpreview'
2929
3030import { escapeAttrValue } from './render'
31+ import { sanitizeUrl } from './utils'
3132
3233import markdownit from 'markdown-it'
3334import markdownitContainer from 'markdown-it-container'
@@ -630,10 +631,11 @@ export function finishView (view) {
630631 view . find ( 'div.pdf.raw' ) . removeClass ( 'raw' )
631632 . each ( function ( key , value ) {
632633 const url = $ ( value ) . attr ( 'data-pdfurl' )
634+ const cleanUrl = sanitizeUrl ( url )
633635 const inner = $ ( '<div></div>' )
634636 $ ( this ) . append ( inner )
635637 setTimeout ( ( ) => {
636- PDFObject . embed ( url , inner , {
638+ PDFObject . embed ( cleanUrl , inner , {
637639 height : '400px'
638640 } )
639641 } , 1 )
Original file line number Diff line number Diff line change @@ -26,3 +26,23 @@ export function decodeNoteId (encodedId) {
2626 idParts . push ( id . substr ( 20 , 12 ) )
2727 return idParts . join ( '-' )
2828}
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