API2:2019 - Broken User Authentication
Tags: cybersecurity, owasp, api, hacking
Published: 2021-12-22 15:15:49

Continuing our series about the OWASP API Security Top 10, this time we are going to talk a little bit about Broken User Authentication. Hope you like it :hugs:

## :thinking: User Authentication, What is it?

Imagine a login page, which asks you for both your email address and your password.


![Login page, asking for email and password](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/979iql49q4934s6f60vt.png)

These are some possible interactions you might have with the page, and the expected responses for each interaction:

- If you click on the login button without passing any data to the input fields, the page returns an error :raised_eyebrow:
- If you type your email but don't type any password, when you try to login, the page will return an error :triumph:
- If you type your email and type a wrong password, when you try to login, the page will still return an error :cursing_face:

But if you manage to **somehow** insert your email along with your correct password, this is what you will get as a response from the application:

![Page saying: hello user1337](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ug411wzn9yxzzm6nf04u.png)

This process of picking up your email and password in order to verify that you are User1337 is a possible form of authentication. In more general terms, any sort of process which verifies whether or not users are who they're saying they are, may be called an user authentication method.

User authentication comes in different shapes, colours and flavours. You can find it not only in basic login forms, but also in password reset forms, HTTP request headers/cookies, 2FA apps, and the list goes on and on...

## :unlock: How Does it Get Broken?

So how does API2:2019 happen? Well, the Broken User Authentication happens when a faulty implementation of an authentication mechanism allows an attacker to impersonate someone else, temporarily or permanently.

### :monocle_face: Example 1

An application in which all passwords have 4 numeric digits and has no brute forcing prevention methods at all. In this scenario, anyone with a computer might impersonate any user of the application in a few seconds or minutes just by automating the process of attempting 4 digit number combinations. So we have a Broken User Authentication here :astonished:

### :exploding_head: Example 2

A password reset flow for users who forgot their password. The user enters their email address in order to receive a link for setting a new password:


![Password reset form, asking for a new password](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6duabmoaw73okbcy91oi.png)

When the user submit this form, the following HTTP request is sent:

> POST /password-reset/n1c3-t0k3n-h3r3 HTTP/1.1
> Content-Type: application/json
>
> {
> &nbsp;&nbsp;&nbsp;&nbsp;"password": "therealpassword123",
> &nbsp;&nbsp;&nbsp;&nbsp;"passwordConfirm": "therealpassword123",
> &nbsp;&nbsp;&nbsp;&nbsp;"userID": 1337
> }

Notice that there's an attribute called `userID` which apparently refers to the ID of the user who did request this password change. And remember, from the [last post](https://dev.to/therealbrenu/api12019-broken-object-level-authorization-17ba), that there is something called Broken Object Level Authorization, which is very very common in applications these days.

If this particular endpoint is vulnerable to API1:2019, in a way that by changing the value of `userID` an attacker end up changing the password of someone else and being able to impersonate them, we may say that this same endpoint is also vulnerable to API2:2019, because we have a broken authorization mechanism leading to a broken authentication mechanism. :sob:

## :books: External materials

As my goal with this series is to just explain what each flaw is, I would like to suggest some materials about authentication security issues, so you understand better the details of it:

https://owasp.org/www-project-top-ten/2017/A2_2017-Broken_Authentication

https://www.youtube.com/watch?v=j8Yxff6L_po

https://auth0.com/blog/what-is-broken-authentication/

## Thank you for taking your time :hugs: