API Security White Paper
API Security White Paper
We all know by now that APIs, application programming interfaces, make the world go around.
More precisely, they let distinct modern applications communicate with each other. Mobile or
web applications can access a backend where data is stored and processed. APIs can be public
allowing applications from different companies to communicate or private, which is common,
where internal applications integrate to meet business goals.
The result? More robust, full-fledged applications, websites and mobile apps with broader
functionality and more diverse data.
For instance, rather than creating their own payment services from scratch, ride-sharing
companies can add it via the APIs of payment companies. Another example are flight aggregator
sites. In order to show us flight times, prices, destinations and everything else we need to know
about a plane ticket, they connect via API calls to airline databases to pull the right data and
display it to us in our aggregator search results page.
The importance of APIs are growing, with more and more companies describing themselves as
“API-first.” In some cases, a company’s actual product is an API with a business model centered
on consuming it. For instance, if a company that provides weather data has made their API their
product, other companies who want weather info will pay them a monthly fee for API access. In
many other instances, given the expectation an application must interact with other applications,
APIs are designed alongside or even before the code that delivers actual product functionality–
not bolted on at the end of development.
Companies devote time and effort to deliberately craft their API approach to consider how it can
expose the right data, becoming foundational to revenue and business models.
However, building perfect APIs is tough, because just like any piece of software, vulnerabilities will
happen, leading to the security challenges we’ll discuss in this document.
Suffice it to say, APIs are everywhere and will only gain momentum in the coming years–and they
must be protected. For this reason, we’ll examine API attacks and aspects of defense-in-depth
when thinking through organizational API security.
Programmable Web1 notes there are more than 24,000 published, well-known APIs. It turns out
however most APIs are private, linking internal applications together. Estimates of the number of
private APIs are in the millions.
And when we say APIs are gaining momentum, Cloudflare is a first-hand witness to their growth.
According to data from Cloudflare Radar from the first half of 2021, roughly half the traffic on the
Cloudflare network was API-related. What’s more, it increased 61 percent from 2020 to 2021.
Given that they expose important data, we can start to see how they represent an enormous new
attack surface we must protect. How do we know this? There have been many prominent attacks
in recent years targeting APIs.
1
https://www.programmableweb.com/apis/directory
An Expanding Attack Surface In 2019, JustDial, a large local search engine in India,
effectively leaked all customer data when they left older
versions of APIs, that had since been replaced by newer
versions, exposed. It gets worse–there was effectively
We now know that APIs are everywhere and fundamental
no authentication in place, meaning anyone could call
to the success of modern business. They expose
the APIs and scrape data from the production server. Put
application logic and can share sensitive data with
another way, no advanced techniques were required to
other applications.
access user data.
It turns out however, in a surprise to no one, that
Facebook, despite their leadership with GraphQL, has
attackers know this and have every intention of
also suffered multiple breaches at the hands of their
exploiting this expanding attack surface in the enterprise.
APIs. For instance in late 2019, Facebook had a database
Maybe Gartner was right when they asserted2 that by scraped, putting the names, phone number and user IDs
2022, API abuses will “move from an infrequent to the of more than 260 million users at risk.
most-frequent attack vector, resulting in data breaches
There is a long list of organizations who have had
for enterprise web applications.”
trouble securing APIs. There are a number of reasons
Whether APIs become the most frequently targeted why. First, underlying API vulnerabilities due to insecure
attack vector remains to be seen, but it is clear APIs will design open the door to attacks. What is more, to date,
continue to be in attacker crosshairs. organizations have not had API-first security tools.
We say “continue” because the world has already Perhaps they would use web security tools like WAFs or
witnessed some high-profile breaches at the hands rate limiting but those were built to protect applications–
of weak API security or API development that did not not APIs. This can lead to challenges like false positives
account for security. and makes clear the need for API security designed for
traffic that is largely automated.
T-Mobile fell victim to an API attack in 2017 when 15
million customers who bought new devices or applied
for T-Mobile accounts had their information exposed.
Data included names, addresses, birth dates, Social
Security numbers, drivers license numbers and passport
numbers. Vice reported the attack was carried out
by adjusting the phone number parameter in the API
call. Any user’s phone number could be queried and
the T-Mobile API would send responses including the
sensitive account data of the person whose phone
number was queried.
Another API-related breach hit the USPS when an API
that supported real-time package tracking was found to
lack basic authorization. When a user was logged in, they
could query for account information of any other user,
via use of wildcard search parameters that would cough
up all the records of the data set. This put the data of 60
million USPS account holders at risk.
2
Source: Gartner: “API Security: What You Need to Do to Protect
Your APIs”, March 2021
6. Mass Assignment
A silver lining in all of this is that the OWASP Foundation,
an organization long-focused on improving application
security, has gotten involved. OWASP is known for its 7. Security Misconfiguration
Top 10 Web Application Security Risks and now they
have published the API Security Top 10, a list of top API
security risks and vulnerabilities. 8. Injection
The truth is, what has long worried us about application
security, also holds true for building and securing APIs. 9. Improper Assets Management
To begin with, any organization that is API-first, must
consider security upfront, as they design their APIs. Let’s 10. Insufficient Logging & Monitoring
examine some of the attacks we just mentioned, and the
OWASP security risk they exploited.
API path and query parameters include the resource ID being accessed:
Authorized call:
Manipulated API calls can gain unauthorized access by changing 235 to 236, that is, adjusting the
object identifier, the userID in this case, to access data for user 236.
GET api.greatsampleapis.com/v1/users/236
If authorization controls are not in place, this can be successful. Developers should threat-model
their endpoint to make sure attacks cannot adjust or modify an object’s ID value to gain access
to other data. Use of unpredictable object ID values can also help so they are not sequential and
easy to guess.
{
“Id”: 213,
“FirstName”:”Sanjay”,
“LastName”:”Smythe”,
“EmailAddress”:”[email protected]”,
“Occupation”: “Assistant to the Deputy Associate Vice Sub-undersecretary”,
“DOB”:”1986-05-21”,
“Bank”:”Easygo Financial”,
“AccountNumber”: 1362886306,
“PetName”: “Aloysius”,
}
Mass Assignment attacks allow for API calls to alter or exploit internal values when APIs expose
internal objects and variables.
OWASP puts it this way:
“Software frameworks sometime allow developers to automatically bind HTTP request
parameters into program code variables or objects to make using that framework easier on
developers... Attackers can sometimes use this methodology to create new parameters that
the developer never intended which in turn creates or overwrites new variable or objects in
program code that was not intended.”
What should developers do? They should understand the potential risks when calling on mass
assignment in development and steer clear of exposing any internal objects or variables that can
be exploited. Allowlisting properties that can be updated by clients should also be considered.
Web applications have long been susceptible to injection attacks and APIs are no different. Given
how well known injection attacks are, we will not dwell on them, but suffice it to say inputs should
be validated and sanitized before being passed on. Efforts should be made to use data leak
prevention on API responses and limit the number of records that can be returned to prevent
a mass disclosure incident.
Foundation of visibility
Visibility
Like with other aspects of security, we have to see something in order to protect it. APIs are no
different, particularly when companies have hundreds or even thousands of API endpoints.
API discovery and visibility is a key foundational aspect to governing APIs so organizations
always have a clear snapshot of their API endpoint estate to prevent shadow or rogue APIs from
becoming an issue.
As we saw with JustDial, if organizations lose track of APIs, this can lead to data breaches.
API Defense-in-depth
API L7 protections
We have long deployed web application firewalls to protect applications against layer 7 DDoS
attacks. API protection should begin with many of these dependable controls like rate limiting
and DDoS protection to ward off denial-of-service attacks and brute-force login attempts and
general abuse carried out by specific IP addresses. This will enforce API usage limits and ensure
availability combatting OWASP API 4—Lack of Resources & Rate Limiting.
WAF rules should also be used to identify and block common attacks targeting APIs.
Schema Validation evaluates each request against an API Schema logging or blocking requests that do not comply with it.
© 2021 Cloudflare Inc. All rights reserved. The Cloudflare logo is a trademark
of Cloudflare. All other company and product names may be trademarks of
the respective companies with which they are associated.