Unintended-Control-Over-The-Email-Body-In-Partner-Integration-Email-Instructions/
The partner integration email feature allowed users to control fields beyond the intended personal message, such as partner name and business name, which changed the email body. An attacker could send emails with malicious content that appeared to come from Facebook.
Published on philippeharewood.com
Within Partner Integrations in Business Manager for pixels, allows the ability to email users with instructions for setting up a pixel. A user can also add a personal message.
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
Business Manager includes Partner Integrations for pixels. One of the features there lets a user email another person a set of instructions for setting up a pixel, and the sender can attach a personal message to that email. The email is assembled server side from a set of fields, and the recipient receives what looks like a Facebook email.
The report looks at the endpoint that delivers those instructions and at how much of the resulting email body a sender can actually influence.
Setup
The report does not describe any special account setup, roles or tooling. The only precondition visible in the text is access to the Partner Integrations pixel flow in Business Manager, from which the instruction email is sent. The researcher used his own address as the recipient while testing.
Finding it
The researcher's starting assumption was that only two fields in the request should be modifiable by the sender: personal_message, which is the intended free-text area, and to_emails, which selects the recipient. Everything else in the request is meant to be filled in by the application.
Looking at the request that delivers the instructions, he found that several other fields were accepted from the client and used when building the email body. That meant the sender could place content into parts of the email that were not designed to carry user text.
Exploitation
Step 1: capture the delivery request
The instruction email is delivered by a POST to the following path:
POST /mhub/tracking-instruction-delivery/
The body of the request carries the CMS identifiers, the partner and business names, the pixel identifier, the personal message, the sender name, the locale, the reply-to address and the recipient list:
{
cms_body_id: '11',
cms_params: {
'partner_name': 'Life, Soul and Bank',
'business_name': 'This is a custom message from phwd controlling the body of the message in an unintended way. Normally the message should appear in the personal_message field. Would you like to watch a Youtube video by Bruno Mars and Cardi B? https://www.youtube.com/watch?v=LsoLEjrDogU. Facebook',
'pixel_id': 'https://www.youtube.com/watch?v=LWpYaXYsPvA',
'personal_message': 'This is the personal_message field, where it\'s intended to place the content https://www.youtube.com/watch?v=uo14xGYwWd4'
},
cms_subject_id: '22',
from_name: 'phwd',
locale: 'en_US',
reply_to_email: '[redacted]',
to_emails: ['[redacted]']
}
In this payload the business_name value is a full sentence that reads as a message to the recipient, and both business_name and pixel_id carry YouTube links. The personal_message value holds its own link and states that this is the field where content is intended to go. The to_emails array points at the researcher's own address.
Step 2: change the recipient and observe the result
The researcher changed to_emails to his own address and sent the request. The screenshot shows the injected text appearing in the body of the message. The business_name sentence appeared in the body of the message, which is the unintended placement: normally that text should appear only in the personal_message field.
Step 3: map which fields are accepted
Having confirmed that the body could be influenced, the researcher enumerated the fields that the endpoint would take from the client. Beyond personal_message and to_emails, the following could be changed:
partner_namebusiness_namepixel_idcms_body_id, to an extent: a valid CMSObject is required, and changing it replaces the entire body, so the other fields are then not used.
The report includes a capture of the pixel_id value:
The report includes a separate capture of the personal_message field:
Root cause
The endpoint accepts several CMS parameters from the client, and changing them changes the email body. The sender is therefore able to write into template slots such as partner_name, business_name and pixel_id that were never meant to be user-controlled. The report does not describe the server-side code, so the exact validation gap is not stated;
The cms_body_id field selects which CMS body is used. Changing the body id requires a valid CMSObject and swaps out the whole body, which is why the researcher describes that path as only partially useful: the other injected fields would no longer be rendered.
Impact
An attacker could send emails containing malicious content to other users, and those emails would appear to come from Facebook, with the relevant DKIM and SPF checks passing.
The researcher explicitly reduced the assessed amount to account for the fact that only a portion of the email is customisable: the injected content sits in specific fields of the template rather than replacing the whole message.
Fix
Facebook fixed the issue on 26 January 2018, two weeks after the report was sent and after further investigation on 12 January 2018. A bounty was awarded on 31 January 2018.
Variants to test
- On other platforms with templated notification emails, intercept the delivery request and try writing into every field of the template parameters object, not just the free-text one. A positive result is your text appearing in a part of the received email outside the intended message area.
- Try URL values in identifier fields such as a pixel or object id. A positive result is the link being rendered as a clickable link in the email body.
- Try changing the template or body identifier to another valid object. A positive result is a different template being rendered with your parameters, or an error that reveals which identifiers are valid.
- Send to an address you control and check the authentication results on the received message. A positive result is the message passing DKIM and SPF for the target domain while carrying your injected content.
What happened, in plain words
Facebook runs a tool for businesses called Business Manager. Inside it there is a section called Partner Integrations, and one of the things it does is let a business send an email to someone else with instructions for setting up a "pixel". A pixel is a small piece of code that a business puts on its website so that Facebook can tell when visitors do things there, such as viewing a page or buying something. The instruction email explains how to install that code.
When a business sends this email, it can also add a short personal note. The email is put together by Facebook's computers, not by the sender's browser, and it arrives looking like a normal message from Facebook.
The researcher, Philippe Harewood, looked at the request that the browser sends when this email is triggered. He expected that only two things in that request could be changed by the sender: the personal note and the recipient's address. Everything else, he assumed, was filled in by Facebook from its own records. He found that several more fields were accepted from the browser and used to build the email. That meant a sender could write text into parts of the email that were never meant to carry the sender's words.
This is a beginner's walkthrough of what he found, in the order he found it.
Background concepts
Before the steps, a few ideas that come up throughout.
- Request: when you use a website, your browser constantly sends small messages to the website's computers asking for things or telling them things. Each of those messages is a request. When you fill in a form and press a button, your browser sends a request containing what you typed.
- Endpoint: the specific address (a path on the server) that a request is sent to. Think of a large office building: the building is the website, and each endpoint is a particular desk inside it that handles one kind of request. The endpoint in this report is the desk that handles "send the pixel instruction email".
- API: the set of endpoints and rules a website offers so that software can talk to it. It is like a restaurant menu: it lists what you can ask for and how to ask for it. The browser uses the same menu as any other program would.
- POST: one of the types of request. A GET request is like asking to read a page; a POST request is like submitting a form, carrying data along with it. The email delivery here is a POST because the browser is sending data (the email contents) to the server.
- Field / parameter: one named piece of data inside a request. If a request is a form with boxes, each box has a label (the field name) and contents (the value).
personal_messageis a field; its value is whatever the sender typed. - Server side: work done on the website's own computers rather than in your browser. When something is assembled server side, the website's computers build it, which is why the result can be trusted to look official.
- CMS: short for content management system, software that stores reusable templates (for example, the layout of an email) so the same design can be filled with different content each time. Here, the email body and subject come from CMS templates identified by numbers.
- Template slot: a named gap in a template that gets filled with a value. A birthday card template might have a slot for the name; this email template has slots for the partner name, the business name and so on.
- DKIM and SPF: two checks that email providers use to confirm that a message really came from the domain it claims to come from. SPF checks that the computer that sent the message is allowed to send mail for that domain; DKIM attaches a cryptographic signature that the receiving side can verify. When both pass, the message is much harder to dismiss as a forgery.
- Bounty: a reward a company pays to someone who reports a security problem to it responsibly.
The setup
The report does not describe any special account setup, roles or tools. The only precondition visible in the text is access to the Partner Integrations pixel flow in Business Manager, from which the instruction email is sent. While testing, the researcher used his own address as the recipient.
Finding it
The researcher's starting assumption was that only two fields in the request should be modifiable by the sender:
personal_message, the intended free-text area where the sender writes their note.to_emails, which selects who receives the email.
Everything else in the request, he assumed, was meant to be filled in by the application itself, from Facebook's own records about the pixel and the partner.
Looking at the request that delivers the instructions, he found that several other fields were accepted from the client and used when building the email body. "Client" here means the browser, that is, the sender's side. That meant the sender could place content into parts of the email that were not designed to carry user text.
Exploitation
Step 1: capture the delivery request
The instruction email is delivered by a POST to the following path:
POST /mhub/tracking-instruction-delivery/
Reading that line: POST is the type of request (submitting data), and /mhub/tracking-instruction-delivery/ is the endpoint, the desk inside Facebook's systems that handles sending the tracking (pixel) instruction email. "Capture" means recording this request as the browser sends it, so it can be inspected and later re-sent with changes. Browsers have built-in developer tools that show every request a page makes, which is how a request like this is seen in the first place.
The body of the request carries the CMS identifiers, the partner and business names, the pixel identifier, the personal message, the sender name, the locale, the reply-to address and the recipient list:
{
cms_body_id: '11',
cms_params: {
'partner_name': 'Life, Soul and Bank',
'business_name': 'This is a custom message from phwd controlling the body of the message in an unintended way. Normally the message should appear in the personal_message field. Would you like to watch a Youtube video by Bruno Mars and Cardi B? https://www.youtube.com/watch?v=LsoLEjrDogU. Facebook',
'pixel_id': 'https://www.youtube.com/watch?v=LWpYaXYsPvA',
'personal_message': 'This is the personal_message field, where it\'s intended to place the content https://www.youtube.com/watch?v=uo14xGYwWd4'
},
cms_subject_id: '22',
from_name: 'phwd',
locale: 'en_US',
reply_to_email: '[redacted]',
to_emails: ['[redacted]']
}
Line by line, in plain words:
- The whole block is one object, a collection of labelled values, written in a JavaScript-like notation. Curly braces group things together, and each entry is a label followed by a colon and a value.
cms_body_id: '11'selects which CMS template is used for the body of the email. The number 11 identifies one particular stored layout.cms_params: { ... }is a nested group: the values that get poured into the template's slots. Everything inside its own braces belongs to it.partner_name: 'Life, Soul and Bank'is the slot meant to hold the name of the partner business.business_nameis the slot meant to hold the business's name. In this payload its value is a full sentence that reads as a message to the recipient, and it ends with the wordFacebook. That sentence is the researcher's test: if it shows up in the email body, the slot is under his control.pixel_idis the slot meant to hold the identifier of the pixel. Here its value is a YouTube link, again as a test: if a link appears where an identifier should be, the slot is under his control.personal_messageholds its own link and states that this is the field where content is intended to go. This is the one slot that is supposed to accept the sender's words.cms_subject_id: '22'selects which CMS template is used for the subject line of the email.from_name: 'phwd'is the name shown as the sender.locale: 'en_US'says which language and regional variant the email should use (here, US English).reply_to_email: '[redacted]'is the address that replies should go to.to_emails: ['[redacted]']is the list of recipients. The square brackets mean a list, and this list has one address in it. In the test, this is the researcher's own address.
So in this payload the business_name value is a full sentence that reads as a message to the recipient, and both business_name and pixel_id carry YouTube links. The personal_message value holds its own link and states that this is the field where content is intended to go. The to_emails array points at the researcher's own address.
Step 2: change the recipient and observe the result
The researcher changed to_emails to his own address and sent the request. Sending it to himself is the safe way to test: nothing reaches a stranger, and he can open the message and see exactly what a recipient would see.
The screenshot shows the injected text appearing in the body of the message. The business_name sentence appeared in the body of the message, which is the unintended placement: normally that text should appear only in the personal_message field.
Step 3: map which fields are accepted
Having confirmed that the body could be influenced, the researcher enumerated the fields that the endpoint would take from the client. "Enumerating" means going through the list one by one and testing each, to find out exactly which ones the server accepts. Beyond personal_message and to_emails, the following could be changed:
partner_namebusiness_namepixel_idcms_body_id, to an extent: a valid CMSObject is required, and changing it replaces the entire body, so the other fields are then not used.
That last point needs unpacking. A CMSObject is a stored template object in the CMS, identified by a number. The body id points at one of these. If you change the body id, you are not editing a slot inside the template; you are swapping the whole template for a different one. The other injected fields only make sense inside the original template, so once the template is swapped they are no longer rendered. That is why the researcher describes this path as only partially useful.
The report includes a capture of the pixel_id value:
The report includes a separate capture of the personal_message field:
Why it worked
The endpoint accepts several CMS parameters from the client, and changing them changes the email body. In everyday terms: the restaurant kitchen took the customer's word for what ingredients were in the dish, instead of checking its own stock records. The sender is therefore able to write into template slots such as partner_name, business_name and pixel_id that were never meant to be user-controlled.
The report does not describe the server-side code, so the exact validation gap is not stated.
The cms_body_id field selects which CMS body is used. Changing the body id requires a valid CMSObject and swaps out the whole body, which is why the researcher describes that path as only partially useful: the other injected fields would no longer be rendered.
Impact
An attacker could send emails containing malicious content to other users, and those emails would appear to come from Facebook, with the relevant DKIM and SPF checks passing. In other words, the email is not a lookalike sent from a random server; it is a real Facebook email, with the attacker's words placed in it.
The researcher explicitly reduced the assessed amount to account for the fact that only a portion of the email is customisable: the injected content sits in specific fields of the template rather than replacing the whole message. The recipient still sees a genuine instruction email, with attacker-chosen text in some of its slots.
Fix and timeline
Facebook fixed the issue on 26 January 2018, two weeks after the report was sent and after further investigation on 12 January 2018. A bounty was awarded on 31 January 2018.
In the restaurant comparison: the kitchen checks its own stock records instead of believing the customer's description of the ingredients.
Variants to test
Each one is a way of asking the same question: does the server trust data from the browser that it should be filling in itself?
- On other platforms with templated notification emails, intercept the delivery request and try writing into every field of the template parameters object, not just the free-text one. A positive result is your text appearing in a part of the received email outside the intended message area.
- Try URL values in identifier fields such as a pixel or object id. A positive result is the link being rendered as a clickable link in the email body.
- Try changing the template or body identifier to another valid object. A positive result is a different template being rendered with your parameters, or an error that reveals which identifiers are valid.
- Send to an address you control and check the authentication results on the received message. A positive result is the message passing DKIM and SPF for the target domain while carrying your injected content.
Glossary
- API: the set of endpoints and rules a website offers so that software (including your browser) can talk to it.
- Business Manager: Facebook's tool for businesses to manage their pages, ad accounts and related settings.
- Client: the sender's side, normally the browser, as opposed to the server.
- CMS: content management system, software that stores reusable templates so the same design can be filled with different content.
- CMSObject: a stored template object in the CMS, identified by a number, such as the one selected by
cms_body_id. - DKIM: an email check that verifies a cryptographic signature attached to a message, confirming it came from the domain it claims.
- Endpoint: the specific address on a server that handles one kind of request.
- Field / parameter: one named piece of data inside a request, like a labelled box on a form.
- GET: a type of request used to read something, as opposed to POST which submits data.
- Locale: the language and regional variant used, such as
en_USfor US English. - Partner Integrations: the Business Manager section that includes the pixel instruction email feature.
- Pixel: a small piece of code placed on a website so that Facebook can tell when visitors do things there.
- POST: a type of request that carries data to the server, like submitting a form.
- Request: a message your browser sends to a website's computers asking for something or telling them something.
- SPF: an email check that confirms the computer that sent a message is allowed to send mail for the domain it claims.
- Template slot: a named gap in a template that gets filled with a value, such as the partner name slot in the email body.