Wilford  Pagac

Wilford Pagac

1596796680

OWASP Top 10 API Security - DZone Security

I am sure that almost all of you would be aware about OWASP. But, just for the context let me just brief about the same.

OWASP is an international non-profit organization that is dedicated to web application security. It is a completely opensource and community driven effort to share articles, methodologies, documentation, tools, and technologies in the field of web application security.

When we talk about API, we are almost every time talking about REST and OWASP has a dedicated project to API security. As this series of articles are focused towards the API security, we shall not be going in details of web application security. You can use the provided links to find more about these. Let us spend some time on the background, before we dive deep in to API security project.

Background

OWASP’s most widely acknowledged project is OWASP top 10. This is the list of security risks compiled by the security experts from across the world. This report is continuously updated, outlining the concerns of web application security, and specially focuses on the Top 10 of the most critical risks. According to OWASP, this report is an “The OWASP Top 10 is a standard awareness document for developers and web application security. It represents a broad consensus about the most critical security risks to web applications.” They recommend that all companies incorporate the report into their processes in order to minimize and/or mitigate security risks. The latest version was published in 2017 and below is the list.

  1. Injection
  2. Broken Authentication
  3. Sensitive Data Exposure
  4. XML Eternal Entities (or XXE)
  5. Broken Access Control
  6. Security Misconfiguration
  7. Cross-Site Scripting (or XSS)
  8. Insecure Deserialization
  9. Using Components With known vulenerabilities
  10. Insufficient Logging And Monitoring

How API Security Is Different from Web Application Security

Although API’s have many similarities with web applications, but both are fundamentally different in nature.

In web applications, all the processing is done on the servers and the resulting web page is sent back to web-browser for rendering. Because of this nature, they have limited entry point and attack surface which are resulting web pages. This can easily be protected by putting up and web-application firewall (WAF) in front of the application server.WAF

In most of the modern application UI itself uses API’s to send and receive data from backend servers and provide the functionality of the application. It is the responsibility of the clients to do the rendering and convert the responses to a web page.

API GET and raw data

Also, with the rise of microservices architecture individual components become APIs, and it becomes a different world altogether, where UI clients could interact with hundreds of services via API calls. This significantly increases the attack surface. Now all those API’s become the entry point and attack surface.

These entry points can’t be guarded using the WAF solutions as they cannot differentiate between the legitimate and malicious API calls.

Why A Separate Project on API security?

Since its first release in 2003 OWASP top 10 projects has been the most useful resource in terms of web application security risks and to suggest the ways to mitigate these issues.

These days almost all the application development like banking, retail, transportation, smart devices, are done with the APIs.

APIs are critical to modern mobile and SaaS application. By nature, the API’s expose business logic and data, often these data are sensitive in nature, for example Personally Identifiable Information (PII). Because of this API’s are increasingly being targeted by attackers.

As API’s are changing how we design and develop our application, this is also changing the way we think about our security. A new approach in needed in terms of security risks. To cater to this need, OWASP decided to come up with another version of Top 10 dedicated to API security which is named “OWASP API Security Project”. The first report was released on 26 December 2019.

Below is the OWASP Top 10 API security risks and their brief description as provided by the official report.

API1:2019 Broken Object Level Authorization

APIs tend to expose endpoints that handle object identifiers, creating a wide attack surface Level Access Control issue. Object level authorization checks should be considered in every function that accesses a data source using an input from the user.

API2:2019 Broken User Authentication

Authentication mechanisms are often implemented incorrectly, allowing attackers to compromise authentication tokens or to exploit implementation flaws to assume other user’s identities temporarily or permanently. Compromising system’s ability to identify the client/user, compromises API security overall.

#security #api security #owasp top 10 #api penetration testing #api security risks #owasp top 10 web security risk

What is GEEK

Buddha Community

OWASP Top 10 API Security - DZone Security
Wilford  Pagac

Wilford Pagac

1596796680

OWASP Top 10 API Security - DZone Security

I am sure that almost all of you would be aware about OWASP. But, just for the context let me just brief about the same.

OWASP is an international non-profit organization that is dedicated to web application security. It is a completely opensource and community driven effort to share articles, methodologies, documentation, tools, and technologies in the field of web application security.

When we talk about API, we are almost every time talking about REST and OWASP has a dedicated project to API security. As this series of articles are focused towards the API security, we shall not be going in details of web application security. You can use the provided links to find more about these. Let us spend some time on the background, before we dive deep in to API security project.

Background

