Skip to content
IDOR Write-up Intermediate

Insufficient GraphQL API vulnerability due to lack of validation of Authorization Bearer token

The GraphQL API for spend rules did not properly validate the Authorization Bearer token, so a mutation that should have been access-controlled could be executed. An attacker could create or query spend rules and, by supplying another user's spend rule identifier, retrieve that user's sensitive information.

Int Follow

Published on 0x1int.gitbook.io

Bounty$700 View original

That day I got one private invitation from one private bug bounty program on HackerOne. And unexpectedly it was really fresh program with only few resolved reports.

Int (@intlulz), on 0x1int.gitbook.io

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

A private bug bounty program on HackerOne invited me shortly after it launched. It was a fresh program with only a few resolved reports, and its front end is built with the Next.js JavaScript framework. The program publishes detailed API documentation, and the whole API described there is GraphQL.

The feature I ended up spending most of my time on was Authorization Controls, also called Rule Types. It is the bank-related part of the product: rules that decide what a spend is allowed or blocked to do. Every rule type is read through the same GraphQL query, FindSpendRule, and each type has its own creation mutation. One of those types is Street Address, and it is the example I use below, but the problem affected the whole feature.

Setup

There was no special tooling involved. I had a private invitation to the program, access to its API documentation, and a way to send GraphQL requests.

Finding it

I started on 21 January 2023 by reading the API documentation, which took most of that day without producing anything. On 22 January I came across a specific feature while exploring the product, went back to the documentation, and found it described there in enough detail that understanding it took some time. On 23 January I finished reading about that feature and started testing it. It was the Authorization Controls / Rule Types feature, the bank-related one.

On 24 January I noticed the actual problem: the Authorization header carrying the Bearer token was not being validated server-side. The server was not validating the Authorization header carrying the Bearer token. Because the whole feature shares the FindSpendRule GraphQL query, every rule type was affected, not just the one I was testing.

Exploitation

Step 1: look at the creation mutation

The Street Address rule type is created with this mutation:

GraphQL
mutation CreateStreetAddressRule($input: CreateStreetAddressSpendRuleInput!) {
  createStreetAddressSpendRule(input: $input) {
    __typename
    ... on StreetAddressSpendRule {
      id
      name
      version
      allowed
      blocked
      createdAt
      updatedAt
    }
    ... on UserError {
      errors {
        code
        path
      }
    }
    ... on AccessDeniedError {
      message
    }
  }
}

The mutation takes a CreateStreetAddressSpendRuleInput input type. Depending on the outcome, it returns either the created rule's fields (ID, name, version, allowed and blocked lists, timestamps) or an AccessDeniedError from the back end, which would mean the operation is not permitted.

Step 2: send the variables

The variables for the mutation are a JSON object with a single key, input, whose value is another object. That inner object has two keys, name and allowed: name is the string test, and allowed is an array containing the single string MATCH.

Step 3: execute and read the response

Executing the mutation returned a data object containing createStreetAddressSpendRule, whose value represents a street address spend rule. It carries __typename, id, name, version, allowed, blocked, createdAt and updatedAt, with the values typed as string, string, string, array, array, string and string respectively. The response also has an extensions key with a requestId field holding a unique identifier for the request.

The mutation returned a created street address spend rule. In other words, createStreetAddressSpendRule does not properly check authorization before creating a new rule, which is a sanitisation and server-side validation failure.

Step 4: reach another user's rule

The more interesting part is reading someone else's data. The API documentation does not list an id field in the variables, but I added one anyway and it worked. The variables object contains an input object with three keys: spendRuleId, allowed and blocked.

  • spendRuleId is a string, a unique identifier for a spend rule. In my test it was AAAAAAAAAAAAA.
  • allowed is an array with the single string AUTOMATED_FUEL_DISPENSERS, a category allowed under the rule type.
  • blocked is an empty array, meaning no spend categories are blocked under the rule.

With that input, the FindSpendRule GraphQL query returns the user's information. All an attacker has to do is substitute another user's spend rule type ID for spendRuleId, and the response discloses that user's sensitive information, bypassing the access controls.

Root cause

The server does not validate the Authorization header with the Bearer token. The rule types feature resolves every type through the same FindSpendRule query, and the resolver does not check that the requested spendRuleId belongs to the caller before returning the record. The documentation does not list an id field in the variables, but adding one worked.

Impact

An authenticated attacker can create rules without proper authorization and, more importantly, read other users' spend rule data by supplying their IDs to FindSpendRule. The exposure covers the whole Rule Types feature, since all types share the query. The report does not describe any further use of the leaked data.

Timeline

  1. 25 January 2023: I reported the issue.
  2. 30 January 2023: HackerOne's triager marked it needs-more-info.
  3. 31 January 2023: the triager changed the status to Pending program review.
  4. 1 February 2023: a program staff member triaged the report and immediately awarded a $700 bounty.
From the original on 0x1int.gitbook.io

Fix

The report does not say what the program changed. The fix belongs on the server: validate the bearer token on every GraphQL operation, and in the FindSpendRule resolver check that the requested spendRuleId belongs to the authenticated user before returning the record. The same ownership check should apply to the creation mutations, and the schema should not accept identifiers that the documentation does not describe.

