Skip to content

Commit

Permalink
notes plugin only listens for same-origin postmessages to prevent xss
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed May 12, 2022
1 parent 4b6ac46 commit 3dade61
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dist/reveal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const HORIZONTAL_SLIDES_SELECTOR = '.slides>section';
export const VERTICAL_SLIDES_SELECTOR = '.slides>section.present>section';

// Methods that may not be invoked via the postMessage API
export const POST_MESSAGE_METHOD_BLACKLIST = /registerPlugin|registerKeyboardShortcut|addKeyBinding|addEventListener/;
export const POST_MESSAGE_METHOD_BLACKLIST = /registerPlugin|registerKeyboardShortcut|addKeyBinding|addEventListener|showPreview/;

// Regex for retrieving the fragment style from a class attribute
export const FRAGMENT_STYLE_REGEX = /fade-(down|up|right|left|out|in-then-out|in-then-semi-out)|semi-fade-out|current-visible|shrink|grow/;
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.

35 changes: 28 additions & 7 deletions plugin/notes/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,36 @@ const Plugin = () => {

}

function onPostMessage( event ) {
/**
* Check if the given event is from the same origin as the
* current window.
*/
function isSameOriginEvent( event ) {

let data = JSON.parse( event.data );
if( data && data.namespace === 'reveal-notes' && data.type === 'connected' ) {
clearInterval( connectInterval );
onConnected();
try {
return window.location.origin === event.source.location.origin;
}
else if( data && data.namespace === 'reveal-notes' && data.type === 'call' ) {
callRevealApi( data.methodName, data.arguments, data.callId );
catch ( error ) {
return false;
}

}

function onPostMessage( event ) {

// Only allow same-origin messages
// (added 12/5/22 as a XSS safeguard)
if( isSameOriginEvent( event ) ) {

let data = JSON.parse( event.data );
if( data && data.namespace === 'reveal-notes' && data.type === 'connected' ) {
clearInterval( connectInterval );
onConnected();
}
else if( data && data.namespace === 'reveal-notes' && data.type === 'call' ) {
callRevealApi( data.methodName, data.arguments, data.callId );
}

}

}
Expand Down
8 changes: 1 addition & 7 deletions plugin/notes/speaker-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,8 @@ <h4 class="label">Notes</h4>
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 all messages to avoid parsing messages
// that aren't meant for us
if( window.location.origin !== event.origin ) {
return;
}
window.addEventListener( 'message', function( event ) {

clearTimeout( connectionTimeout );
connectionStatus.style.display = 'none';
Expand Down

0 comments on commit 3dade61

Please sign in to comment.