OWASP’s most widely acknowledged project is OWASP top 10. This is the list of security risks compiled by the security experts from across the world. This report is continuously updated, outlining the concerns of web application security, and specially focuses on the Top 10 of the most critical risks. According to OWASP, this report is an “The OWASP Top 10 is a standard awareness document for developers and web application security. It represents a broad consensus about the most critical security risks to web applications.” They recommend that all companies incorporate the report into their processes in order to minimize and/or mitigate security risks. The latest version was published in 2017 and below is the list.

  1. Injection
  2. Broken Authentication
  3. Sensitive Data Exposure
  4. XML Eternal Entities (or XXE)
  5. Broken Access Control
  6. Security Misconfiguration
  7. Cross-Site Scripting (or XSS)
  8. Insecure Deserialization
  9. Using Components With known vulenerabilities
  10. Insufficient Logging And Monitoring

How API Security Is Different from Web Application Security

Although API’s have many similarities with web applications, but both are fundamentally different in nature.

In web applications, all the processing is done on the servers and the resulting web page is sent back to web-browser for rendering. Because of this nature, they have limited entry point and attack surface which are resulting web pages. This can easily be protected by putting up and web-application firewall (WAF) in front of the application server.WAF

In most of the modern application UI itself uses API’s to send and receive data from backend servers and provide the functionality of the application. It is the responsibility of the clients to do the rendering and convert the responses to a web page.

API GET and raw data

Also, with the rise of microservices architecture individual components become APIs, and it becomes a different world altogether, where UI clients could interact with hundreds of services via API calls. This significantly increases the attack surface. Now all those API’s become the entry point and attack surface.

These entry points can’t be guarded using the WAF solutions as they cannot differentiate between the legitimate and malicious API calls.

Why A Separate Project on API security?

Since its first release in 2003 OWASP top 10 projects has been the most useful resource in terms of web application security risks and to suggest the ways to mitigate these issues.

These days almost all the application development like banking, retail, transportation, smart devices, are done with the APIs.

APIs are critical to modern mobile and SaaS application. By nature, the API’s expose business logic and data, often these data are sensitive in nature, for example Personally Identifiable Information (PII). Because of this API’s are increasingly being targeted by attackers.

As API’s are changing how we design and develop our application, this is also changing the way we think about our security. A new approach in needed in terms of security risks. To cater to this need, OWASP decided to come up with another version of Top 10 dedicated to API security which is named “OWASP API Security Project”. The first report was released on 26 December 2019.

Below is the OWASP Top 10 API security risks and their brief description as provided by the official report.

API1:2019 Broken Object Level Authorization

APIs tend to expose endpoints that handle object identifiers, creating a wide attack surface Level Access Control issue. Object level authorization checks should be considered in every function that accesses a data source using an input from the user.

API2:2019 Broken User Authentication

Authentication mechanisms are often implemented incorrectly, allowing attackers to compromise authentication tokens or to exploit implementation flaws to assume other user’s identities temporarily or permanently. Compromising system’s ability to identify the client/user, compromises API security overall.

#security #api security #owasp top 10 #api penetration testing #api security risks #owasp top 10 web security risk

Top 10 API Security Threats Every API Team Should Know

As more and more data is exposed via APIs either as API-first companies or for the explosion of single page apps/JAMStack, API security can no longer be an afterthought. The hard part about APIs is that it provides direct access to large amounts of data while bypassing browser precautions. Instead of worrying about SQL injection and XSS issues, you should be concerned about the bad actor who was able to paginate through all your customer records and their data.

Typical prevention mechanisms like Captchas and browser fingerprinting won’t work since APIs by design need to handle a very large number of API accesses even by a single customer. So where do you start? The first thing is to put yourself in the shoes of a hacker and then instrument your APIs to detect and block common attacks along with unknown unknowns for zero-day exploits. Some of these are on the OWASP Security API list, but not all.

Insecure pagination and resource limits

Most APIs provide access to resources that are lists of entities such as /users or /widgets. A client such as a browser would typically filter and paginate through this list to limit the number items returned to a client like so:

First Call: GET /items?skip=0&take=10 
Second Call: GET /items?skip=10&take=10

However, if that entity has any PII or other information, then a hacker could scrape that endpoint to get a dump of all entities in your database. This could be most dangerous if those entities accidently exposed PII or other sensitive information, but could also be dangerous in providing competitors or others with adoption and usage stats for your business or provide scammers with a way to get large email lists. See how Venmo data was scraped

