Skip to content

Commit 3dade61

Browse files
committed
notes plugin only listens for same-origin postmessages to prevent xss
1 parent 4b6ac46 commit 3dade61

9 files changed

+36
-21
lines changed

dist/reveal.esm.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/reveal.esm.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/reveal.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/reveal.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/utils/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const HORIZONTAL_SLIDES_SELECTOR = '.slides>section';
44
export const VERTICAL_SLIDES_SELECTOR = '.slides>section.present>section';
55

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

99
// Regex for retrieving the fragment style from a class attribute
1010
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/;

plugin/notes/notes.esm.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/notes/notes.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/notes/plugin.js

+28-7
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,36 @@ const Plugin = () => {
151151

152152
}
153153

154-
function onPostMessage( event ) {
154+
/**
155+
* Check if the given event is from the same origin as the
156+
* current window.
157+
*/
158+
function isSameOriginEvent( event ) {
155159

156-
let data = JSON.parse( event.data );
157-
if( data && data.namespace === 'reveal-notes' && data.type === 'connected' ) {
158-
clearInterval( connectInterval );
159-
onConnected();
160+
try {
161+
return window.location.origin === event.source.location.origin;
160162
}
161-
else if( data && data.namespace === 'reveal-notes' && data.type === 'call' ) {
162-
callRevealApi( data.methodName, data.arguments, data.callId );
163+
catch ( error ) {
164+
return false;
165+
}
166+
167+
}
168+
169+
function onPostMessage( event ) {
170+
171+
// Only allow same-origin messages
172+
// (added 12/5/22 as a XSS safeguard)
173+
if( isSameOriginEvent( event ) ) {
174+
175+
let data = JSON.parse( event.data );
176+
if( data && data.namespace === 'reveal-notes' && data.type === 'connected' ) {
177+
clearInterval( connectInterval );
178+
onConnected();
179+
}
180+
else if( data && data.namespace === 'reveal-notes' && data.type === 'call' ) {
181+
callRevealApi( data.methodName, data.arguments, data.callId );
182+
}
183+
163184
}
164185

165186
}

plugin/notes/speaker-view.html

+1-7
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,8 @@ <h4 class="label">Notes</h4>
380380
var connectionTimeout = setTimeout( function() {
381381
connectionStatus.innerHTML = 'Error connecting to main window.<br>Please try closing and reopening the speaker view.';
382382
}, 5000 );
383-
;
384-
window.addEventListener( 'message', function( event ) {
385383

386-
// Validate the origin of all messages to avoid parsing messages
387-
// that aren't meant for us
388-
if( window.location.origin !== event.origin ) {
389-
return;
390-
}
384+
window.addEventListener( 'message', function( event ) {
391385

392386
clearTimeout( connectionTimeout );
393387
connectionStatus.style.display = 'none';

0 commit comments

Comments
 (0)