Header spoofing via a hidden parameter in Facebook Batch GraphQL APIs
A hidden 'headers' parameter in Facebook's batch GraphQL API allowed setting custom headers, including the Host header, on batched requests. This could cause the server to route requests to different virtual hosts, potentially enabling SSRF or spoofing of internal headers.
Published on feed.bugs.xdavidhu.me
GraphQL queries can be batched as described by the documentation: https://developers.facebook.com/docs/graph-api/batch-requests/
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
Meta's Graph API supports batching several GraphQL operations into a single HTTP request, as described in the public batch requests documentation. The batch service accepts a batch form parameter containing a JSON array of operations, each with fields such as method, relative_url, body, name and omit_response_on_success. The service then executes each operation and returns the individual responses.
The researcher found that the batch service also accepts a parameter that is not in the documentation: headers. It lets the caller attach custom HTTP headers to each batched request. The report was submitted during the Meta BountyConEDU 2022 live hacking event in Madrid, Spain, and the asset involved was the batch GraphQL service reachable at hosts such as b-graph.workplace.com.
Setup
The testing was done against the batch endpoint with a raw HTTP request. The researcher used an access token from a Publishing Bot on a test account and said readers were free to use it. The request was modified from the Workplace Android app, so it carries the headers that app normally sends (X-Fb-Sim-Hni, X-Fb-Device-Group, X-Fb-Http-Engine: Liger, and so on).
Finding it
The starting point was the documented batching feature. While experimenting with it, the researcher discovered the undocumented headers parameter, which allows custom headers to be set on the batched requests. Setting the Host header through this parameter produced responses that depended on the value supplied:
Host: [redacted]returned a redirect tohttps://www.facebook.com/graph/server.php?[params].Host: apps.intern.facebook.comreturned a redirect tohttps://apps.intern.facebook.com/login/.Host: graph.intern.facebook.comreturned an error saying:The request could not be understood by the server due to malformed syntax.
The researcher then checked whether the same effect could be obtained without batching at all, by sending the Host header directly to the server hosting the batching service. It behaved the same way. That suggested the requests were not leaving the machine: they were hitting different virtual hosts available on the same IP. The researcher was not able to reach internalfb.com infrastructure through the batch endpoint and concluded it sits on different infrastructure.
A second observation concerned the nature of the batched calls. It looked less like the service creating real HTTP requests and more like calls to the /graph/server.php endpoint, with method and relative_url acting as parameters to that script. relative_url appeared to be converted into a parameter named _fb_url.
Exploitation
Step 1: Send a batch request with custom headers
The proof of concept is a raw batch request with two headers injected through the headers array: a Host header and X-FB-Debug.
POST /?include_headers=true&decode_body_json=false&streamable_json_response=false&locale=en_US&client_country_code=HU HTTP/1.1
Host: b-graph.workplace.com
Priority: u=3, i
Authorization: OAuth [redacted]
X-Fb-Sim-Hni: 21601
X-Fb-Connection-Type: unknown
User-Agent:
Content-Type: application/x-www-form-urlencoded
X-Fb-Device-Group: 6066
X-Tigon-Is-Retry: False
X-Fb-Friendly-Name: handleLogin
X-Fb-Request-Analytics-Tags: unknown
Accept-Encoding: gzip, deflate
X-Fb-Http-Engine: Liger
X-Fb-Client-Ip: True
X-Fb-Server-Cluster: True
Content-Length: 213
Connection: close
batch=[{"headers": ["Host: graph.intern.facebook.com", "X-FB-Debug: True"], "method":"GET","body":"asd","name":"fetchViewerLoginAudienceInfo","omit_response_on_success":false,"relative_url":"/intern/api/graphql"}]
The query string enables header inclusion and disables body decoding and streamable JSON responses. The Authorization header carries the OAuth token. The batch parameter holds a single operation whose headers array contains the two injected headers, with relative_url pointing at /intern/api/graphql.
Step 2: Compare with direct requests
Sending the same Host values directly to the server hosting the batching service, without batching, produced the same redirects and errors. This is the evidence that the batch service is not the only path to the behaviour, and that the requests are being served by virtual hosts on the same IP rather than by remote systems.
Step 3: Test X-FB-Debug
Setting X-FB-Debug: True on a request to these IPs returned a set of encrypted debug headers. The researcher assumed these came from a middleman such as a load balancer rather than from the application. To test that, the same header was set on a batch request: no debug headers came back in the batch response. This made the researcher think that batch requests reach the application directly and do not pass through the load balancer.
Step 4: Try to spoof a client IP
Because the application might trust headers that the load balancer normally supplies and strips, the researcher tried setting X-FB-Client-IP-Forwarded in batch calls to spoof the IP used for GraphQL actions. This did not succeed. The researcher noted that other internal headers trusted from the load balancer might still be spoofable this way.
Step 5: Reach other Meta graph services
Other Meta-owned, non-Facebook graph services are available on the same IPs. For example, the ExpressWiFi GraphQL can be reached by setting Host: b-graph.expresswifi.com. The researcher said it seemed these IPs and servers handle all non-internalfb.com Meta graph services.
Step 6: Observe the rewritten URL
Setting the Host header to m.intern.facebook.com returned a 404 HTML page that essentially redirects to the login page. This confirmed that the batch service sends a request to the selected virtual host at the following path:
/graph/server.php?_fb_url=[relative_url]&locale=[locale_from_querystring]&access_token=[access_token_from_header]&_fb_domain=Facebook&_fb_profilable_request_id=326014522&_fb_batch_child_request=1&_fb_batch_expires=1651402020&_fb_batch_sig=Afh-Je5z3GOz274X4h4
The path shows relative_url mapped to _fb_url, the locale taken from the query string, the access token taken from the Authorization header, and a set of batch bookkeeping parameters (_fb_batch_child_request, _fb_batch_expires, _fb_batch_sig). The researcher was not sure where the method parameter is added, suggesting it may be sent as a POST inside the body. Depending on the target application, the response is content, a redirect or a login page.
Root cause
The batch service accepts a headers array per operation and applies those headers to the request it makes on the caller's behalf. Because the batched request is issued directly to the application, bypassing the load balancer, headers that the application would normally receive only from trusted infrastructure can be supplied by the caller. The Host header appears to select which virtual host on the shared IP receives the request, and the researcher could reach other Meta graph services this way. The report does not describe the server-side code, so the exact implementation is not stated; the behaviour is consistent with the batch handler passing the supplied headers straight through to the outgoing request.
Impact
The researcher describes the issue as potentially exploitable for SSRF or for spoofing internal headers for the Graph application. In practice the demonstrated effects are: redirects and error pages that reveal the existence and behaviour of internal virtual hosts, access to other Meta graph services on the same IPs (such as ExpressWiFi), and the ability to set headers on requests that reach the application without passing through the load balancer. The attempt to spoof the client IP with X-FB-Client-IP-Forwarded did not work, and internalfb.com infrastructure was not reachable. The report does not show any data disclosure or account takeover. Meta awarded a bounty of $3000, describing the issue as "spoofing host header in specific situations".
Fix
Meta stated on 2022-10-03 that the vulnerability had been patched, and on 2022-10-19 confirmed the report had been fully investigated and fixed and could be published.
Variants to test
- Send a batch operation with a
headersarray containingHostset to an internal hostname and observe whether the response differs from the public host. A positive result is a redirect, login page or error that reveals an internal virtual host. - Set
X-FB-Debug: Trueboth directly and inside a batch and compare. If debug headers appear only on the direct request, the batch path bypasses the load balancer. - Try other headers the application may trust from the load balancer, such as client IP or forwarding headers, inside the batch. A positive result is a change in the application's view of the caller, for example in access decisions or logged identity.
- Point
Hostat other services sharing the same IPs, as withb-graph.expresswifi.com. A positive result is a response from a service other than the one the endpoint belongs to. - Inspect the rewritten
_fb_urlpath in redirects to learn howrelative_url, locale and token are mapped, then test whether other query parameters can be influenced through the batch fields.
What happened, in plain words
Facebook (Meta) runs a service that lets apps send several GraphQL requests at once, bundled together in a single web request. This is called batching, and it is a documented feature. While testing that feature, the researcher found an extra, undocumented option called headers that lets the caller attach custom HTTP headers to each bundled request. By putting a Host header into that option, the caller could make the service send the request to a different virtual host on the same machine, and could reach other Meta services that share the same servers. Meta paid a $3000 bounty and later said the issue was fixed.
To follow the rest of this article you only need to know what a browser does: it sends a request to a server, the server answers. Everything below is a more detailed version of that same idea.
Background concepts, from zero
Before the details, here are the pieces involved, explained as if you have never seen them.
- HTTP request: the message your browser sends to a server when you open a page. It has a first line (the method, like
GETorPOST, and the path), then a list of headers (small labelled pieces of information), then optionally a body (data). - Header: a line like
Host: example.comorContent-Type: application/x-www-form-urlencoded. Headers tell the server who is asking, what format the data is in, and so on. TheHostheader is special: it tells the server which website name the visitor typed, because one server (one IP address) can answer for many names. Each name is called a virtual host. - API: a way for one program to talk to another. Instead of a page made for humans, an API returns data in a structured format. Facebook's Graph API is the API that apps use to read and write Facebook data.
- GraphQL: a query language for APIs. Instead of calling many different addresses, you send one query describing exactly the data you want, and the server answers with just that.
- Batching: sending several API operations inside one HTTP request, so the app does not have to open many connections. The server runs each operation and returns each result.
- Token (access token): a long string that proves who you are, like a temporary key card. Apps send it in an
Authorizationheader instead of a username and password. - Load balancer: a machine that sits in front of the real servers and spreads incoming traffic across them. It often adds headers of its own (for example, the real visitor's IP address) before passing the request on, and it strips headers of that kind if a visitor tries to send them.
- SSRF (Server-Side Request Forgery): a bug where an attacker can make the server itself send a request to a destination the attacker chooses. The server becomes a puppet that can reach places the attacker cannot reach directly, such as internal machines.
- Header spoofing: pretending to be something you are not by setting a header that the server trusts, for example claiming to come from an internal address.
- Virtual host: one server can host many websites. The
Hostheader picks which one answers. If you can choose theHostvalue, you can choose which site on that server you talk to.
The feature being tested
Meta's Graph API supports batching several GraphQL operations into a single HTTP request, as described in the public batch requests documentation. The batch service accepts a form parameter called batch that contains a JSON array of operations. Each operation has fields such as method, relative_url, body, name and omit_response_on_success. The service runs each operation and returns the individual responses.
In plain words: you send one request to the batch endpoint, and inside its body you put a list of smaller requests. The server unpacks the list, performs each one, and hands back the answers together.
The researcher found that the batch service also accepts a parameter that is not in the documentation: headers. It lets the caller attach custom HTTP headers to each batched request. The report was submitted during the Meta BountyConEDU 2022 live hacking event in Madrid, Spain. The asset involved was the batch GraphQL service, reachable at hosts such as b-graph.workplace.com.
Setting up the test
The testing was done against the batch endpoint with a raw HTTP request, meaning the researcher wrote the request by hand rather than through a browser. The access token came from a Publishing Bot on a test account, and the researcher said readers were free to use it. The request was modified from the Workplace Android app, so it carries the headers that app normally sends (X-Fb-Sim-Hni, X-Fb-Device-Group, X-Fb-Http-Engine: Liger, and so on).
Finding the hidden parameter
The starting point was the documented batching feature. While experimenting with it, the researcher discovered the undocumented headers parameter, which allows custom headers to be set on the batched requests. Setting the Host header through this parameter produced responses that depended on the value supplied:
Host: [redacted]returned a redirect tohttps://www.facebook.com/graph/server.php?[params].Host: apps.intern.facebook.comreturned a redirect tohttps://apps.intern.facebook.com/login/.Host: graph.intern.facebook.comreturned an error saying:The request could not be understood by the server due to malformed syntax.
[redacted] is the address a computer uses to refer to itself. The other two names are internal Facebook hostnames. Each value produced a different reaction, which is the clue: the server was not ignoring the header, it was acting on it.
The researcher then checked whether the same effect could be obtained without batching at all, by sending the Host header directly to the server hosting the batching service. It behaved the same way. That suggested the requests were not leaving the machine: they were hitting different virtual hosts available on the same IP. The researcher was not able to reach internalfb.com infrastructure through the batch endpoint and concluded it sits on different infrastructure.
A second observation concerned the nature of the batched calls. It looked less like the service creating real HTTP requests and more like calls to the /graph/server.php endpoint, with method and relative_url acting as parameters to that script. relative_url appeared to be converted into a parameter named _fb_url.
Exploitation
Step 1: Send a batch request with custom headers
The proof of concept is a raw batch request with two headers injected through the headers array: a Host header and X-FB-Debug.
POST /?include_headers=true&decode_body_json=false&streamable_json_response=false&locale=en_US&client_country_code=HU HTTP/1.1
Host: b-graph.workplace.com
Priority: u=3, i
Authorization: OAuth [redacted]
X-Fb-Sim-Hni: 21601
X-Fb-Connection-Type: unknown
User-Agent:
Content-Type: application/x-www-form-urlencoded
X-Fb-Device-Group: 6066
X-Tigon-Is-Retry: False
X-Fb-Friendly-Name: handleLogin
X-Fb-Request-Analytics-Tags: unknown
Accept-Encoding: gzip, deflate
X-Fb-Http-Engine: Liger
X-Fb-Client-Ip: True
X-Fb-Server-Cluster: True
Content-Length: 213
Connection: close
batch=[{"headers": ["Host: graph.intern.facebook.com", "X-FB-Debug: True"], "method":"GET","body":"asd","name":"fetchViewerLoginAudienceInfo","omit_response_on_success":false,"relative_url":"/intern/api/graphql"}]
Line by line:
POST /?include_headers=true&decode_body_json=false&streamable_json_response=false&locale=en_US&client_country_code=HU HTTP/1.1: the request line.POSTmeans we are sending data. The path is/with a query string.include_headers=trueasks the service to include headers in the response.decode_body_json=falseandstreamable_json_response=falseturn off two response formats.locale=en_USsets the language and region, andclient_country_code=HUsays Hungary.HTTP/1.1is the protocol version.Host: b-graph.workplace.com: the normal hostname of the batch service, the one the request is really addressed to.Priority: u=3, i: a header the app sends about request priority.Authorization: OAuth [redacted]: the access token, the key card that identifies the caller. It is redacted here because it is a secret.X-Fb-Sim-Hni: 21601,X-Fb-Connection-Type: unknown,X-Fb-Device-Group: 6066,X-Tigon-Is-Retry: False,X-Fb-Friendly-Name: handleLogin,X-Fb-Request-Analytics-Tags: unknown,X-Fb-Http-Engine: Liger,X-Fb-Client-Ip: True,X-Fb-Server-Cluster: True: headers copied from the Workplace Android app. They describe the phone, the network and the app, and make the request look like genuine app traffic.User-Agent:with nothing after it: the app sends an empty user agent.Content-Type: application/x-www-form-urlencoded: the body is form data, the same format a web form uses.Accept-Encoding: gzip, deflate: the client can accept compressed answers.Content-Length: 213: the body is 213 bytes long.Connection: close: close the connection after this request.- The blank line separates headers from the body.
batch=[...]: the body. It is one form field namedbatchwhose value is a JSON array with a single operation. Inside that operation,headersis the hidden field: it holdsHost: graph.intern.facebook.comandX-FB-Debug: True, the two headers we want the service to add.methodisGET,bodyisasd(a placeholder),nameisfetchViewerLoginAudienceInfo,omit_response_on_successisfalse, andrelative_urlis/intern/api/graphql, the internal path the batched call should hit.
Why this shape? The goal is to make the batch service issue a request to an internal hostname and path, with headers of our choosing, while the outer request still goes to the public batch host.
Step 2: Compare with direct requests
Sending the same Host values directly to the server hosting the batching service, without batching, produced the same redirects and errors. This is the evidence that the batch service is not the only path to the behaviour, and that the requests are being served by virtual hosts on the same IP rather than by remote systems.
Why this matters: if the effect only appeared through batching, it would be a bug in the batch code. Because it also appears on direct requests, it shows the underlying server is simply answering for many hostnames, and the batch feature is a way to choose which one.
Step 3: Test X-FB-Debug
Setting X-FB-Debug: True on a request to these IPs returned a set of encrypted debug headers. The researcher assumed these came from a middleman such as a load balancer rather than from the application. To test that, the same header was set on a batch request: no debug headers came back in the batch response. This made the researcher think that batch requests reach the application directly and do not pass through the load balancer.
Why this matters: a load balancer often adds trusted headers and removes any the visitor tries to set. If the batch path skips the load balancer, then headers the application normally trusts from the load balancer might be settable by the caller.
Step 4: Try to spoof a client IP
Because the application might trust headers that the load balancer normally supplies and strips, the researcher tried setting X-FB-Client-IP-Forwarded in batch calls to spoof the IP used for GraphQL actions. This did not succeed. The researcher noted that other internal headers trusted from the load balancer might still be spoofable this way.
In plain words: the idea was to make the application believe the request came from a different address. That particular header did not work, but the door was not fully closed.
Step 5: Reach other Meta graph services
Other Meta-owned, non-Facebook graph services are available on the same IPs. For example, the ExpressWiFi GraphQL can be reached by setting Host: b-graph.expresswifi.com. The researcher said it seemed these IPs and servers handle all non-internalfb.com Meta graph services.
Why this matters: one entry point was giving access to services that belong to other products, simply by changing the hostname in the hidden header.
Step 6: Observe the rewritten URL
Setting the Host header to m.intern.facebook.com returned a 404 HTML page that essentially redirects to the login page. This confirmed that the batch service sends a request to the selected virtual host at the following path:
/graph/server.php?_fb_url=[relative_url]&locale=[locale_from_querystring]&access_token=[access_token_from_header]&_fb_domain=Facebook&_fb_profilable_request_id=326014522&_fb_batch_child_request=1&_fb_batch_expires=1651402020&_fb_batch_sig=Afh-Je5z3GOz274X4h4
Line by line:
/graph/server.php: the script on the selected virtual host that actually handles the call._fb_url=[relative_url]: therelative_urlfrom the batch operation, placed into this parameter. This is the mapping the researcher suspected earlier.locale=[locale_from_querystring]: the language and region, taken from the outer request's query string.access_token=[access_token_from_header]: the token, taken from theAuthorizationheader of the outer request._fb_domain=Facebook: which product the call belongs to._fb_profilable_request_id=326014522: an identifier for the request._fb_batch_child_request=1: marks this as one child of a batch._fb_batch_expires=1651402020: an expiry time for the batch._fb_batch_sig=Afh-Je5z3GOz274X4h4: a signature that lets the server check the batch was not tampered with.
The researcher was not sure where the method parameter is added, suggesting it may be sent as a POST inside the body. Depending on the target application, the response is content, a redirect or a login page.
Root cause
The batch service accepts a headers array per operation and applies those headers to the request it makes on the caller's behalf. Because the batched request is issued directly to the application, bypassing the load balancer, headers that the application would normally receive only from trusted infrastructure can be supplied by the caller. The Host header appears to select which virtual host on the shared IP receives the request, and the researcher could reach other Meta graph services this way. The report does not describe the server-side code, so the exact implementation is not stated; the behaviour is consistent with the batch handler passing the supplied headers straight through to the outgoing request.
In everyday terms: the batch service is like a receptionist who will forward your note to any desk in the building, and will write on the envelope whatever sender name you dictate. If the desks trust the sender name, you can pretend to be someone from head office.
Impact
The researcher describes the issue as potentially exploitable for SSRF or for spoofing internal headers for the Graph application. In practice the demonstrated effects are: redirects and error pages that reveal the existence and behaviour of internal virtual hosts, access to other Meta graph services on the same IPs (such as ExpressWiFi), and the ability to set headers on requests that reach the application without passing through the load balancer. The attempt to spoof the client IP with X-FB-Client-IP-Forwarded did not work, and internalfb.com infrastructure was not reachable. The report does not show any data disclosure or account takeover. Meta awarded a bounty of $3000, describing the issue as "spoofing host header in specific situations".
Fix
Meta stated on 2022-10-03 that the vulnerability had been patched, and on 2022-10-19 confirmed the report had been fully investigated and fixed and could be published.
Variants to test
These are follow-up ideas in the same spirit, useful if you want to practise on a service you are allowed to test.
- Send a batch operation with a
headersarray containingHostset to an internal hostname and observe whether the response differs from the public host. A positive result is a redirect, login page or error that reveals an internal virtual host. - Set
X-FB-Debug: Trueboth directly and inside a batch and compare. If debug headers appear only on the direct request, the batch path bypasses the load balancer. - Try other headers the application may trust from the load balancer, such as client IP or forwarding headers, inside the batch. A positive result is a change in the application's view of the caller, for example in access decisions or logged identity.
- Point
Hostat other services sharing the same IPs, as withb-graph.expresswifi.com. A positive result is a response from a service other than the one the endpoint belongs to. - Inspect the rewritten
_fb_urlpath in redirects to learn howrelative_url, locale and token are mapped, then test whether other query parameters can be influenced through the batch fields.
Glossary
- API: a way for one program to talk to another, usually returning structured data rather than a web page.
- Access token: a long string that proves who the caller is, sent instead of a username and password.
- Batch request: one HTTP request that carries several smaller API operations, which the server runs and answers together.
- Body: the part of an HTTP request or response that carries data, after the headers.
- Content-Type: a header saying what format the body is in, for example form data or JSON.
- Form data: a body format of
name=valuepairs, the same format a web form uses. - GraphQL: a query language for APIs where the caller describes exactly the data wanted in one query.
- Header: a labelled line of information in an HTTP request or response, such as
HostorAuthorization. - Header spoofing: setting a header to a value the server trusts, to pretend to be something you are not.
- Host header: the header that says which website name the request is for, used to pick a virtual host on a shared server.
- HTTP: the protocol browsers and servers use to exchange requests and responses.
- IP address: the numeric address of a machine on a network.
[redacted]means the machine itself. - JSON: a text format for structured data, using curly braces, square brackets and quoted names.
- Load balancer: a machine in front of the real servers that spreads traffic and often adds or strips trusted headers.
- Locale: the language and region setting, such as
en_US. - OAuth: a scheme where an app presents a token to act on a user's behalf.
- Query string: the part of a URL after
?, made ofname=valuepairs. - Redirect: a response telling the client to go to a different address.
- SSRF (Server-Side Request Forgery): a bug where the attacker makes the server send a request to a destination of the attacker's choosing.
- Virtual host: one of several websites served by the same machine, selected by the
Hostheader. - X-FB-Debug: a header that asks Facebook servers to return debug information; the report notes it returns encrypted debug headers on direct requests but not through batching.