A naive protection mechanism would be to check the take count and throw an error if greater than 100 or 1000. The problem with this is two-fold:

  1. For data APIs, legitimate customers may need to fetch and sync a large number of records such as via cron jobs. Artificially small pagination limits can force your API to be very chatty decreasing overall throughput. Max limits are to ensure memory and scalability requirements are met (and prevent certain DDoS attacks), not to guarantee security.
  2. This offers zero protection to a hacker that writes a simple script that sleeps a random delay between repeated accesses.
skip = 0
while True:    response = requests.post('https://api.acmeinc.com/widgets?take=10&skip=' + skip),                      headers={'Authorization': 'Bearer' + ' ' + sys.argv[1]})    print("Fetched 10 items")    sleep(randint(100,1000))    skip += 10

How to secure against pagination attacks

To secure against pagination attacks, you should track how many items of a single resource are accessed within a certain time period for each user or API key rather than just at the request level. By tracking API resource access at the user level, you can block a user or API key once they hit a threshold such as “touched 1,000,000 items in a one hour period”. This is dependent on your API use case and can even be dependent on their subscription with you. Like a Captcha, this can slow down the speed that a hacker can exploit your API, like a Captcha if they have to create a new user account manually to create a new API key.

Insecure API key generation

Most APIs are protected by some sort of API key or JWT (JSON Web Token). This provides a natural way to track and protect your API as API security tools can detect abnormal API behavior and block access to an API key automatically. However, hackers will want to outsmart these mechanisms by generating and using a large pool of API keys from a large number of users just like a web hacker would use a large pool of IP addresses to circumvent DDoS protection.

How to secure against API key pools

The easiest way to secure against these types of attacks is by requiring a human to sign up for your service and generate API keys. Bot traffic can be prevented with things like Captcha and 2-Factor Authentication. Unless there is a legitimate business case, new users who sign up for your service should not have the ability to generate API keys programmatically. Instead, only trusted customers should have the ability to generate API keys programmatically. Go one step further and ensure any anomaly detection for abnormal behavior is done at the user and account level, not just for each API key.

Accidental key exposure

APIs are used in a way that increases the probability credentials are leaked:

  1. APIs are expected to be accessed over indefinite time periods, which increases the probability that a hacker obtains a valid API key that’s not expired. You save that API key in a server environment variable and forget about it. This is a drastic contrast to a user logging into an interactive website where the session expires after a short duration.
  2. The consumer of an API has direct access to the credentials such as when debugging via Postman or CURL. It only takes a single developer to accidently copy/pastes the CURL command containing the API key into a public forum like in GitHub Issues or Stack Overflow.
  3. API keys are usually bearer tokens without requiring any other identifying information. APIs cannot leverage things like one-time use tokens or 2-factor authentication.

If a key is exposed due to user error, one may think you as the API provider has any blame. However, security is all about reducing surface area and risk. Treat your customer data as if it’s your own and help them by adding guards that prevent accidental key exposure.

How to prevent accidental key exposure

The easiest way to prevent key exposure is by leveraging two tokens rather than one. A refresh token is stored as an environment variable and can only be used to generate short lived access tokens. Unlike the refresh token, these short lived tokens can access the resources, but are time limited such as in hours or days.

The customer will store the refresh token with other API keys. Then your SDK will generate access tokens on SDK init or when the last access token expires. If a CURL command gets pasted into a GitHub issue, then a hacker would need to use it within hours reducing the attack vector (unless it was the actual refresh token which is low probability)

Exposure to DDoS attacks

APIs open up entirely new business models where customers can access your API platform programmatically. However, this can make DDoS protection tricky. Most DDoS protection is designed to absorb and reject a large number of requests from bad actors during DDoS attacks but still need to let the good ones through. This requires fingerprinting the HTTP requests to check against what looks like bot traffic. This is much harder for API products as all traffic looks like bot traffic and is not coming from a browser where things like cookies are present.

Stopping DDoS attacks

The magical part about APIs is almost every access requires an API Key. If a request doesn’t have an API key, you can automatically reject it which is lightweight on your servers (Ensure authentication is short circuited very early before later middleware like request JSON parsing). So then how do you handle authenticated requests? The easiest is to leverage rate limit counters for each API key such as to handle X requests per minute and reject those above the threshold with a 429 HTTP response. There are a variety of algorithms to do this such as leaky bucket and fixed window counters.

Incorrect server security

APIs are no different than web servers when it comes to good server hygiene. Data can be leaked due to misconfigured SSL certificate or allowing non-HTTPS traffic. For modern applications, there is very little reason to accept non-HTTPS requests, but a customer could mistakenly issue a non HTTP request from their application or CURL exposing the API key. APIs do not have the protection of a browser so things like HSTS or redirect to HTTPS offer no protection.

How to ensure proper SSL

