Privilege escalation allows any user to add an administrator
The user-management endpoints in express-cart were not protected by the admin restriction middleware, and the insert endpoint decided admin status by checking whether the Referer header contained the setup path. Any logged-in normal user could therefore create a new account with administrator privileges.
Originally disclosed on HackerOne
- Triaged in 12 days
- Fixed in 40 days
- Disclosed after 3 months
I would like to report privilege escalation in the npm module express-cart.
It allows a normal user to add another user with administrator privileges.
Module
module name: express-cart
version: 1.1.5
npm page: https://www.npmjs.com/package/express-cart
Module Description
expressCart is a fully functional shopping cart built in Node.js (Express, MongoDB) with Stripe, PayPal and Authorize.net payments.
Module Stats
[10] weekly downloads
Vulnerability
Vulnerability Description
A deficiency in the access control allows normal users from expressCart to add new users to the application. This behavior by itself might be considered a privilege escalation. However, it was also possible to add the user as administrator.
Steps To Reproduce:
Firstly, I noticed that all the endpoints located in the user.js file are not being restricted by the common.restrict middleware, as the other admin routes do. Also, the endpoint /admin/user/insert does not check if the user is admin before adding a new user, which I guess it would be a unlikely behavior.
The following code is used to check if it is the first time creating a user:
// set the account to admin if using the setup form. Eg: First user account
let urlParts = url.parse(req.header('Referer'));
let isAdmin = false;
if(urlParts.path === '/admin/setup'){
isAdmin = true;
}
As you can see in the above snippet, if you send a request with a Referer containing the string /admin/setup the user added will be considered an admin. For example:
POST /admin/user/insert HTTP/1.1
Host: localhost:1111
Referer: http://localhost:1111/admin/setup
Content-Type: application/x-www-form-urlencoded
Cookie: connect.sid=[NORMAL_USER_COOKIE]
usersName=NEWADMIN&[email protected]&userPassword=password&frm_userPassword_confirm=password
Wrap up
- I contacted the maintainer to let them know: [N]
- I opened an issue in the related repository: [N]
Impact
This vulnerability would allow any registered user to create another user with administrator privileges and takeover the application.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the user routes lacked the admin restriction middleware and admin status was derived from the attacker-controlled Referer header instead of the session's role.
Impact
Any registered user could create another user with administrator privileges and take over the application.
What the attacker needed
A normal registered account; ability to set request headers
How it was found
- Log in as a normal, non-admin user and keep the session cookie.
- Send a request to the user insert endpoint with the Referer header pointing at the setup path.
- Supply a new username, email and password in the form body.
- The new account is created with administrator privileges.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
The application has a page for adding users, and it should only be reachable by administrators. The code decided whether a new user is an admin by looking at a header the browser sends (the Referer, which says where the request came from), and anyone can set that header to whatever they like. So a normal logged-in user could pretend the request came from the first-time setup page and create a brand-new administrator account.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.