Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 102 additions & 122 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,145 +1,125 @@
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/snoopysecurity/dvws-node)
![Node.js Version](https://img.shields.io/badge/node-v22-green)
![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?logo=docker&logoColor=white)
![Security](https://img.shields.io/badge/Security-Intentionally%20Vulnerable-red)
# Web Vulnerability Detection and Fixing

# DVWS-Node
A university cybersecurity project in which our team detects, demonstrates, fixes and re-tests 12 web application vulnerabilities in a deliberately vulnerable Node.js application, running locally in Docker.

DVWS-Node is a deliberately vulnerable web application for practising API and web-service security testing. It includes a browser UI and REST, GraphQL, SOAP, and XML-RPC interfaces. The vulnerabilities are intentional; do not expose this project to an untrusted network.
> ⚠️ **For education only.** This application contains intentional security vulnerabilities. Run it only on your own machine or in an isolated VM. Never deploy it to a public server.

It is the successor to [DVWS](https://github.com/snoopysecurity/dvws). The hands-on exercises are in the [challenge guide](CHALLENGES.md).
## Team

## Interfaces
| Name | Student ID | Focus area |
|---|---|---|
| Amr Hosni | 200064 | Injection |
| Momen Amin | 241492 | Access Control |
| Bashar Zain | 249625 | Data Exposure |
| Ahmed Ramadan | 245882 | Authentication and Client-Side |

| Interface | Path |
|---|---|
| REST | `/api/v1/*`, `/api/v2/*` |
| GraphQL | `/graphql` |
| SOAP | `/dvwsuserservice` |
| XML-RPC | `/xmlrpc` |
| Swagger | `/api-docs` |
## Project Goal

For each vulnerability in our scope, we:

1. **Detect** the vulnerability and locate the vulnerable code.
2. **Demonstrate** that it exists, with evidence (screenshots or logs).
3. **Fix** it with an appropriate security control.
4. **Re-test** with the same method to prove the fix works.

Every vulnerability in our scope leads to unauthorized access to, or exposure of, user data, so the project also looks at each one from a **data privacy** angle.

## Scope: 12 Vulnerabilities

Numbers refer to the sections in [`CHALLENGES.md`](CHALLENGES.md).

| # | Vulnerability | Owner | Status |
|---|---|---|---|
| 1 | SQL Injection | Amr Hosni | ⬜ To do |
| 2 | NoSQL Injection | Amr Hosni | ⬜ To do |
| 3 | OS Command Injection | Amr Hosni | ⬜ To do |
| 15 | IDOR (Insecure Direct Object Reference) | Momen Amin | ⬜ To do |
| 18 | Vertical Access Control (Privilege Escalation) | Momen Amin | ⬜ To do |
| 19 | Horizontal Access Control | Momen Amin | ⬜ To do |
| 26 | Information Disclosure | Bashar Zain | ⬜ To do |
| 27 | Sensitive Data Exposure (Password Hashes) | Bashar Zain | ⬜ To do |
| 51 | Missing Security Headers | Bashar Zain | ⬜ To do |
| 16 | JWT "none" Algorithm | Ahmed Ramadan | ⬜ To do |
| 17 | Weak JWT Secret | Ahmed Ramadan | ⬜ To do |
| 21 | Cross-Site Scripting (XSS) | Ahmed Ramadan | ⬜ To do |

Update the status to ✅ **Fixed** when your fix is merged.

## Tech Stack

- **Backend:** Node.js, Express
- **Frontend:** Svelte
- **Databases:** MongoDB, MySQL
- **Environment:** Docker, Docker Compose

The exercises cover injection, broken authentication and access control, unsafe file handling, browser attacks, GraphQL flaws, and several business-logic bugs.
## Getting Started

## Run it with Docker Compose
### Requirements

```sh
git clone https://github.com/snoopysecurity/dvws-node.git
cd dvws-node
- [Docker Desktop](https://www.docker.com/products/docker-desktop) (running, with "Engine running" shown)
- [Git](https://git-scm.com/downloads)

### Run the application

```bash
git clone https://github.com/basharzin/Data-Privacy.git
cd Data-Privacy
docker compose up --build
```

This starts the application, MongoDB, and MySQL. If startup fails because a database is still coming up, increase `WAIT_HOSTS_TIMEOUT`.
Wait for `All services listening at http://127.0.0.1`, then open:

The app is available on port 80 by default. The optional HTTPS setup is needed for the cross-origin browser exercises:
| URL | What it is |
|---|---|
| http://localhost | The web application (login: `test` / `test`) |
| http://localhost/api-docs | API documentation (Swagger) |

```sh
docker compose -f docker-compose.yml -f docker-compose.tls.yml up --build
```
Stop the app with `Ctrl + C`, or `docker compose down`.
Use `--build` again after any code change so the fix is included.

## Run it manually
## Team Workflow

You need Node.js 22, MongoDB on port 27017, and MySQL on port 3306. Docker can start the databases:
1. Create a branch for your vulnerability:
```bash
git checkout -b fix/<vulnerability-name>
```
2. Confirm the vulnerability and take a **"before"** screenshot.
3. Find the vulnerable code in `src/`.
4. Apply the fix and rebuild with `docker compose up --build`.
5. Repeat the same test and take an **"after"** screenshot.
6. Fill in your section in `docs/fixes/` using the template below.
7. Commit, push and open a Pull Request:
```bash
git add .
git commit -m "Fix <vulnerability> (#<number>)"
git push origin fix/<vulnerability-name>
```

```sh
docker run -d -p 27017:27017 --name dvws-mongo mongo:4.0.4
docker run -d -p 3306:3306 --name dvws-mysql \
-e MYSQL_ROOT_PASSWORD=mysecretpassword \
-e MYSQL_DATABASE=dvws_sqldb mysql:8
```
## Fix Report Template

Then install, seed, and start the app:
Copy this for each vulnerability:

```sh
npm install
node scripts/seed-database.js
npm start
```
```markdown
## #<number> <Vulnerability name>

- **Owner:**
- **Location:** endpoint and file (e.g. `GET /api/v1/info`, `src/controllers/notes.js`)
- **Severity:** Low / Medium / High / Critical
- **Data privacy impact:** what user data is exposed and to whom

Set the database values in `.env` if your services use different settings. The server listens on port 80; set `EXPRESS_JS_PORT` to an unprivileged port if needed.
### Evidence (before)
<screenshot>

For Swagger links, you can add this entry to `/etc/hosts`:
### Root cause
<what is wrong in the code>

```text
127.0.0.1 dvws.local
### Fix
<code before and after>

### Verification (after)
<screenshot showing the same test now fails>
```

## Security issues covered

The application includes guided exercises across REST, GraphQL, SOAP, XML-RPC, and browser workflows. See the [challenge guide](CHALLENGES.md) for endpoint details, example requests, and mitigation notes.

* SQL Injection
* NoSQL Injection
* OS Command Injection
* XML External Entity Injection (XXE)
* XML Bomb (Denial of Service)
* Server-Side Request Forgery (SSRF)
* Insecure Deserialization (RCE)
* XPath Injection
* LDAP Injection
* Path Traversal
* SOAP Injection
* XML Injection (Profile Export)
* XML Injection (Profile Import / Mass Assignment)
* Mass Assignment (User Registration)
* IDOR (Insecure Direct Object Reference)
* Broken Authentication (JWT `none` Algorithm)
* JWT Secret Key Brute Force
* JWT JKU Key Source Trust
* JWT KID Path Traversal
* JWT Disclosure Through PostMessage
* Vertical Access Control (Privilege Escalation)
* Horizontal Access Control
* Open Redirect
* Cross-Site Scripting (XSS)
* Cross-Site Request Forgery (CSRF)
* CORS Misconfiguration
* CRLF Injection / Log Pollution
* User Enumeration
* Information Disclosure
* Sensitive Data Exposure (Password Hashes)
* Prototype Pollution
* API Endpoint Brute Forcing (Missing Rate Limit)
* HTTP Method Confusion (State Change Through GET)
* Ignored `Accept` Headers and Content-Type Confusion
* Credentials in URLs and Base64 Mistaken for Encryption
* HTTP Method Override Bypass
* Shared Caching of Authenticated Reports
* Inconsistent Request Format Handling
* Resource Store: Get an Item for Free
* Resource Store: Increase Your Balance by 1,000 Credits
* Rate Limit Bypass via `X-Forwarded-For`
* Hidden API Functionality Exposure
* GraphQL Introspection
* GraphQL Access Control Issues
* GraphQL Arbitrary File Write
* GraphQL Batching Brute Force
* GraphQL Sensitive Data Exposure
* GraphQL Alias Amplification
* Missing Security Headers
* Unrestricted File Upload
* Role-Based Profile Data Exposure
* Account Recovery IDOR Chain
* Session Revocation After Password Change
* Cross-Site Request Forgery Through the Login Cookie
* JSONP Cross-Origin Profile Sharing
* Cross-Site WebSocket Hijacking
* Server-Side Template Injection
* Unsafe YAML Supplier Import
* Cross-Customer Monthly Statement Path Traversal
* Notification Preference Mass Assignment
* Undocumented TRACE Diagnostics
* Legacy Login Skips Password Verification
* Excessive Activity Report Page Size
* Timing Attacks

## Tests

The vulnerability tests are intentionally expected to pass when the vulnerable behaviour is present. See [`test/README.md`](test/README.md) for the commands and prerequisites.

## Further reading

- [Challenge guide](CHALLENGES.md)
- [Frontend README](frontend/README.md)

Questions and bug reports are welcome as [GitHub issues](https://github.com/snoopysecurity/dvws-node/issues).
## Credits and License

This project is built on [DVWS-node](https://github.com/snoopysecurity/dvws-node) by snoopysecurity, an intentionally vulnerable application for security training. The original application and our modifications are distributed under the [GNU GPL v3.0](LICENSE).
104 changes: 104 additions & 0 deletions docs/fixes/27-sensitive-data-exposure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# #27 Sensitive Data Exposure (Password Hashes)

**Owner:** Bashar Zain
**Severity:** High
**Affected endpoints:** `GET /api/v2/users`, `POST /api/v2/users/login`

## Description

The API sends users' bcrypt password hashes back in its responses. We logged in as `test`, a normal user with no admin rights, and sent a request to `GET /api/v2/users` with that user's token in Burp Repeater. The server returned every user in the database with their `password` field, including the admin account.

![GET /api/v2/users returning the admin's password hash to a normal user](images/27-before-users.png)

The login endpoint has the same problem. After a successful login, the response contains the logged-in user's hash:

```json
"result": {
"username": "test",
"password": "$2b$10$KF48rmhNFOt1fAZmOMxdj.eLT56KW4ruNRXraPZVgUrVnEsTtqWPS",
"admin": false,
"email": "test@dvws.local"
}
```

A hash is not the password itself, but anyone who has it can try to crack it offline, and weak passwords can be recovered this way. Hashes should never leave the server.

## Root cause

![getAll before the fix](images/27-code-before-getall.png)

In `src/controllers/users.js`, the `getAll` function loads users with `User.find({})`. Mongoose returns every field of the document by default, and nothing excludes `password`, so the hash ends up in the JSON response. The `login` function does the same thing with `result.result = user`, which sends the whole user object back to the client.

There is also a second issue on the same endpoint. In `src/routes/users.js`, the route is protected only by `validateToken`:

```js
router.route('/v2/users')
.get(validateToken, controller.getAll);
```

`validateToken` checks that the caller is logged in, but it does not check whether the caller is an admin. That is why a normal user can list all accounts. This overlaps with #18 (Vertical Access Control).

## Fix

**1. Exclude the password in `getAll`** (`src/controllers/users.js`):

```js
const users = await User.find({}).select('-password');
```

**2. Don't send the full user object after login** (`src/controllers/users.js`):

```js
result.result = {
username: user.username,
email: user.email,
admin: user.admin,
bio: user.bio
};
```

We changed this in both places it appears in `login` (the admin branch and the normal user branch).

![login response after the fix](images/27-code-after-login.png)

The login function still reads the hash internally to run `bcrypt.compare`, which is fine. It just no longer sends it back.

**3. Only allow admins to list users** (`src/routes/users.js`):

```js
const requireAdmin = (req, res, next) => {
const perms = (req.decoded && req.decoded.permissions) || [];
if (!perms.includes('user:admin')) {
return res.status(403).send({ error: 'Forbidden' });
}
next();
};

router.route('/v2/users')
.get(validateToken, requireAdmin, controller.getAll);
```

Admin tokens are issued with the `user:admin` permission at login, and normal user tokens are not, so only admins get past this check. We did not use the `guard` from `express-jwt-permissions` that is already imported in this file, because it reads permissions from `req.identity` while `validateToken` stores the token in `req.decoded`, so it would block admins too.

## Verification

After rebuilding with `docker compose up --build`, we will repeat the same Burp request:

- With the `test` user's token, `GET /api/v2/users` should return `403 Forbidden`.
- With an admin token, the user list should come back without any `password` field.
- Logging in should still work, and the login response should not contain `password`.

We tested all three after rebuilding:

With the admin token, `GET /api/v2/users` returns `200 OK` and the full user list, with no `password` field on any user:

```json
{"status":200,"result":[
{"username":"admin","admin":true,"email":"admin@dvws.local", "...": "no password field"},
{"username":"test","admin":false,"email":"test@dvws.local", "...": "no password field"}
]}
```

![normal user token: blocked with 403](images/27-after-test-403.png)

With the `test` user's token, the same request now returns `403 Forbidden`, confirming the admin check works.
Binary file added docs/fixes/images/27-after-test-403.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/fixes/images/27-before-users.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/fixes/images/27-code-after-login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/fixes/images/27-code-before-getall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 13 additions & 3 deletions src/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ module.exports = {

result.token = token;
result.status = status;
result.result = user;
result.result = {
username: user.username,
email: user.email,
admin: user.admin,
bio: user.bio
};
} else {

const payload = { user: user.username,"permissions": [
Expand All @@ -192,7 +197,12 @@ module.exports = {

result.token = token;
result.status = status;
result.result = user;
result.result = {
username: user.username,
email: user.email,
admin: user.admin,
bio: user.bio
};
}
// Create a token

Expand Down Expand Up @@ -267,7 +277,7 @@ module.exports = {
let status = 200;

try {
const users = await User.find({});
const users = await User.find({}).select('-password');
result.status = status;
result.result = users;
} catch (err) {
Expand Down
Loading