Variants to test

  • On other GraphQL APIs, add an undocumented identifier field such as spendRuleId to an input object and see whether the resolver accepts it. A positive result is a record returned for an ID you do not own.
  • Send requests with a missing, malformed or expired Authorization: Bearer header against mutations and queries. A positive result is a successful response instead of an authentication or access-denied error.
  • Take an object ID from one account and use it in a query or mutation from a second account. A positive result is the first account's data appearing in the second account's response.
  • Test every rule type that shares a common query, since a missing check in the shared resolver affects all of them.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

What happened, in plain words

A security researcher received a private invitation to a bug bounty program on HackerOne. A bug bounty program is a scheme where a company pays people to find security problems in its systems and report them privately, instead of attacking it for real. This program was brand new, with only a few reports resolved so far, and its website front end was built with a tool called Next.js. The program also published detailed documentation describing its API.

An API is the set of doors a website or app uses to talk to its servers behind the scenes: when you click a button, your browser sends a request to one of those doors and the server sends data back. GraphQL is a particular style of API where the client sends a request describing exactly which pieces of data it wants, and the server answers with just those pieces. The documentation told the researcher that the whole API here was GraphQL.

The feature the researcher spent most of the time on was called Authorization Controls, also known as Rule Types. It is the bank-related part of the product: rules that decide what a spend is allowed to do and what it is blocked from doing. Every rule type is read through the same GraphQL query, FindSpendRule, and each type has its own separate request for creating a rule. One of those types is Street Address, which is the example used below, but the problem affected the whole feature.

A query, in GraphQL terms, is a request that reads data. A mutation is a request that changes something, such as creating a new record. Both are just messages sent to the server.

Setup

No special tools were involved. The researcher had a private invitation to the program, access to its API documentation, and a way to send GraphQL requests.

Finding it

  1. On 21 January 2023 the researcher read the API documentation. That took most of the day and produced nothing.
  2. On 22 January, while exploring the product, the researcher came across a specific feature, went back to the documentation, and found it described there in enough detail that understanding it took some time.
  3. On 23 January, having finished reading about that feature, the researcher started testing it. It was the Authorization Controls / Rule Types feature, the bank-related one.
  4. On 24 January the actual problem became clear: the Authorization header carrying the Bearer token was not being validated on the server side. The server was not validating the Authorization header carrying the Bearer token.

A header is a small piece of extra information attached to every request your browser sends, a bit like the label on a parcel. The Authorization header is the one that carries proof of who you are. A Bearer token is that proof: a long string the server gave you when you logged in, which you show on each later request, in the same way a cloakroom ticket proves a coat is yours. If the server never checks the ticket, the ticket proves nothing.

Because the whole feature shares the FindSpendRule GraphQL query, every rule type was affected, not just the one being tested.

Exploitation

Step 1: look at the creation request

The Street Address rule type is created with this mutation:

GraphQL
mutation CreateStreetAddressRule($input: CreateStreetAddressSpendRuleInput!) {
  createStreetAddressSpendRule(input: $input) {
    __typename
    ... on StreetAddressSpendRule {
      id
      name
      version
      allowed
      blocked
      createdAt
      updatedAt
    }
    ... on UserError {
      errors {
        code
        path
      }
    }
    ... on AccessDeniedError {
      message
    }
  }
}

