To evaluate the source code of the application and find the cause of the vulnerability, we need to find the appropriate file where vulnerability exists.
To interactively attach the shell inside docker, use the following command:
You may notice that your shell has changed and you are inside the container runtime at /app directory:
After searching the /app directory, we encountered a file named app.py whose truncated contents are as follows:
If you remember, our vulnerability exists in /profile endpoint, so let’s focus onto the function used for the /profile endpoint.
Let’s now break this function for a better understanding.
The first statement in the function is global current_user, which uses a global variable reference to the currently logged in user.
The initial if condition redirects the user to login page (/login) if the user is currently logged in, which is a valid security measure for checking Authentication.
The second if condition checks whether the requested user in /profile/<username> endpoint exists inside our list of registered users. If the user is not present, then the developer is throwing message that User Profile not found..
But, wait! If the user requested is present, the developer is taking the profile details directly and showing it to the user.
Bug
The developer forgot to add a check whether the current_user i.e. logged in user and the requested username is same.
Let’s try to mitigate the above said issue:
Now, let’s try to access the alice profile, location at /profile/alice.
Voila! We have successfully mitigated the IDOR vulnerability.
Question
A vulnerability still exists in the above code. Are you able to identify it. Hint: Information disclosure. Join our discord channel to tell us your bug hunting story.