• Browse topics
Login
Login

SNYK LEARN LOGIN

OTHER REGIONS

For Snyk Enterprise customers with regional contracts. More info

Broken object level authorization

Failing to enforce proper permissions

Select your ecosystem

Broken object level authorization: the basics

What is broken object level authorization?

Broken object level authorization (BOLA) arises when an API fails to enforce proper permissions for individual objects within its endpoints. BOLA allows attackers to manipulate object identifiers (such as IDs) to access or modify resources they shouldn’t have access to. This is typically due to missing or inadequate authorization checks for specific object references at the API level.

For instance, an e-commerce API may permit an attacker to fetch or alter sensitive data, such as customers' postal addresses, by replacing an object ID in the request URL or payload for an "orders" endpoint. BOLA can lead to unauthorized access, data manipulation, and even deletion of critical resources.

In this lesson, you will learn how BOLA vulnerabilities work and how to secure your APIs against them. We will explore a real-world-inspired exploit scenario, dissect the vulnerability, and provide mitigations and secure coding practices.

FUN FACT

The widespread vulnerability of APIs

In a 2023 survey, over 75% of API vulnerabilities reported were related to improper access control, with BOLA leading the pack. It remains the most exploited API vulnerability globally.

Broken object level authorization in action

Let's walk through an example of broken object level authorization.

Testing for BOLAs

  • STEP 1
  • STEP 2
  • STEP 3
  • STEP 4
  • STEP 5

Setting the stage

Step into the shoes of Jane, a developer testing the API of a car rental company. The API offers the ability to manage car rentals. Let's start!

BOLA-1.svg

Broken object level authorization under the hood

To understand this vulnerability, let’s analyze how the server processes requests:

  • The API relies solely on the id parameter from the client request to fetch data from the database.
  • No checks are performed to confirm if the requesting user has permission to access the resource.

The lack of validation leads to unauthorized access, making this a classic BOLA vulnerability.

This Java code is vulnerable to broken object level authorization because it directly uses the id parameter from the URL to query reservations in the database without verifying the requester's identity. This allows attackers to manipulate the id parameter and access reservation data for other users. To mitigate this, the application should validate that the ID corresponds to the currently authenticated user before executing the query.

In this snippet, the offending line is List<Reservation> reservations = repository.findByUserId(id);

The line queries the repository for reservations associated with the provided id, but it never validates if that id belongs to the authenticated user.

What is the impact of broken object level authorization?

BOLA vulnerabilities can have devastating security implications. The criticality of any one particular BOLA vulnerability depends on the sensitivity and quantity of data that can be edited or accessed by the attacker. At worst, the exploitation of a BOLA vulnerability could result in a mass-scale data breach.

It's important to note that BOLA vulnerabilities aren't just about accessing data, it's also about editing or deleting data, so the impacts also expand to data integrity issues and service disruptions. Again, the full impact will be determined by the functionality that is being abused.

When determining impact, it's also pertinent to consider the likelihood that the vulnerability will be discovered and exploited. Because BOLA is quite a simple class of vulnerability, it is highly likely that it will be discovered and exploited when compared to more complex vulnerability classes.

Scan your code & stay secure with Snyk - for FREE!

Did you know you can use Snyk for free to verify that your code
doesn't include this or other vulnerabilities?

Scan your code

Broken object level authorization mitigation

How do you mitigate broken object level authorization?

Mitigating BOLA will depend on the specific nature of the application, but in general it requires using policies and server-side checks to validate user permissions for each resource. It is best if this can be achieved further up the stack - for example by using middleware or framework features to enforce authorization checks globally, rather than needing to custom-code permissions checks on every endpoint.

Another mitigating factor is the format of object IDs. If incrementing integers are used to identify objects, then they are easy to guess. Using the same example as above, if an attacker wanted to enumerate the reservations of all users they could write a basic script that pulls all details from each URL, like this:

For this reason, it's best to use object IDs that are not as predictable, such as UUIDs, that way if an attacker has no way of enumerating the UUIDs, even if no other access controls are implemented, it will be very difficult to exploit at scale. It should be noted that this is not a full mitigation for BOLA vulnerabilities, only a mitigating factor.

The updated code snippet demonstrates how to mitigate a BOLA vulnerability by implementing robust authorization checks.

In this snippet, the authenticated user's ID is securely retrieved using the getCurrentUserId() method, which is set during the authentication process. The code then compares the authenticated user's ID (currentUserId) with the id parameter provided in the URL via the @PathParam annotation. If they do not match, the server responds with a 403 Forbidden status by returning a Response with the appropriate status and error message, ensuring that users cannot access data belonging to others.

After passing the authorization check, the code fetches the reservations for the authenticated user by calling repository.findByUserId(currentUserId). This query ensures that only the reservations associated with the authenticated user are retrieved.

Quiz

Test your knowledge!

Quiz

Which of the following best describes how authentication impacts the prevention of Broken Object Level Authorization (BOLA) vulnerabilities?

Keep learning

Learn more about API security and BOLA from these resources:

Congratulations

You’ve taken the first step in understanding BOLA vulnerabilities, their impact, and how to mitigate them. Apply this knowledge to secure your APIs and ensure robust access control mechanisms. Explore other lessons to continue your journey in application security!