Skip to content

Commit

Permalink
new attempt at speaker view xss fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed May 12, 2022
1 parent 0ca3897 commit 4b6ac46
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion plugin/notes/notes.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugin/notes/notes.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugin/notes/plugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import speakerViewHTML from './speaker-view.html';
import speakerViewHTML from './speaker-view.html'

import { marked } from 'marked';

Expand Down
27 changes: 20 additions & 7 deletions plugin/notes/speaker-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@ <h4 class="label">Notes</h4>
layoutDropdown,
pendingCalls = {},
lastRevealApiCallId = 0,
connected = false,
whitelistedWindows = [window.opener];
connected = false

var connectionStatus = document.querySelector( '#connection-status' );

var SPEAKER_LAYOUTS = {
'default': 'Default',
Expand All @@ -362,15 +363,29 @@ <h4 class="label">Notes</h4>

setupLayout();

var connectionStatus = document.querySelector( '#connection-status' );
let openerOrigin;

try {
openerOrigin = window.opener.location.origin;
}
catch ( error ) { console.warn( error ) }

// In order to prevent XSS, the speaker view will only run if its
// opener has the same origin as itself
if( window.location.origin !== openerOrigin ) {
connectionStatus.innerHTML = 'Cross origin error.<br>The speaker window can only be opened from the same origin.';
return;
}

var connectionTimeout = setTimeout( function() {
connectionStatus.innerHTML = 'Error connecting to main window.<br>Please try closing and reopening the speaker view.';
}, 5000 );
;
window.addEventListener( 'message', function( event ) {

// Validate the origin of this message to prevent XSS
if( window.location.origin !== event.origin && whitelistedWindows.indexOf( event.source ) === -1 ) {
// Validate the origin of all messages to avoid parsing messages
// that aren't meant for us
if( window.location.origin !== event.origin ) {
return;
}

Expand Down Expand Up @@ -539,8 +554,6 @@ <h4 class="label">Notes</h4>
upcomingSlide.setAttribute( 'src', upcomingURL );
document.querySelector( '#upcoming-slide' ).appendChild( upcomingSlide );

whitelistedWindows.push( currentSlide.contentWindow, upcomingSlide.contentWindow );

}

/**
Expand Down

0 comments on commit 4b6ac46

Please sign in to comment.