# Business Logic Tests

{% hint style="danger" %}
**At a Glance**: ⚠️ Business logic API attacks exploit weaknesses in the underlying logic of an API to gain unauthorized access or manipulate data. Developers must understand these issues to prevent security breaches.
{% endhint %}

***

## What are the common mistakes made by developers?

In most cases Business logic issues happen when authorization is not enforced through all the flows of the application. Modern applications usually assign a non guessable identifiers to users and resources.&#x20;

Consider the following example:

```python
def get_profile(self, getprofile_request, context):
    cursor, conn = connection_to_sql(f"GET_PROFILE_BL {getprofile_request}")
    cursor.execute('select * from profiles where uid=?',(getprofile_request.uid,))
    p = cursor.fetchone()
```

The function get\_profile accepts the User ID as uid and directly querying the database to get this user's profile without any validation that the logged in user is the same user that is represented by the uid.

## How can I fix Business Logic issues?

Ensure that only authorized users can access the API and that access is granted on a need-to-know basis. Use strong authentication methods such as multi-factor authentication and implement authorization checks at the API endpoint level.&#x20;

## Test cases in this category

These test cases test the enforce of authorization between user identifiers, resource identifiers and the actual logged in users on APIs that **read** user related data

<table><thead><tr><th>Test case</th><th width="226.33333333333331">OWASP</th><th>CWE</th><th data-hidden></th></tr></thead><tbody><tr><td><strong>[BL001]</strong> User data leakage to other users - Resource-ID authorization</td><td><a href="https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa1-broken-object-level-authorization.md">API1 OWASP API Top 10</a></td><td><a href="https://cwe.mitre.org/data/definitions/285.html">CWE-285</a>, <a href="https://cwe.mitre.org/data/definitions/284.html">CWE-284</a>, <a href="https://cwe.mitre.org/data/definitions/639.html">CWE-639</a></td><td></td></tr><tr><td><strong>[BL002]</strong> User data leakage to other users - User-ID authorization</td><td><a href="https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa1-broken-object-level-authorization.md">API1 OWASP API Top 10</a></td><td><a href="https://cwe.mitre.org/data/definitions/285.html">CWE-285</a>, <a href="https://cwe.mitre.org/data/definitions/284.html">CWE-284</a>, <a href="https://cwe.mitre.org/data/definitions/639.html">CWE-639</a></td><td></td></tr><tr><td><strong>[BL003]</strong> User data leakage to other users - Resource-ID and User-ID authorization</td><td><a href="https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa1-broken-object-level-authorization.md">API1 OWASP API Top 10</a></td><td><a href="https://cwe.mitre.org/data/definitions/285.html">CWE-285</a>, <a href="https://cwe.mitre.org/data/definitions/284.html">CWE-284</a>, <a href="https://cwe.mitre.org/data/definitions/639.html">CWE-639</a></td><td></td></tr><tr><td><strong>[BL004]</strong> User data leakage to other users - credentials authorization</td><td><a href="https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa1-broken-object-level-authorization.md">API1 OWASP API Top 10</a></td><td><a href="https://cwe.mitre.org/data/definitions/285.html">CWE-285</a>, <a href="https://cwe.mitre.org/data/definitions/284.html">CWE-284</a>, <a href="https://cwe.mitre.org/data/definitions/639.html">CWE-639</a></td><td></td></tr></tbody></table>

These test cases test the enforce of authorization between user identifiers, resource identifiers and the actual logged in users on APIs that **write** user related data

| Test case                                                                                  | OWASP                                                                                                                          | CWE                                                        |
| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------- |
| **\[BL005]** User data manipulation by other users - Resource-ID authorization             | [API5 OWASP Top 10](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa5-broken-function-level-authorization.md) | [CWE-285](https://cwe.mitre.org/data/definitions/285.html) |
| **\[BL006]** User data manipulation by other users - User-ID authorization                 | [API5 OWASP Top 10](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa5-broken-function-level-authorization.md) | [CWE-285](https://cwe.mitre.org/data/definitions/285.html) |
| **\[BL007]** User data manipulation by other users - Resource-ID and User-ID authorization | [API5 OWASP Top 10](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa5-broken-function-level-authorization.md) | [CWE-285](https://cwe.mitre.org/data/definitions/285.html) |
| **\[BL008]** User data manipulation by other users - credentials authorization             | [API5 OWASP Top 10](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa5-broken-function-level-authorization.md) | [CWE-285](https://cwe.mitre.org/data/definitions/285.html) |

This test case try to guess values of user Identifiers with a numeric structure

| Test case                                  | OWASP                                                                                                                          | CWE |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | --- |
| **\[BL009]** Guessable resource identifier | [API1 OWASP Top 10](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa5-broken-function-level-authorization.md) |     |