Line by line:

  • mutation CreateStreetAddressRule($input: CreateStreetAddressSpendRuleInput!) names the request and declares one input, called $input, whose shape is defined by a type named CreateStreetAddressSpendRuleInput. The exclamation mark means the input is required.
  • createStreetAddressSpendRule(input: $input) { is the actual operation: create a street address spend rule using that input. The opening brace starts the list of fields the client wants back.
  • __typename asks the server to say which type of object it is returning.
  • ... on StreetAddressSpendRule { means: if the result is a street address spend rule, return the fields listed inside this block. This is how GraphQL handles several possible outcomes in one request.
  • id, name, version, allowed, blocked, createdAt, updatedAt are the fields of the created rule: its identifier, its name, its version, the list of allowed spend categories, the list of blocked ones, and when it was created and last updated.
  • ... on UserError { means: if the result is a user error, return its errors list, with each error's code and path.
  • ... on AccessDeniedError { means: if the result is an access denied error, return its message.

The mutation takes a CreateStreetAddressSpendRuleInput input type. Depending on the outcome it returns either the created rule's fields or an AccessDeniedError from the back end, which would mean the operation is not permitted.

Step 2: send the variables

The variables for the mutation are a JSON object with a single key, input, whose value is another object. That inner object has two keys, name and allowed: name is the string test, and allowed is an array containing the single string MATCH.

JSON is a plain text format for structured data, made of keys and values in curly braces, like a labelled form. Variables are the values filled into the placeholders declared in the request, the way you fill in a form before handing it over.

Step 3: execute and read the response

Executing the mutation returned a data object containing createStreetAddressSpendRule, whose value represents a street address spend rule. It carries __typename, id, name, version, allowed, blocked, createdAt and updatedAt, with the values typed as string, string, string, array, array, string and string respectively. The response also has an extensions key with a requestId field holding a unique identifier for the request.

An array is simply a list of values in square brackets. The requestId is a label the server attaches so it can find that particular request in its logs later.

The mutation returned a created street address spend rule. In other words, createStreetAddressSpendRule does not properly check authorization before creating a new rule, which is a sanitisation and server-side validation failure. Sanitisation means cleaning and checking incoming data before acting on it; server-side validation means doing that checking on the server, where the user cannot skip it, rather than trusting the browser.

Step 4: reach another user's rule

The more interesting part is reading someone else's data. The API documentation does not list an id field in the variables, but the researcher added one anyway and it worked. The variables object contains an input object with three keys: spendRuleId, allowed and blocked.

  • spendRuleId is a string, a unique identifier for a spend rule. In the test it was AAAAAAAAAAAAA.
  • allowed is an array with the single string AUTOMATED_FUEL_DISPENSERS, a category allowed under the rule type.
  • blocked is an empty array, meaning no spend categories are blocked under the rule.

With that input, the FindSpendRule GraphQL query returns the user's information. All an attacker has to do is substitute another user's spend rule type ID for spendRuleId, and the response discloses that user's sensitive information, bypassing the access controls.

This is the heart of the bug. An identifier is like a locker number: if the attendant hands over whatever locker you name without checking that it is yours, you can read anyone's contents just by guessing or learning their number. The server should have checked that the requested rule belongs to the logged-in user before returning it, and it did not.

Root cause

The server does not validate the Authorization header with the Bearer token. The rule types feature resolves every type through the same FindSpendRule query, and the resolver does not check that the requested spendRuleId belongs to the caller before returning the record. A resolver is the piece of server code that answers a particular field in a GraphQL request. The documentation does not list an id field in the variables, but adding one worked. The schema is the formal description of what a GraphQL API accepts and returns.

Impact

An authenticated attacker can create rules without proper authorization and, more importantly, read other users' spend rule data by supplying their IDs to FindSpendRule. The exposure covers the whole Rule Types feature, since all types share the query. The report does not describe any further use of the leaked data.

Timeline

  1. 25 January 2023: the issue was reported.
  2. 30 January 2023: HackerOne's triager marked it needs-more-info. A triager is the person who first reads a report and decides whether it is valid and complete.
  3. 31 January 2023: the triager changed the status to Pending program review.
  4. 1 February 2023: a program staff member triaged the report and immediately awarded a $700 bounty.
From the original on 0x1int.gitbook.io

Fix

The report does not say what the program changed. The fix belongs on the server: validate the bearer token on every GraphQL operation, and in the FindSpendRule resolver check that the requested spendRuleId belongs to the authenticated user before returning the record. The same ownership check should apply to the creation mutations, and the schema should not accept identifiers that the documentation does not describe.

Variants to test

  • On other GraphQL APIs, add an undocumented identifier field such as spendRuleId to an input object and see whether the resolver accepts it. A positive result is a record returned for an ID you do not own.
  • Send requests with a missing, malformed or expired Authorization: Bearer header against mutations and queries. A positive result is a successful response instead of an authentication or access-denied error.
  • Take an object ID from one account and use it in a query or mutation from a second account. A positive result is the first account's data appearing in the second account's response.
  • Test every rule type that shares a common query, since a missing check in the shared resolver affects all of them.

Glossary

  • API: the set of doors a website or app uses to exchange data with its servers behind the scenes.
  • GraphQL: a style of API where the client describes exactly which data it wants and the server returns just that.
  • Query: a GraphQL request that reads data.
  • Mutation: a GraphQL request that changes data, such as creating a record.
  • Resolver: the server code that answers a particular field in a GraphQL request.
  • Schema: the formal description of what a GraphQL API accepts and returns.
  • Header: extra information attached to every request, like a label on a parcel.
  • Authorization header: the header that carries proof of who you are.
  • Bearer token: a long string given at login and shown on later requests as proof of identity, like a cloakroom ticket.
  • JSON: a plain text format for structured data, made of keys and values in curly braces.
  • Variables: the values filled into the placeholders declared in a GraphQL request.
  • Array: a list of values in square brackets.
  • Input type: the defined shape of the data a GraphQL operation accepts.
  • Sanitisation: cleaning and checking incoming data before acting on it.
  • Server-side validation: doing that checking on the server, where the user cannot skip it.
  • Access control: the rule that decides who is allowed to see or change what.
  • Bypass: getting past a check without satisfying it.
  • Bug bounty program: a scheme where a company pays people to find and privately report security problems.
  • Triager: the person who first reads a report and decides whether it is valid and complete.
  • Bounty: the money paid for a valid report.
  • Next.js: a JavaScript framework for building websites.
  • Request ID: a label the server attaches to a request so it can find it in its logs later.

Similar reports

View all

Same bug class and techniques, clearest first.

Insecure direct object reference (IDOR)

The lesson behind this report.

One user can read or change another user's data, usually by changing an identifier the server trusts without checking who is asking. One of the most paid bug classes on web programs.