Skip to content

Commit

Permalink
Merge pull request #3548 from hackmdio/fix/xss-on-data-background-vid…
Browse files Browse the repository at this point in the history
…eo-attribute

fix: use `setAttribute` instead of `innerHTML` to prevent XSS
  • Loading branch information
hakimel authored Dec 15, 2023
2 parents 993b8f3 + 89ab00a commit 767a67e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions js/controllers/slidecontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,15 @@ export default class SlideContent {

// Support comma separated lists of video sources
backgroundVideo.split( ',' ).forEach( source => {
const sourceElement = document.createElement( 'source' );
sourceElement.setAttribute( 'src', source );

let type = getMimeTypeFromFile( source );
if( type ) {
video.innerHTML += `<source src="${source}" type="${type}">`;
}
else {
video.innerHTML += `<source src="${source}">`;
sourceElement.setAttribute( 'type', type );
}

video.appendChild( sourceElement );
} );

backgroundContent.appendChild( video );
Expand Down

0 comments on commit 767a67e

Please sign in to comment.