You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+117-3Lines changed: 117 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ This vulnerable app includes the following capabilities to experiment with:
14
14
```bash
15
15
mongod &
16
16
17
-
git clone https://github.com/Snyk/snyk-demo-todo
17
+
git clone https://github.com/snyk/goof.git
18
18
npm install
19
19
npm start
20
20
```
@@ -42,15 +42,129 @@ npm run cleanup
42
42
43
43
## Exploiting the vulnerabilities
44
44
45
-
This app uses npm dependencies holding known vulnerabilities.
45
+
This app uses npm dependencies holding known vulnerabilities,
46
+
as well as insecure code that introduces code-level vulnerabilities.
47
+
48
+
The `exploits/` directory includes a series of steps to demonstrate each one.
49
+
50
+
### Vulnerabilities in open source dependencies
46
51
47
52
Here are the exploitable vulnerable packages:
48
53
-[Mongoose - Buffer Memory Exposure](https://snyk.io/vuln/npm:mongoose:20160116) - requires a version <= Node.js 8. For the exploit demo purposes, one can update the Dockerfile `node` base image to use `FROM node:6-stretch`.
The `exploits/` directory includes a series of steps to demonstrate each one.
58
+
### Vulnerabilities in code
59
+
60
+
* Open Redirect
61
+
* NoSQL Injection
62
+
* Code Injection
63
+
* Command execution
64
+
* Cross-site Scripting (XSS)
65
+
* Information exposure via Hardcoded values in code
66
+
* Security misconfiguration exposes server information
67
+
* Insecure protocol (HTTP) communication
68
+
69
+
#### Code injection
70
+
71
+
The page at `/account_details` is rendered as an Handlebars view.
72
+
73
+
The same view is used for both the GET request which shows the account details, as well as the form itself for a POST request which updates the account details. A so-called Server-side Rendering.
74
+
75
+
The form is completely functional. The way it works is, it receives the profile information from the `req.body` and passes it, as-is to the template. This however means, that the attacker is able to control a variable that flows directly from the request into the view template library.
76
+
77
+
You'd think that what's the worst that can happen because we use a validation to confirm the expected input, however the validation doesn't take into account a new field that can be added to the object, such as `layout`, which when passed to a template language, could lead to Local File Inclusion (Path Traversal) vulnerabilities. Here is a proof-of-concept showing it:
Actually, there's even another vulnerability in this code.
88
+
The `validator` library that we use has several known regular expression denial of service vulnerabilities. One of them, is associated with the email regex, which if validated with the `{allow_display_name: true}` option then we can trigger a denial of service for this route:
A POST request to `/login` will allow for authentication and signing-in to the system as an administrator user.
103
+
It works by exposing `loginHandler` as a controller in `routes/index.js` and uses a MongoDB database and the `User.find()` query to look up the user's details (email as a username and password). One issue is that it indeed stores passwords in plaintext and not hashing them. However, there are other issues in play here.
104
+
105
+
106
+
We can send a request with an incorrect password to see that we get a failed attempt
We know the username, and we pass on what seems to be an object of some sort.
123
+
That object structure is passed as-is to the `password` property and has a specific meaning to MongoDB - it uses the `$gt` operation which stands for `greater than`. So, we in essence tell MongoDB to match that username with any record that has a password that is greater than `empty string` which is bound to hit a record. This introduces the NoSQL Injection vector.
124
+
125
+
#### Open redirect
126
+
127
+
The `/admin` view introduces a `redirectPage` query path, as follows in the admin view:
One fault here is that the `redirectPage` is rendered as raw HTML and not properly escaped, because it uses `<%- >` instead of `<%= >`. That itself, introduces a Cross-site Scripting (XSS) vulnerability via:
To exploit the open redirect, simply provide a URL such as `redirectPage=https://google.com` which exploits the fact that the code doesn't enforce local URLs in `index.js:72`.
140
+
141
+
#### Hardcoded values - session information
142
+
143
+
The application initializes a cookie-based session on `app.js:40` as follows:
144
+
145
+
```js
146
+
app.use(session({
147
+
secret:'keyboard cat',
148
+
name:'connect.sid',
149
+
cookie: { secure:true }
150
+
}))
151
+
```
152
+
153
+
As you can see, the session `secret` used to sign the session is a hardcoded sensitive information inside the code.
154
+
155
+
First attempt to fix it, can be to move it out to a config file such as:
156
+
```js
157
+
module.exports= {
158
+
cookieSecret:`keyboard cat`
159
+
}
160
+
```
161
+
162
+
And then require the configuration file and use it to initialize the session.
163
+
However, that still maintains the secret information inside another file, and Snyk Code will warn you about it.
164
+
165
+
Another case we can discuss here in session management, is that the cookie setting is initialized with `secure: true` which means it will only be transmitted over HTTPS connections. However, there's no `httpOnly` flag set to true, which means that the default false value of it makes the cookie accessible via JavaScript. Snyk Code highlights this potential security misconfiguration so we can fix it. We can note that Snyk Code shows this as a quality information, and not as a security error.
166
+
167
+
Snyk Code will also find hardcoded secrets in source code that isn't part of the application logic, such as `tests/` or `examples/` folders. We have a case of that in this application with the `tests/authentication.component.spec.js` file. In the finding, Snyk Code will tag it as `InTest`, `Tests`, or `Mock`, which help us easily triage it and indeed ignore this finding as it isn't actually a case of information exposure.
0 commit comments