Test your SSL implementation over at Qualys SSL Test or similar tool. You should also block all non-HTTP requests which can be done within your load balancer. You should also remove any HTTP headers scrub any error messages that leak implementation details. If your API is used only by your own apps or can only be accessed server-side, then review Authoritative guide to Cross-Origin Resource Sharing for REST APIs

Incorrect caching headers

APIs provide access to dynamic data that’s scoped to each API key. Any caching implementation should have the ability to scope to an API key to prevent cross-pollution. Even if you don’t cache anything in your infrastructure, you could expose your customers to security holes. If a customer with a proxy server was using multiple API keys such as one for development and one for production, then they could see cross-pollinated data.

#api management #api security #api best practices #api providers #security analytics #api management policies #api access tokens #api access #api security risks #api access keys

Brain  Crist

Brain Crist

1597266000

OWASP TOP 10 API Security Part 2 (Broken Object Level Authorization)

In the previous article, we had them build our ground around OWASP’s top ten projects and covered the brief official definition of OWASP Top 10 for API security.

In this article, we will explore the first of the OWASP Top 10 API security risks for the year 2019. (API1:2019 - Broken object-level authorization).

Context

In most of the API implementations, where we have to get some data which is specific to some object, Reference of the internal object implementation is exposed, for example: “id”, “pid”, “uid” and so on. Although in most cases this reference is visible as part of the HTTP parameter itself, but these could also be part of headers and cookies.

The problem here is that it reveals the real identifier and format/pattern used of the element in the storage backend side. The most common example of it (although is not limited to this one) is a record identifier in a storage system (database or filesystem).

Once the pattern is identified, the malicious user can easily guess/autogenerate the reference ID’s and modify the requests to supply the reference ID’s that do not belong to them.

If the API implementation does not have proper measures in place, then these malicious requests can cause revelations, modifications, or even deletion of records in the backend.

Just because the direct object reference checks were not in place or misconfigured. That is the reason this attack is also known as Insecure Direct Object Reference or IDOR in short.

Use Case

Let us assume that we have an API implementation that gets the financial information of a user. And to get the details the API expects the user id as parameter.

  1. API call parameters use the ID of the resource accessed through the API /API/user1/financial_info.
  2. By proxying and intercepting the URL’s attacker can guess the format of the parameter (user1).
  3. Attackers replace the IDs of their resources with a different one which they guessed through /API/user2/financial_info.
  4. As there is no measure to check the check permissions, the API returns data for user2. Which, it should not have.
  5. This could cause further issues if IDs can be enumerated and calls are automated to scrape though the data available with the UI /api/{AUTOMATED_USER_ID_HERE}/financial_info.

api users

How to Prevent it

If we have to summarize then we can say, IDOR is a combination of two issues

  1. Enumerable identifiers, which could easily be guessed.
  2. Insufficient checking of access rights on the requests.

So, the solution to prevent IDOR completely has to address both the issues, Below are some of the recommendations.

  • API should verify that the current user has permission to access the object, every time access is attempted. For example, if a user has access to record 3 and no others, any attempt to access record 4 should be rejected.
  • The API should validate both read and write requests, it should not be the case that a user can write to a record, even without having the read permission to it, such scenarios may allow the further compromise of the system. For example, if a PUT request made to /data/1 contains a sensitive value, it is important to check that the same PUT request cannot be made to /data/2, even if it is known that GET /data/2 is rejected.
  • Implement authorization checks with user policies and hierarchy.
  • Do not rely on IDs that the client sends. Use IDs stored in the session object instead.
  • Check authorization for each client request to access the database.
  • Use random IDs that cannot be guessed (UUIDs).
  • idor preventionIDOR Prevention

Sample Application

As we saw earlier that our solution has to address both the Access and predictable ID issue. Let us try to build an application to demonstrates the same. Please be advised that this application is meant for demonstration purposes only.

So, our hypothetical application has a requirement that the users shall be able to get his data (e.g. financial details). Now, the API design could take user-id as input and serve returns the financial details belonging to the user. The common implementation approach for the API will be to have the user id as path parameters or as part of headers. Let’s say we choose the path parameter. Then our API will look something like this. And it works as expected.

PowerShell

1

http://localhost:9999/getdata-IDOR-vulnerable/user_2

But by analyzing the request we can see that the input is user_1, what if we supply **user_2? **

PowerShell

1

http://localhost:9999/getdata-IDOR-vulnerable/user_2

Voila! it works again. Thus, it is clear that **user_x ** is a reference to internal ID. Now, what if we somehow automate this parameter using some tool, or even simple programming? We can get the data of all the users available in the system.

