Facebook Bypass Ads Account Roles
The backend endpoint for adding users to a Facebook ad account did not check whether the requester had permission to assign higher roles. A user with Analyst access could call the endpoint directly and add a user as an administrator, escalating privileges.
Published on blog.darabi.me
I discovered an authorization vulnerability in Facebook Ads Manager that allowed a user with limited access to an ad account to escalate privileges and gain administrator access.
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
Facebook Ads Manager let businesses share ad accounts with other people and with other business accounts through Facebook Business Manager. Each person or business granted access held a role that defined what they could do on the ad account. The roles described in the report are:
- Admin
- Advertiser
- Analyst
The point of the feature is delegation with limits: an organisation can hand an agency access to an ad account at a restricted level, for example Analyst only, and the agency is expected to stay within the capabilities the owner assigned. The vulnerability described here is in the backend endpoint that adds users to an ad account, which did not properly enforce the permission level of the user making the request.
| Issue | Privilege escalation / broken authorization |
|---|---|
| Impact | Escalate from limited ad-account access to administrator privileges |
| Bounty | $8,000 |
Setup
The issue affected ad accounts shared through Facebook Business Manager. The precondition is an account with a lower-privileged role on a target ad account, such as Analyst, obtained through that sharing mechanism. From that position the researcher needed to be able to send a request to the permission-management endpoint, which in the proof of concept is done from the browser with JavaScript and the page's fb_dtsg token.
No specific tooling, browser version or server version is given in the report.
Finding it
The researcher found that the endpoint used to add users to an ad account did not properly enforce the permission level of the user making the request. In other words, the check on who is allowed to assign roles was missing or insufficient on the server side, so a user holding only Analyst access could send the permission-management request directly and assign a higher role.
What makes this a real escalation rather than a cosmetic one is the role model: the owner of the ad account chooses which role an agency receives, and the agency should remain limited to the capabilities assigned by the owner. If the agency can call the add-user endpoint itself and choose the role value, the owner's restriction is bypassed.
Exploitation
Step 1: identify the endpoint and its parameters
The backend endpoint used to add users to an ad account is:
POST /ads/manage/settings/permissions/?action=add_user
The important request parameters are:
act=[AD_ACCOUNT_ID]
user_id=[USER_ID]
add_user_permission=[PERMISSION]
act selects the target ad account, user_id is the user being added, and add_user_permission carries the role to grant. The available permission values are:
1001 = Admin
1002 = Advertiser
1003 = Analyst
Step 2: send the request as a lower-privileged user
A user with Analyst access can send a request directly to the endpoint above. Because the backend does not sufficiently verify whether the requester is authorised to assign higher roles, a lower-privileged user can assign the Admin role.
Step 3: build the request in JavaScript
A simplified version of the request can be generated with JavaScript:
var xhr = new XMLHttpRequest();
xhr.open(
"POST",
"/ads/manage/settings/permissions/?action=add_user",
true
);
var body =
"act=__ACCID__" +
"&user_id=__USERID__" +
"&add_user_permission=__PERM__" +
"&__a=1";
body +=
"&fb_dtsg=" +
document.getElementsByName("fb_dtsg")[0].value;
xhr.send(body);
The placeholders are:
__ACCID__ = Target ad account ID
__USERID__ = User to add
__PERM__ = Permission level (1001, 1002, or 1003)
The request is a POST to the permissions endpoint with action=add_user in the query string. The body carries the ad account ID, the user to add, the permission value and an __a=1 parameter, plus the page's fb_dtsg value read from the DOM, plus the page's fb_dtsg value read from the DOM.
Step 4: choose the Admin value
Setting add_user_permission to 1001 adds the chosen user as an administrator of the ad account. The report notes that some sections of the original PoC were intentionally removed because they contained user IDs or email addresses.
Root cause
The mistake is a missing or insufficient server-side authorisation check on the add-user endpoint. The endpoint accepts a role value from the client and applies it without verifying that the requester is permitted to assign that role. The role model itself is sound: the owner assigns a level, and the delegate should be bound by it. The failure is that the backend did not sufficiently verify whether the requester was authorised to assign higher roles.
Impact
An agency or business account holding a lower-privileged role, such as Analyst or Advertiser, on an ad account shared through Business Manager could escalate to administrator access on that ad account. Concretely, in the scenario in the report, a business grants another business account only Analyst access; that agency should only have the permissions explicitly assigned by the owner, but by submitting the permission-management request itself it can create an Admin user and take administrative control of the ad account, bypassing the owner's assigned role restrictions.
Fix
Facebook's security team acknowledged the vulnerability and deployed a fix that prevented lower-privileged users from assigning unauthorised roles. The report does not describe the implementation of the fix beyond that.
Variants to test
- Role value tampering on other role-assignment endpoints. Take any endpoint that accepts a numeric or named role for a shared resource and submit the highest-privilege value from a low-privilege session. A positive result is the target account showing the elevated role after the request, or the added user being able to perform admin-only actions.
- Adding a new user rather than changing your own role. Submit the add-user request with a
user_idyou control while authenticated as the low-privileged delegate. A positive result is that the new user appears with the higher role even though the requester could not assign it through the UI. - Same check on removal and edit actions. Try the sibling actions on the permissions endpoint (for example removing or modifying another user's role) from the low-privileged session. A positive result is a change to another user's permissions that the UI does not offer you.
- Delegation chains. Grant a role from an account that itself received access through delegation, rather than from the owner. A positive result is that the second-level delegate can assign roles the first-level delegate was never allowed to assign.
- Token handling. Replay the request with the session's own
fb_dtsgvalue from a different page context. A positive result is acceptance of the request outside the page where the form is normally rendered, which shows the check is only on the token and not on the requester's role.
What happened, in plain words
Facebook lets businesses run adverts through a product called Ads Manager. A business can share its ad account with other people, or with another business such as a marketing agency, so that those people can work on the adverts without owning the account. When you share an ad account, you do not hand over full control: you pick a role, and the role decides what the other person is allowed to do.
In 2015, Pouya Darabi found that this limit could be removed. Someone who had been given only a low-level role on an ad account could send a request to Facebook's servers asking to make a user an administrator of that same ad account. The servers accepted the request, even though the person sending it was not allowed to hand out administrator rights. The result was that a restricted partner could add a user as an administrator of the ad account.
Facebook fixed the problem and paid a bounty of $8,000. This article walks through what the roles mean, what the request looked like, and why the server should have refused it.
| Issue | Privilege escalation / broken authorization |
|---|---|
| Impact | Escalate from limited ad-account access to administrator privileges |
| Bounty | $8,000 |
Background: ad accounts, roles and delegation
An ad account is the container Facebook uses for a business's advertising: its campaigns, its spending and its billing. It is not the same thing as a personal profile. A business owns the ad account, and other people can be given access to it.
Facebook Business Manager is the tool businesses use to organise this. It lets a business hold several ad accounts and several people, and lets it share an ad account with another business, for example an agency that runs campaigns on its behalf.
When access is shared, it is shared at a particular role. A role is a named bundle of permissions: a list of actions the holder is allowed to take. The report describes three roles:
- Admin
- Advertiser
- Analyst
Admin is the highest of the three roles listed in the report. Advertiser and Analyst are lower roles listed in the report.
The whole point of the feature is delegation with limits. An organisation hands an agency access at a restricted level, for example Analyst only, and expects the agency to stay inside those limits. The owner keeps control; the delegate gets enough access to do the job and no more.
This kind of control is called authorization (sometimes spelled authorisation): deciding what an already-identified user is allowed to do. It is different from authentication, which is about proving who you are in the first place. Logging in is authentication; being told you may not delete a campaign is authorization.
The vulnerability
The problem was in the backend endpoint that adds users to an ad account. An endpoint is simply a specific address on a server that accepts a particular kind of request. Think of a large office building: the building is the website, and each endpoint is a service window with a label on it. You walk to the right window and ask for a specific thing.
The endpoint in question is the one whose job is to add a user to an ad account with a role. Its job is administrative: it changes who has access. So the server behind it should check two things before doing anything:
- Is the person making the request logged in and identified? (authentication)
- Is that person allowed to hand out this role on this ad account? (authorization)
The report says the second check was not properly enforced. The server did not properly enforce the permission level of the user making the request. It looked at what was being asked for, but not properly at who was asking.
This class of bug is called broken authorization, and the specific outcome here is privilege escalation: a user with few rights manages to obtain more rights than they were given. The everyday comparison is a hotel key card. Your card opens your room and the gym, because that is what you paid for. Privilege escalation is finding that the door system also accepts your card for the penthouse, because the lock checks that the card is valid but never checks which floors the card was issued for.
What makes this a real escalation rather than a cosmetic one is the role model. The owner of the ad account chooses which role an agency receives. If the agency can call the add-user endpoint itself and choose the role value, the owner's restriction is bypassed entirely.
Exploitation
Step 1: identify the endpoint and its parameters
The backend endpoint used to add users to an ad account is:
POST /ads/manage/settings/permissions/?action=add_user
Line by line:
POSTis the HTTP method, the verb of the request. A browser usesGETwhen it fetches a page to read, andPOSTwhen it sends data that will change something on the server. Adding a user changes something, so it is aPOST./ads/manage/settings/permissions/is the path, the address of the service window inside Facebook's servers. The wordpermissionstells you this window deals with who is allowed to do what.?action=add_useris the query string, extra information appended after the?. Here it tells the endpoint which of its jobs to perform: add a user. The same window may handle several actions, and this parameter picks one.
The important request parameters are:
act=[AD_ACCOUNT_ID]
user_id=[USER_ID]
add_user_permission=[PERMISSION]
A parameter is a named value sent with a request, like a field on a paper form. The square brackets are placeholders: they show where a real value goes, not literal text.
actselects the target ad account. It is the account the change applies to.user_idis the user being added, identified by their numeric Facebook user ID.add_user_permissioncarries the role to grant.
The available permission values are:
1001 = Admin
1002 = Advertiser
1003 = Analyst
These are numeric codes. Instead of sending the word Admin, the request sends the number 1001, and the server translates it back into the Admin role. This is common: numbers are compact and unambiguous, and they do not depend on language or spelling. The important consequence for security is that the number is just data in the request. If the server trusts the number without checking whether the sender is allowed to ask for it, the sender can put any number there.
Step 2: send the request as a lower-privileged user
A user with Analyst access can send a request directly to the endpoint above. The word directly matters. Normally a person changes permissions by clicking through the Ads Manager interface, and the interface only offers the options that person is allowed to use.
But the interface is only a convenience layer on top of the endpoint. The browser talks to the endpoint, and anything the browser can send, a person can send too, by hand or with a small script. Hiding a button is not a security control; the server has to enforce the rule itself. Here it did not: because the backend did not sufficiently verify whether the requester was authorised to assign higher roles, the request was accepted and the role named in add_user_permission was applied.
Step 3: build the request in JavaScript
A simplified version of the request can be generated with JavaScript:
var xhr = new XMLHttpRequest();
xhr.open(
"POST",
"/ads/manage/settings/permissions/?action=add_user",
true
);
var body =
"act=__ACCID__" +
"&user_id=__USERID__" +
"&add_user_permission=__PERM__" +
"&__a=1";
body +=
"&fb_dtsg=" +
document.getElementsByName("fb_dtsg")[0].value;
xhr.send(body);
Line by line:
var xhr = new XMLHttpRequest();creates an object that can send requests to a server from inside a web page, without reloading the page. This technique is called AJAX, and it is how modern web pages update themselves quietly in the background.xhr.open("POST", "/ads/manage/settings/permissions/?action=add_user", true);prepares the request. It says: use thePOSTmethod, send it to this path (the same endpoint from Step 1), and do it asynchronously (true), meaning the page does not freeze while waiting for the answer.var body = ...builds the request body, the content of the request, as opposed to the address. It is a single string made by gluing pieces together with+. The pieces areact=__ACCID__,user_id=__USERID__,add_user_permission=__PERM__and__a=1, joined with&. The&is the separator between parameters, exactly like the&in a web address.__a=1is an extra parameter that the report includes without explaining it.body += ...appends one more parameter to that string:fb_dtsg, whose value is read from the page itself.document.getElementsByName("fb_dtsg")[0].valuemeans: find the element on the page namedfb_dtsg, take the first one, and read its value.xhr.send(body);actually sends the request, with the body attached.
CSRF stands for Cross-Site Request Forgery, an attack where a malicious website makes your browser send a request to another site where you are logged in, using your existing session. To stop this, sites put a secret, unpredictable value into their pages and require every state-changing request to include it. A malicious site cannot read that value from Facebook's page, so it cannot forge a valid request.
A session is how a website remembers you between requests. When you log in, the server gives your browser a small piece of data, often stored in a cookie, and the browser sends it back with every later request. The server sees the cookie and knows the request comes from you. The fb_dtsg token is tied to that session.
The placeholders are:
__ACCID__ = Target ad account ID
__USERID__ = User to add
__PERM__ = Permission level (1001, 1002, or 1003)
So the script is a template. You fill in which ad account you are targeting, which user you want to add, and which role code you want to grant, and the script assembles the request for you.
Step 4: choose the Admin value
Setting add_user_permission to 1001 adds the chosen user as an administrator of the ad account. That is the whole trick: the same request that a legitimate administrator would send, sent by someone who is not an administrator, with the highest role code in the role field.
The report notes that some sections of the original PoC were intentionally removed because they contained user IDs or email addresses. A PoC, or proof of concept, is the minimal demonstration that a bug is real: the smallest set of steps that produces the effect. Removing personal data from a published PoC is normal practice, because the point is to show the mechanism, not to expose anyone's account.
Why the token did not stop it
The token answers the question "did this request really come from a page on our site, in this user's browser?" It does not answer the question "is this user allowed to do this?" Those are two different questions, and only the second one would have stopped the escalation.
Root cause
The mistake is a missing or insufficient server-side authorization check on the add-user endpoint. The endpoint accepts a role value from the client and applies it without verifying that the requester is permitted to assign that role. The role model itself is sound: the owner assigns a level, and the delegate should be bound by it. The failure is that the backend did not sufficiently verify whether the requester was authorised to assign higher roles.
A useful way to remember the principle: the server should never decide what you may do based on what you asked for. It should decide based on who you are and what you were granted. The request is a wish; the server holds the rulebook.
Impact
An agency or business account holding a lower-privileged role, such as Analyst or Advertiser, on an ad account shared through Business Manager could escalate to administrator access on that ad account. Concretely, in the scenario in the report, a business grants another business account only Analyst access; that agency should only have the permissions explicitly assigned by the owner, but by submitting the permission-management request itself it can create an Admin user and take administrative control of the ad account, bypassing the owner's assigned role restrictions.
Fix
Facebook's security team acknowledged the vulnerability and deployed a fix that prevented lower-privileged users from assigning unauthorized roles. The report does not describe the implementation of the fix beyond that.
Disclosure timeline
| Date and time | Event |
|---|---|
| March 14, 2015, 01:27 | Initial vulnerability reported. |
| March 17, 2015, 03:35 | Issue acknowledged by Facebook's security team. |
| March 17, 2015, 08:00 | Facebook confirmed the vulnerability had been fixed. |
| March 20, 2015, 22:08 | $8,000 bounty awarded. |
A bug bounty is a programme where a company pays researchers who report security problems responsibly, instead of attacking them or selling the information.
Variants to test
These are the follow-up checks a researcher would try after finding the first bug, because the same mistake often appears in more than one place. Each one is described with what a positive result looks like.
- Role value tampering on other role-assignment endpoints. Take any endpoint that accepts a numeric or named role for a shared resource and submit the highest-privilege value from a low-privilege session. A positive result is the target account showing the elevated role after the request, or the added user being able to perform admin-only actions.
- Adding a new user rather than changing your own role. Submit the add-user request with a
user_idyou control while authenticated as the low-privileged delegate. A positive result is that the new user appears with the higher role even though the requester could not assign it through the UI. - Same check on removal and edit actions. Try the sibling actions on the permissions endpoint (for example removing or modifying another user's role) from the low-privileged session. A positive result is a change to another user's permissions that the UI does not offer you.
- Delegation chains. Grant a role from an account that itself received access through delegation, rather than from the owner. A positive result is that the second-level delegate can assign roles the first-level delegate was never allowed to assign.
- Token handling. Replay the request with the session's own
fb_dtsgvalue from a different page context. A positive result is acceptance of the request outside the page where the form is normally rendered, which shows the check is only on the token and not on the requester's role.
Glossary
- Ad account: the container Facebook uses for a business's advertising, including its campaigns, spending and billing.
- Admin: the highest of the roles described in the report; an administrator can manage the account and decide who else gets access.
- Advertiser: a lower role described in the report, below Admin.
- Analyst: a lower role described in the report, below Admin.
- AJAX: a technique for sending requests to a server from inside a web page without reloading it.
- Anti-CSRF token: a secret, unpredictable value placed in a page and required in state-changing requests, so that another website cannot forge a request on your behalf.
- Authentication: proving who you are, for example by logging in.
- Authorization: deciding what an already-identified user is allowed to do.
- Backend: the server-side part of a system, which the user does not see directly.
- Body: the content of an HTTP request, as opposed to its address.
- Broken authorization: a vulnerability where the server fails to properly check whether a user is allowed to perform an action.
- Bug bounty: a programme that pays researchers for responsibly reporting security problems.
- Cookie: a small piece of data a website stores in your browser and receives back with later requests, often used to keep you logged in.
- CSRF (Cross-Site Request Forgery): an attack where a malicious site makes your browser send a request to another site where you are logged in.
- Delegation: giving another person or business access to something you own, at a level you choose.
- Endpoint: a specific address on a server that accepts a particular kind of request.
- fb_dtsg: the anti-CSRF token used in the proof of concept, read from the page and sent with the request.
- HTTP method: the verb of a request, such as
GETto read orPOSTto change something. - Parameter: a named value sent with a request, like a field on a form.
- PoC (proof of concept): the minimal demonstration that a vulnerability is real.
- POST: the HTTP method used to send data that changes something on the server.
- Privilege escalation: obtaining more rights than you were granted.
- Query string: the part of a URL after the
?, carrying extra parameters. - Role: a named bundle of permissions that defines what its holder may do.
- Session: how a website remembers you between requests, usually via a cookie.
- User ID: the numeric identifier Facebook uses for a user account.