Skip to content

Commit 78bbcb4

Browse files
committed
test
1 parent 62240e5 commit 78bbcb4

1 file changed

Lines changed: 46 additions & 26 deletions

File tree

README.md

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
# Goof - Snyk's vulnerable demo app
2+
23
[![Known Vulnerabilities](https://snyk.io/test/github/snyk/goof/badge.svg?style=flat-square)](https://snyk.io/test/github/snyk/goof)
34

45
A vulnerable Node.js demo application, based on the [Dreamers Lab tutorial](http://dreamerslab.com/blog/en/write-a-todo-list-with-express-and-mongodb/)
56

67
## Features
78

8-
This vulnerable app includes the following capabilities to experiment with:
9-
* [Exploitable packages](#exploiting-the-vulnerabilities) with known vulnerabilities
10-
* [Docker Image Scanning](#docker-image-scanning) for base images with known vulnerabilities in system libraries
11-
* [Runtime alerts](#runtime-alerts) for detecting an invocation of vulnerable functions in open source dependencies
9+
This vulnerable apassa includes the following capabilities to experiment with:
10+
11+
- [Exploitable packages](#exploiting-the-vulnerabilities) with known vulnerabilities
12+
- [Docker Image Scanning](#docker-image-scanning) for base images with known vulnerabilities in system libraries
13+
- [Runtime alerts](#runtime-alerts) for detecting an invocation of vulnerable functions in open source dependencies
1214

1315
## Running
16+
1417
```bash
1518
mongod &
1619

1720
git clone https://github.com/snyk-labs/nodejs-goof
1821
npm install
1922
npm start
2023
```
24+
2125
This will run Goof locally, using a local mongo on the default port and listening on port 3001 (http://localhost:3001)
2226

23-
Note: You *have* to use an old version of MongoDB version due to some of these old libraries' database server APIs. MongoDB 3 is known to work ok.
27+
Note: You _have_ to use an old version of MongoDB version due to some of these old libraries' database server APIs. MongoDB 3 is known to work ok.
2428

2529
You can also run the MongoDB server individually via Docker, such as:
2630

@@ -29,21 +33,26 @@ docker run --rm -p 27017:27017 mongo:3
2933
```
3034

3135
## Running with docker-compose
36+
3237
```bash
3338
docker-compose up --build
3439
docker-compose down
3540
```
3641

3742
### Heroku usage
38-
Goof requires attaching a MongoLab service to be deployed as a Heroku app.
39-
That sets up the MONGOLAB_URI env var so everything after should just work.
43+
44+
Goof requires attaching a MongoLab service to be deployed as a Heroku app.
45+
That sets up the MONGOLAB_URI env var so everything after should just work.
4046

4147
### CloudFoundry usage
42-
Goof requires attaching a MongoLab service and naming it "goof-mongo" to be deployed on CloudFoundry.
43-
The code explicitly looks for credentials to that service.
48+
49+
Goof requires attaching a MongoLab service and naming it "goof-mongo" to be deployed on CloudFoundry.
50+
The code explicitly looks for credentials to that service.
4451

4552
### Cleanup
53+
4654
To bulk delete the current list of TODO items from the DB run:
55+
4756
```bash
4857
npm run cleanup
4958
```
@@ -58,21 +67,22 @@ The `exploits/` directory includes a series of steps to demonstrate each one.
5867
### Vulnerabilities in open source dependencies
5968

6069
Here are the exploitable vulnerable packages:
70+
6171
- [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`.
6272
- [st - Directory Traversal](https://snyk.io/vuln/npm:st:20140206)
6373
- [ms - ReDoS](https://snyk.io/vuln/npm:ms:20151024)
6474
- [marked - XSS](https://snyk.io/vuln/npm:marked:20150520)
6575

6676
### Vulnerabilities in code
6777

68-
* Open Redirect
69-
* NoSQL Injection
70-
* Code Injection
71-
* Command execution
72-
* Cross-site Scripting (XSS)
73-
* Information exposure via Hardcoded values in code
74-
* Security misconfiguration exposes server information
75-
* Insecure protocol (HTTP) communication
78+
- Open Redirect
79+
- NoSQL Injection
80+
- Code Injection
81+
- Command execution
82+
- Cross-site Scripting (XSS)
83+
- Information exposure via Hardcoded values in code
84+
- Security misconfiguration exposes server information
85+
- Insecure protocol (HTTP) communication
7686

7787
#### Code injection
7888

@@ -110,19 +120,21 @@ curl -X 'POST' -H 'Content-Type: application/json' --data-binary "{\"email\": \"
110120
A POST request to `/login` will allow for authentication and signing-in to the system as an administrator user.
111121
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.
112122

113-
114123
We can send a request with an incorrect password to see that we get a failed attempt
124+
115125
```sh
116126
echo '{"username":"admin@snyk.io", "password":"WrongPassword"}' | http --json $GOOF_HOST/login -v
117127
```
118128

119129
And another request, as denoted with the following JSON request to sign-in as the admin user works as expected:
130+
120131
```sh
121132
echo '{"username":"admin@snyk.io", "password":"SuperSecretPassword"}' | http --json $GOOF_HOST/login -v
122133
```
123134

124135
However, what if the password wasn't a string? what if it was an object? Why would an object be harmful or even considered an issue?
125136
Consider the following request:
137+
126138
```sh
127139
echo '{"username": "admin@snyk.io", "password": {"$gt": ""}}' | http --json $GOOF_HOST/login -v
128140
```
@@ -151,20 +163,23 @@ To exploit the open redirect, simply provide a URL such as `redirectPage=https:/
151163
The application initializes a cookie-based session on `app.js:40` as follows:
152164

153165
```js
154-
app.use(session({
155-
secret: 'keyboard cat',
156-
name: 'connect.sid',
157-
cookie: { secure: true }
158-
}))
166+
app.use(
167+
session({
168+
secret: "keyboard cat",
169+
name: "connect.sid",
170+
cookie: { secure: true },
171+
})
172+
);
159173
```
160174

161175
As you can see, the session `secret` used to sign the session is a hardcoded sensitive information inside the code.
162176

163177
First attempt to fix it, can be to move it out to a config file such as:
178+
164179
```js
165180
module.exports = {
166-
cookieSecret: `keyboard cat`
167-
}
181+
cookieSecret: `keyboard cat`,
182+
};
168183
```
169184

170185
And then require the configuration file and use it to initialize the session.
@@ -179,11 +194,13 @@ Snyk Code will also find hardcoded secrets in source code that isn't part of the
179194
The `Dockerfile` makes use of a base image (`node:6-stretch`) that is known to have system libraries with vulnerabilities.
180195

181196
To scan the image for vulnerabilities, run:
197+
182198
```bash
183199
snyk test --docker node:6-stretch --file=Dockerfile
184200
```
185201

186202
To monitor this image and receive alerts with Snyk:
203+
187204
```bash
188205
snyk monitor --docker node:6-stretch
189206
```
@@ -197,14 +214,17 @@ The agent is installed and initialized in [app.js](./app.js#L5).
197214
For the agent to report back to your snyk account on the vulnerabilities it detected it needs to know which project on Snyk to associate with the monitoring. Due to that, we need to provide it with the project id through an environment variable `SNYK_PROJECT_ID`
198215

199216
To run the Node.js app with runtime monitoring:
217+
200218
```bash
201219
SNYK_PROJECT_ID=<PROJECT_ID> npm start
202220
```
203221

204-
** The app will continue to work normally even if it's not provided a project id
222+
\*\* The app will continue to work normally even if it's not provided a project id
205223

206224
## Fixing the issues
225+
207226
To find these flaws in this application (and in your own apps), run:
227+
208228
```
209229
npm install -g snyk
210230
snyk wizard

0 commit comments

Comments
 (0)