PowerShell

1

http://localhost:9999/getdata-IDOR-vulnerable/user_2

2

http://localhost:9999/getdata-IDOR-vulnerable/user_3

3

http://localhost:9999/getdata-IDOR-vulnerable/user_4

4

.

5

.

6

.

7

http://localhost:9999/getdata-IDOR-vulnerable/user_N

We leaked all the data just because someone was able to guess the reference ID.

So, what if we use something difficult or random to guess? We solve one part of our problem.

One of the possible ways could be that we use these complex ID’s (something like UUID) in our backend system, or we can wrap our data fetch logic around some utility class or filter which does this job for each request. In a very basic example, we could write something like below.

Java

1

package org.sk.owasp.api.security.idor.util;

2

3

import java.util.Base64;

4

import org.springframework.stereotype.Service;

5

/**

6

 * <strong>FOR DEMONSTRATION ONLY, NOT TO BE USED IN PRODUCTION.</strong><br>

7

 * As this code is for demonstration purpose only. {@link Base64} is used to encypt-decrypt the ID's. This algorithm is not considered safe and can be

8

 * decoded easily. 

9

 * In real world scenario you shall be using more sophisticated algorithms or something like UUID

10

 *  Access check in intentionaly left from the code.

11

 * @author Satish Sharma

12

 *

13

 */

14

@Service

15

public class IdorUtility {

16

17

    // this could be externalized to configuration.

18

    private String saltString="S3cUr#d1Ds1L$";

19

20

    public String computeObfuscatedId(String actualIdentifier) {

21

        String saltedString = actualIdentifier + saltString;

22

        return new String(Base64.getEncoder().encode(saltedString.getBytes()));

23

    }

24

25

    public String resolveObfuscatedId(String obfuscatedIdentifier) {

26

        var decodedBit = Base64.getDecoder().decode(obfuscatedIdentifier);

27

        String decodedSaltedString = new String(decodedBit);

28

        return decodedSaltedString.replace(saltString, "");

29

    }

30

}

Once we wrap our service call around the encode-decode utility class. As we have encoded all the identifiers with Base64, The API request will change something like below. Notice the change in the path parameter in the URL.

PowerShell

1

http://localhost:9999/getdata-IDOR-secured/dXNlcl8zUzNjVXIjZDFEczFMJA%3D%3D

As we can see now the IDs cannot be guessed easily. Combined the above code with authorization mechanism (left intentionally from this code). We address both the issues, and hence prevent the IDOR.

You can find the sample spring-boot application at this GitHub location. In the next article, we shall be addressing **API2:2019 Broken User Authentication. **

Thank you for reading. If any questions or comments please share them, I would be happy to hear.

#security #spring boot 2 #owasp top 10 #api penetration testing #owasp top 10 web security risk #broken api

Autumn  Blick

Autumn Blick

1601385115

API Security Weekly: Issue #101

After the special 100th edition last week, which was all about API security advice from the industry’s thought leaders, this week we are back to our regular API security news, and we have twice the number of them, from the past two weeks.

Vulnerability: Giggle

Giggle is a women-only social network and mobile app. It is meant to be a safe place for everyone on the network but, turns out it was not all that safe: researchers from Digital Interruption found some serious API flaws in it.

The team ran the app through a proxy and observed the API traffic. They found that the API behind the app effectively had a query language:

This meant that they could query any user record:

The API returned full user info, even when the queried record was another user (classical BOLA/IDOR):

#security #integration #api #cybersecurity #apis #api security #api vulnerabilites #api newsletter #security newsletter

Autumn  Blick

Autumn Blick

1601381326

Public ASX100 APIs: The Essential List

We’ve conducted some initial research into the public APIs of the ASX100 because we regularly have conversations about what others are doing with their APIs and what best practices look like. Being able to point to good local examples and explain what is happening in Australia is a key part of this conversation.

Method

The method used for this initial research was to obtain a list of the ASX100 (as of 18 September 2020). Then work through each company looking at the following:

  1. Whether the company had a public API: this was found by googling “[company name] API” and “[company name] API developer” and “[company name] developer portal”. Sometimes the company’s website was navigated or searched.
  2. Some data points about the API were noted, such as the URL of the portal/documentation and the method they used to publish the API (portal, documentation, web page).
  3. Observations were recorded that piqued the interest of the researchers (you will find these below).
  4. Other notes were made to support future research.
  5. You will find a summary of the data in the infographic below.

Data

With regards to how the APIs are shared:

#api #api-development #api-analytics #apis #api-integration #api-testing #api-security #api-gateway