postMessage XSS in Tesla Payment page
The Tesla payment page registered a postMessage listener that accepted messages from any origin and used the message's URL to build an auto-submitting form. An attacker could send a crafted message with a javascript: URL to execute arbitrary JavaScript in the context of www.tesla.com.
- Accepted in 9 days
- Fixed in 9 months
- Disclosed after 9 months
Summary by TheTime
postMessage XSS in Tesla's payment pages
Report details
-
Submitted
25 May 2021 16:20:10 UTC
-
Target Location
*.tesla.com -
Target category
Web App
-
VRT
Cross-Site Scripting (XSS) > Reflected > Non-Self
-
Priority
P3
-
Bug URL
https://www.tesla.com/ro_ro/model3/design#payment -
Description
Hey Tesla,
Trying to do bug bounty until I get enough money to buy a Tesla, I stumbled upon a postMessage XSS in the payment page (available when configuring a Tesla car).
This vulnerability occurs because the web page at https://www.tesla.com/ro_ro/model3/design#payment registers an "onmessage" event listener which accepts cross-domain messages from any other domain. Neither the source nor the origin of the received message are checked, so any other domain can send messages using the postMessage API.
Moreover, as shown in the "DOM XSS in form.action.png" attachement, part of the received message (without any additional validation) is used for constructing an auto-submitting form. If the action property of this form is set to a "javascript:" URL, then the JavaScript code specified in it will execute in the security context of www.tesla.com domain.
Please see the attached video POC and screenshots for more details.
postMessage XSS vulnerabilities are not very common, but very similar vulnerabilities have also been found in the past. Example of a write-up of such a vulnerability in Facebook.
In terms of fixing the vulnerability, I recommend taking one or more of the following actions:
- validating that the URL received in the message object is a valid HTTPS url (and maybe a trusted website, to avoid an open redirect vulnerability);
- validating the "message.origin" property to be a trusted Tesla domain;
- validating the "message.source" property to be one of the iframes / tabs which have a business need for communicating with the payment page.
Please let me know if I can be of help with further details.
Thank you, Daniel Tomescu
-
HTTP request
postMessage payload: var payload = { "instanceId": 0, "data":"aaaa", "method":"GET", "url":"javascript:alert(`XSS in the context of: ` + origin)", "type": "redirect" } -
Extra info
This type of XSS allows attackers to execute custom JavaScript code from 3rd party websites inside the security context of the web application at https://www.tesla.com/. This allows attackers to gain access to the victim's web session, to their private details stored in their account or even to their payment details, should the user be tricked to input them during the attack.
I would like to highlight that this type of XSS is bypassing all server-side mitigating controls (user input validation, WAFs etc) because the payload never touches the server. Also, it bypasses client-side protections such as CSP because the XSS payload already executes in a trusted context.
In my CVSS calculation (CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N), I took into account the following:
- this is a 'network' attack since it can be carried over the internet;
- the attack complexity is Low since XSS attacks are fairly well understood and the attack can be automated;
- victim user interaction is required, usually in the form of visiting an attacker-controlled web page;
- The scope is changed - the attacker gains access from its 3rd party website to www.tesla.com domains through the XSS attack.
- The confidentiality impact is high - the attacker can leak the victim user's private details (if logged in), payment details etc.
- The integrity impact is high, since the attacker can fully rewrite the web page at https://www.tesla.com/ro_ro/model3/design#payment through JavaScript in order to serve a completely different purpose; also the attacker can make changes in the victim user's account; I can think of no better phishing page than a genuine Tesla page offering a 99% discount. :)
- I considered the availability impact to be negligible.
Context
The target is the Tesla web application on *.tesla.com, specifically the payment page that appears while configuring a car. The researcher used the Romanian model 3 design page as the entry point:
https://www.tesla.com/ro_ro/model3/design#payment
That page is the payment step of the car configurator. It registers an onmessage event listener so that other windows, typically iframes or tabs involved in the purchase flow, can send it messages with the postMessage API. The listener receives structured messages, and part of the message is used to build a form.
Setup
No accounts, roles, tools or versions are described in the report. The only precondition that matters is that a victim loads the Tesla payment page and that an attacker-controlled page is able to obtain a reference to that window (for example by opening it, or by framing it) so it can call postMessage on it. The researcher submitted the report on 25 May 2021 through Bugcrowd under the Tesla program, with the VRT category Cross-Site XSS > Reflected > Non-Self and priority P3.
Finding it
While going through the payment page, the researcher noticed that the onmessage handler accepts cross-domain messages from any other domain. Neither the source nor the origin of the received message is checked, so any domain can send messages to the page using the postMessage API.
The second half of the bug is what the page does with the message. Part of the received message is used, without any additional validation, to construct an auto-submitting form. The researcher documented this in an attachment named "DOM XSS in form.action.png". If the action property of that form is set to a javascript: URL, the JavaScript in it executes in the security context of the www.tesla.com domain.
Exploitation
Step 1: send a crafted message to the payment page
The attacker page sends a message object to the Tesla payment window. The payload from the report is:
postMessage payload:
var payload = {
"instanceId": 0,
"data":"aaaa",
"method":"GET",
"url":"javascript:alert(`XSS in the context of: ` + origin)",
"type": "redirect"
}
The important field is url. It carries a javascript: URL instead of an HTTPS URL. The type field is set to redirect. instanceId, data and method fill out the rest of the expected message shape. The alert prints the origin of the executing context.
Step 2: the page builds an auto-submitting form
The Tesla page takes the url value from the message and uses it as the action of a form that submits itself. Because the value is not validated, a javascript: URL is accepted as the action. When the form submits, the browser evaluates the JavaScript in the URL in the security context of www.tesla.com.
Step 3: code runs in the Tesla origin
The result is XSS on the payment page. The researcher refers to an attached video proof of concept and screenshots for the full sequence; those attachments are not reproduced here.
Root cause
The onmessage listener on the payment page trusts every message it receives. It does not check message.origin and it does not check message.source, so any domain that can reach the window can drive it. On top of that, the URL taken from the message is placed into a form's action without validation, which turns a javascript: URL into script execution in the Tesla origin.
The researcher notes that this class of XSS bypasses all server-side controls, such as user input validation and WAFs, because the payload never touches the server. It also bypasses client-side protections such as CSP, because the payload executes in an already trusted context.
Impact
An attacker can execute custom JavaScript from a third-party website inside the security context of https://www.tesla.com/. That gives access to the victim's web session and to private details stored in their account, and potentially to payment details if the user is tricked into entering them during the attack. The attacker can also fully rewrite the payment page through JavaScript to serve a different purpose, and can make changes in the victim's account. The researcher's own framing of the phishing angle is a genuine Tesla page offering a 99% discount.
The attack requires victim interaction, usually visiting an attacker-controlled page. The researcher's CVSS 3.0 vector was:
CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N
with network attack, low complexity because XSS is well understood and automatable, required user interaction, changed scope because the attacker reaches www.tesla.com from a third-party site, high confidentiality and integrity impact, and negligible availability impact.
Fix
The researcher recommended one or more of the following:
- Validate that the URL received in the message object is a valid HTTPS URL, and possibly a trusted website, to avoid an open redirect vulnerability.
- Validate the
message.originproperty against a trusted Tesla domain. - Validate the
message.sourceproperty against the iframes or tabs that have a business need to communicate with the payment page.
The report does not describe which of these was implemented.
Variants to test
- Look for
onmessagehandlers on payment and checkout flows that accept a URL or redirect target. A positive result is a handler that acts on a message sent from an unrelated origin. - Send a message whose URL field is a
javascript:URL and watch for an auto-submitting form or a navigation that evaluates it. A positive result is script execution in the target origin.
What happened, in plain words
A security researcher was looking at the payment step of Tesla's online car configurator, the page where you pick options for a car and then reach the part where money would change hands. He found that this page listens for instructions from other web pages, and that it follows those instructions without checking who sent them. One of the instructions it accepts is a web address, and that address is placed into a form that submits itself. If the address starts with javascript: instead of https://, the browser runs the text after it as code, as if Tesla's own site had written that code. That is a cross-site scripting bug, or XSS: a way to make someone else's website run code you supplied.
The researcher reported it through Bugcrowd under the Tesla program on 25 May 2021. The platform filed it under the category Cross-Site Scripting (XSS) > Reflected > Non-Self, with priority P3, and later recorded it as medium severity with a 500.00 USD bounty, disclosed on 22 February 2022.
The page and the feature involved
The target is the Tesla web application on *.tesla.com. The specific page is the payment step that appears while you configure a car. The researcher used the Romanian Model 3 design page as his entry point:
https://www.tesla.com/ro_ro/model3/design#payment
A quick word on that address. tesla.com is the site. ro_ro is a locale marker, here Romanian. model3/design is the configurator for the Model 3. The #payment part at the end is a fragment: it tells the page to jump to, or show, its payment section. Fragments are handled by the browser and are not sent to the server in the request, which matters later.
That page registers an onmessage event listener. To understand what that means, start with the idea of an API. An API is an agreed way for two pieces of software to talk to each other, like a standard order form at a counter: you fill in the fields the counter expects and hand it over. In a browser, the postMessage API is the agreed way for one window, tab or frame to send a message to another. The receiving side subscribes to those messages with an event listener, a piece of code that says "when a message arrives, run this". The listener receives structured messages from other windows, and part of the message is used to build a form.
Setting up
The report describes no accounts, roles, tools or software versions. The only precondition that matters is this: a victim loads the Tesla payment page, and an attacker-controlled page is able to obtain a reference to that window, for example by opening it or by framing it, so that it can call postMessage on it. Think of it as one browser tab being able to hand a note to another tab, provided it knows which tab to hand it to.
Finding it
While going through the payment page, the researcher noticed that the onmessage handler accepts cross-domain messages from any other domain. Neither the source nor the origin of the received message is checked, so any domain can send messages to the page using the postMessage API. "Origin" here means the combination of scheme, host and port that identifies where a page came from, such as https://www.tesla.com. "Source" means the specific window object that sent the message. Checking either one is how a receiver normally decides whether to trust a note. This page checked neither, so it trusted everyone.
The second half of the bug is what the page does with the message. Part of the received message is used, without any additional validation, to construct an auto-submitting form. A form is the part of a web page that collects fields and sends them somewhere when you press a button; its action property is the address it sends them to. An auto-submitting form is one that presses its own button, so to speak, without waiting for a person. The researcher documented this in an attachment named "DOM XSS in form.action.png". If the action property of that form is set to a javascript: URL, the JavaScript in it executes in the security context of the www.tesla.com domain. "Security context" means the browser treats the code as belonging to that site: it can read that site's data and act with that site's permissions. "DOM XSS" means the dangerous value is handled by the page's own script in the browser (the DOM is the browser's in-memory model of the page), rather than being reflected back by the server.
Exploitation
Step 1: send a crafted message to the payment page
The attacker page sends a message object to the Tesla payment window. The payload from the report is:
postMessage payload:
var payload = {
"instanceId": 0,
"data":"aaaa",
"method":"GET",
"url":"javascript:alert(`XSS in the context of: ` + origin)",
"type": "redirect"
}
Line by line:
var payload = {starts a JavaScript object, a bundle of named values, like a filled-in form in memory."instanceId": 0gives the message an instance number. The report does not explain what the receiving page uses it for."data":"aaaa"is a placeholder value for a data field. It carries nothing meaningful."method":"GET"names an HTTP method. GET is the ordinary method a browser uses to ask a server for a page or resource."url":"javascript:alert(XSS in the context of:+ origin)"is the important field. It carries ajavascript:URL instead of an HTTPS URL. Ajavascript:URL is a browser feature: instead of pointing at a document, it contains code, and the browser runs that code when the URL is used. The code here callsalert, which pops up a dialog box, and prints the textXSS in the context of:followed byorigin, the origin of the page that is executing the code. That is the proof: if the dialog sayswww.tesla.com, the code ran as Tesla, not as the attacker."type": "redirect"marks the message as a redirect instruction.}closes the object.
The url field is the one that ends up in the form's action. Sending a javascript: URL there is the whole trick.
Step 2: the page builds an auto-submitting form
The Tesla page takes the url value from the message and uses it as the action of a form that submits itself. Because the value is not validated, a javascript: URL is accepted as the action. When the form submits, the browser evaluates the JavaScript in the URL in the security context of www.tesla.com. The everyday comparison: a receptionist takes a note that says "deliver this parcel to address X" and does not check that X is a real street address. If X says "open this box and follow the instructions inside", the receptionist does that too, on company premises.
Step 3: code runs in the Tesla origin
The result is XSS on the payment page. The researcher refers to an attached video proof of concept and screenshots for the full sequence; those attachments are not reproduced here.
Why this is hard to block with the usual defences
The researcher notes that this class of XSS bypasses all server-side controls, such as user input validation and WAFs, because the payload never touches the server. A WAF, or web application firewall, inspects requests arriving at a server and blocks suspicious ones; here there is nothing to inspect, because the message goes from one browser window to another. It also bypasses client-side protections such as CSP, because the payload executes in an already trusted context. CSP, or Content Security Policy, is a set of rules a site sends to the browser saying which sources of code are allowed; it is designed to stop injected code, but code that the page itself chooses to run through its own form is a different matter.
Impact
An attacker can execute custom JavaScript from a third-party website inside the security context of https://www.tesla.com/. That gives access to the victim's web session and to private details stored in their account, and potentially to payment details if the user is tricked into entering them during the attack. A web session is the state of being logged in: the browser holds a cookie or token, a small piece of data the site gave it after login, and presents it with each request so the site knows who you are. Code running as Tesla can read what the page can read and act as the logged-in user.
The attacker can also fully rewrite the payment page through JavaScript to serve a different purpose, and can make changes in the victim's account. The researcher's own framing of the phishing angle is a genuine Tesla page offering a 99% discount. Phishing means fooling someone into trusting a page or message that is not what it claims to be; here the page really is Tesla's, which makes the deception stronger.
The attack requires victim interaction, usually visiting an attacker-controlled page. The researcher's CVSS 3.0 vector was:
CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N
CVSS is a standard scoring system for vulnerabilities. Each part of that string is a measurement:
AV:Nmeans the attack vector is network: it can be carried over the internet.AC:Lmeans attack complexity is low: XSS is well understood and the attack can be automated.PR:Nmeans no privileges are required: the attacker does not need an account on the target.UI:Rmeans user interaction is required: the victim usually has to visit an attacker-controlled page.S:Cmeans scope is changed: the attacker reacheswww.tesla.comfrom a third-party site, crossing a boundary.C:Hmeans confidentiality impact is high: private details and potentially payment details can leak.I:Hmeans integrity impact is high: the page can be rewritten and the account changed.A:Nmeans availability impact is negligible.
The fix
The researcher recommended one or more of the following:
- Validate that the URL received in the message object is a valid HTTPS URL, and possibly a trusted website, to avoid an open redirect vulnerability. An open redirect is a page that will send visitors to any address someone supplies, which is useful to attackers for disguising links.
- Validate the
message.originproperty against a trusted Tesla domain, so only messages from Tesla's own pages are accepted. - Validate the
message.sourceproperty against the iframes or tabs that have a business need to communicate with the payment page, so only the expected windows are heard.
The report does not describe which of these was implemented.
Variants to test
- Look for
onmessagehandlers on payment and checkout flows that accept a URL or redirect target. A positive result is a handler that acts on a message sent from an unrelated origin. - Send a message whose URL field is a
javascript:URL and watch for an auto-submitting form or a navigation that evaluates it. A positive result is script execution in the target origin.
Glossary
- API: an agreed way for two pieces of software to talk to each other, with defined fields and rules.
- postMessage: a browser API that lets one window, tab or frame send a message to another.
- Event listener: code that waits for something to happen, such as a message arriving, and then runs.
- onmessage: the handler that runs when a window receives a
postMessagemessage. - Origin: the scheme, host and port that identify where a page came from, such as
https://www.tesla.com. - Source (message.source): the specific window object that sent a message.
- Cross-domain: coming from a different site or origin than the one receiving it.
- XSS (cross-site scripting): a bug that lets an attacker get code of their choosing to run in another site's security context.
- DOM XSS: XSS where the dangerous value is handled by the page's own script in the browser, not reflected by the server.
- DOM: the browser's in-memory model of the page, which scripts read and change.
- Security context: the site a piece of code is treated as belonging to, with that site's data and permissions.
- Form: the part of a page that collects fields and sends them somewhere when submitted.
- action (form action): the address a form sends its data to when submitted.
- Auto-submitting form: a form that submits itself without a person pressing a button.
- javascript: URL: a URL that contains code instead of pointing at a document; the browser runs the code when the URL is used.
- alert: a browser function that shows a dialog box with a message.
- HTTP method: the verb of a request, such as GET, which asks for a resource.
- GET: the ordinary HTTP method a browser uses to request a page or resource.
- iframe: a page embedded inside another page.
- Fragment: the
#...part of a URL, handled by the browser and not sent to the server. - Locale: a marker in a URL or page indicating language and region, such as
ro_ro. - WAF (web application firewall): a defence that inspects requests arriving at a server and blocks suspicious ones.
- CSP (Content Security Policy): rules a site sends to the browser saying which sources of code are allowed.
- Cookie / token: a small piece of data a site gives the browser after login and the browser presents with each request, so the site knows who you are.
- Session: the state of being logged in to a site.
- Phishing: fooling someone into trusting a page or message that is not what it claims to be.
- Open redirect: a page that will send visitors to any address someone supplies.
- CVSS: a standard scoring system for vulnerabilities, expressed as a vector string.
- VRT: Bugcrowd's Vulnerability Rating Taxonomy, a standard way of categorising findings.
- P3 / medium severity: priority and severity labels used by the platform to rank the finding.
- Bounty: the money paid to a researcher for a valid report.
- Prefix check: validation that only looks at the start of a string, which can be bypassed by a value that begins with something allowed.