APISec - Best Practices For API Security
APISec - Best Practices For API Security
Dan Barahona
[email protected]
apisec.ai
A decade ago, securing a company’s web interfaces
was a straightforward affair, and website
vulnerabilities were well understood. Periodic
scanning and manual penetration testing provided
some assurance that a company’s web and mobile
applications were resistant to hacking. Since then,
the world of web applications has changed radically,
with Application Programming Interfaces, or APIs,
transforming how organizations build, manage, and
scale their web and mobile services.
RESTful APIs became widely adopted, using HTTP verbs and endpoints that resembled
the organization of web-based sites. Developers and IT shops found an easy familiarity
with a tech that has massive potential. By 2019, Akamai, the leading content delivery
network, reported that 83% of all internet traffic was now generated by APIs.
The problem is that web applications remain a primary target for breaches (90%
according to Verizon) and that APIs now make up 90% of the web app attack surface
area. This led Gartner to forecast that by 2022, APIs will become the “most frequent
attack vector”.
Of OWASP’s top ten API vulnerabilities only one involves a classic security attack
vector, number eight, which covers various SQL injection vulnerabilities -
acknowledging the unique challenges of securing API-based applications. Four of the
top five vulnerabilities all involve logical errors in the software stack that are unique to
each organization and each API, and are difficult to identify with traditional testing
methodologies.
In fact, the common thread among most API breaches is that these are not classic
security attacks and vulnerabilities. These breaches are the result of business logic
flaws and loopholes in the API itself. Developers are taught to never trust user data,
but APIs allow attackers to modify request properties in unexpected ways that are
difficult to test for given the huge number of possible attack scenarios. In the rush to
push more code, functionality and fixes into production, developers often introduce
unintended access vulnerabilities as well. Here are some specific examples:
In light of the
machine-to-machine nature of
Real-world example
APIs, these resources are Instagram allowed password resets by
especially vulnerable to highly sending a 6 digit code to the account
automated, high volume denial owner’s device, giving the user 10
minutes to provide the correct code.
of service attacks. These
Instagram also limited code
attacks can come from many submissions to no more than 200
different IPs, target different attempts per IP address. However,
API functionality and data. there was no restriction on the number
of attempts per user account. A hacker
Without restrictions on
discovered the API for submitting
frequency and volume of API security codes and setup a farm of
requests attackers can servers on AWS, each with a different IP
brute-force password resets, address, allowing the hacker to run
through all 1 million possible 6 digit
harvest user information,
codes in less than 10 minutes and take
impact performance, and over any account of their choosing.
download massive quantities of
proprietary information.
Building security testing into a company’s CI/CD pipeline is a common first line of
defense. This approach focuses on the code itself, adding Static Analysis Security
Testing (SAST) and other code quality solutions to the continuous integration workflow.
There are well established vendors in this segment, and SAST can help enormously
with ensuring the quality and maintainability of a codebase and to identify common,
well-known coding issues and vulnerabilities. However, static code analysis is
incapable of identifying the types of logic flaws that lead to major API breaches and
data loss.
The primary issues with code analysis and API firewalling is that these technologies
focus primarily on classic security-oriented vulnerabilities such as SQL injection
attacks, cross-site scripting, buffer overflows, etc. As we saw earlier, these are not the
causes of the vast majority of API breaches - these breaches are a result of the
business logic flaws that are unique to each API and cannot be detected or prevented
with standard approaches.
Meanwhile, organizations continue to operate at the speed of DevOps, with new code
pushed to production every day. As a result, defects make it into production, creating
vulnerabilities and leading to serious breaches as described earlier.
Scale
The coverage problem leads to the scale problem. How do you create test scenarios to
cover the entire range of API functionality. Consider a relatively lightweight API with,
say, 50 endpoints. Each of those endpoints can support multiple POST, GET, PUT and
DELETE methods. Quickly you’re already up to ~250 endpoint-method permutations.
And then consider the myriad API breach categories as described by the OWASP API
Security Top 10 - pushing testing requirements to thousands of unique attacks. Testing
needs to cover all these permutations and scenarios, otherwise vulnerabilities will
make it to production waiting to get discovered by someone else.
Speed
Speed in CI/CD time means seconds or minutes. When fixes and new functionality
need to move to production, testing cannot delay progress. However, given the
complexity of APIs, the breadth of scenarios to cover, testing speed is more often
measured in weeks or months.
The APIsec approach to API security begins with learning the API: cataloging all
available endpoints and identifying supported methods. This approach is 100%
automated and allows critical API vulnerabilities to be addressed before a company’s
product reaches Production. This allows approach offers major advantages to static
code analysis, API firewalling, and manual pen testing:
After completing the vulnerability analysis, APIsec integrates results into the CI/CD
pipeline, creates trouble tickets in popular systems like Github and Jira, produces
pen-test reports suitable for submission to FedRAMP auditors and compliance officers,
and provides an easy-to-use dashboard for visualizing and managing changes to an API
over time. The dashboard allows replaying the attack to show the exact nature of the
vulnerability, and automatically calculates Common Vulnerability Scoring System
(CVSS) severity scores.