Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master into feature/187 #220

Open
wants to merge 25 commits into
base: feature/187
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bb07586
fix: startup logs stringified objects incorrectly
lirantal Jul 9, 2020
7c293e7
fix: example of xss in bad context using a dedicated profile field
lirantal Jul 9, 2020
38de373
Fix NoSQL injection solution
karlhorky Jul 9, 2020
58cbbe2
Merge pull request #204 from karlhorky/patch-1
lirantal Jul 9, 2020
a51149e
Merge pull request #202 from lirantal/fix/startup-logs
lirantal Aug 3, 2020
a512124
Merge pull request #203 from lirantal/fix/xss-context
lirantal Aug 3, 2020
5b6a307
test: update broken build in commit 7c293e721bd1e95be6f82475d295b9b10…
lirantal Aug 5, 2020
21d5740
Fix "Cannot read property 'seq' of null" error
rcowsill Sep 24, 2020
d1d5657
Fix database URI under docker-compose
rcowsill Sep 25, 2020
ec40213
Bypass livereload script in cypress tests
rcowsill Sep 26, 2020
fe5b12b
Faster deploy to Heroku
rcowsill Oct 10, 2020
12fa8fa
Replace mongolab addon with MONGODB_URI env var
rcowsill Oct 10, 2020
1af3c64
Remove MONGOLAB_URI and mlab connection string
rcowsill Oct 10, 2020
aec7782
Adjustments to livereload to stop (timeout) in prod
binarymist Oct 22, 2020
ddca594
Update instructions
rcowsill Nov 1, 2020
1ede1df
Add detail to MONGODB_URI instructions
rcowsill Nov 2, 2020
3d77c3d
Add note about MongoDB Atlas M0
rcowsill Nov 2, 2020
c44bbd6
Merge pull request #215 from rcowsill/fix/heroku-db
ckarande Nov 10, 2020
57817e3
Changed livereload script and put it in test env only
binarymist Nov 10, 2020
5ab0088
add atlas db url
ckarande Nov 10, 2020
dcd2a1d
Merge pull request #216 from binarymist/livereload-refactor
ckarande Nov 10, 2020
3137d3c
Add cross-env to package-lock.json
karlhorky Nov 13, 2020
b8d031d
Add cross-env for Windows scripts compatibility
karlhorky Nov 13, 2020
a8327fc
Merge pull request #217 from karlhorky/patch-2
lirantal Nov 13, 2020
7c036aa
Merge branch 'master' into merge/master-into-187
rcowsill Nov 20, 2020
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
161 changes: 98 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,93 +9,128 @@ OWASP Top 10 for Node.js web applications:
[Tutorial Guide](http://nodegoat.herokuapp.com/tutorial) explaining how each of the OWASP Top 10 vulnerabilities can manifest in Node.js web apps and how to prevent it.

### Do it!
[A Vulnerable Node.js App for Ninjas](http://nodegoat.herokuapp.com/) to exploit, toast, and fix. You may like to [set up your own copy](#how-to-setup-your-copy-of-nodegoat) of the app to fix and test vulnerabilities. Hint: Look for comments in the source code.
[A Vulnerable Node.js App for Ninjas](http://nodegoat.herokuapp.com/) to exploit, toast, and fix. You may like to [set up your own copy](#how-to-set-up-your-copy-of-nodegoat) of the app to fix and test vulnerabilities. Hint: Look for comments in the source code.
##### Default user accounts
The database comes pre-populated with these user accounts created as part of the seed data -
* Admin Account - u:admin p:Admin_123
* User Accounts (u:user1 p:User1_123), (u:user2 p:User2_123)
* New users can also be added using the sign-up page.

## How to Setup Your Copy of NodeGoat
## How to Set Up Your Copy of NodeGoat

### OPTION 1 - Run NodeGoat on your machine

1) Install [Node.js](http://nodejs.org/) - NodeGoat requires Node v8 or above

2) Clone the github repository:
```
git clone https://github.com/OWASP/NodeGoat.git
```

3) Go to the directory:
```
cd NodeGoat
```

4) Install node packages:
```
npm install
```

5) Set up MongoDB. You can either install MongoDB locally or create a remote instance:

* Using local MongoDB:
1) Install [MongoDB Community Server](https://docs.mongodb.com/manual/administration/install-community/)
2) Start [mongod](http://docs.mongodb.org/manual/reference/program/mongod/#bin.mongod)

* Using remote MongoDB instance:
1) [Deploy a MongoDB Atlas free tier cluster](https://docs.atlas.mongodb.com/tutorial/deploy-free-tier-cluster/) (M0 Sandbox)
2) [Enable network access](https://docs.atlas.mongodb.com/security/add-ip-address-to-list/) to the cluster from your current IP address
3) [Add a database user](https://docs.atlas.mongodb.com/tutorial/create-mongodb-user-for-cluster/) to the cluster
4) Set the `MONGODB_URI` environment variable to the connection string of your cluster, which can be viewed in the cluster's
[connect dialog](https://docs.atlas.mongodb.com/tutorial/connect-to-your-cluster/#connect-to-your-atlas-cluster). Select "Connect your application",
set the driver to "Node.js" and the version to "2.2.12 or later". This will give a connection string in the form:
```
mongodb://<username>:<password>@<cluster>/<dbname>?ssl=true&replicaSet=<rsname>&authSource=admin&retryWrites=true&w=majority
```
The `<username>` and `<password>` fields need filling in with the details of the database user added earlier. The `<dbname>` field sets the name of the
database nodegoat will use in the cluster (eg "nodegoat"). The other fields will already be filled in with the correct details for your cluster.

6) Populate MongoDB with the seed data required for the app:
```
npm run db:seed
```
By default this will use the "development" configuration, but the desired config can be passed as an argument if required.

7) Start the server. You can run the server using node or nodemon:
* Start the server with node. This starts the NodeGoat application at [http://localhost:4000/](http://localhost:4000/):
```
npm start
```
* Start the server with nodemon, which will automatically restart the application when you make any changes. This starts the NodeGoat application at [http://localhost:5000/](http://localhost:5000/):
```
npm run dev
```

### OPTION 1 - One click install on Heroku
The the quickest way to get running with NodeGoat is to click the button below to deploy it on Heroku.
#### Customizing the Default Application Configuration
By default the application will be hosted on port 4000 and will connect to a MongoDB instance at localhost:27017. To change this set the environment variables `PORT` and `MONGODB_URI`.

Even though it is not essential, but recommended that you fork this repository and deploy the forked repo.
This would allow you to fix vulnerabilities in your own forked version, and deploy and test it on heroku.
Other settings can be changed by updating the [config file](https://github.com/OWASP/NodeGoat/blob/master/config/env/all.js).

[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)

This Heroku instance uses Free ($0/month) node server and MongoLab add-on.
### OPTION 2 - Run NodeGoat on Docker

### OPTION 2 - Run NodeGoat on your machine
The repo includes the Dockerfile and docker-compose.yml necessary to set up the app and db instance, then connect them together.

If you do not wish to run NodeGoat on Heroku, please follow these steps to setup and run it locally -
* Install [Node.js](http://nodejs.org/) - NodeGoat requires Node v8 or above
1) Install [docker](https://docs.docker.com/installation/) and [docker compose](https://docs.docker.com/compose/install/)

* Clone the github repository
```
git clone https://github.com/OWASP/NodeGoat.git
```
2) Clone the github repository:
```
git clone https://github.com/OWASP/NodeGoat.git
```

*go to the directory
```
cd NodeGoat
```
3) Go to the directory:
```
cd NodeGoat
```

* Install node modules
```
npm install
```
4) Build the images:
```
docker-compose build
```

* Create Mongo DB:
You can create a remote MongoDB instance or use local mongod installation
* A. Using Remote MongoDB
* Create a sandbox mongoDB instance (free) at [mLab](https://mlab.com/plans/pricing/#plan-sandbox)
* Create a new database.
* Create a user.
* Update the `db` property in file `config/env/development.js` to reflect your DB setup. (in format: `mongodb://<username>:<password>@<databasename>`)
* OR B.Using local MongoDB
* If using local Mongo DB instance, start [mongod](http://docs.mongodb.org/manual/reference/program/mongod/#bin.mongod).
* Update the `db` property in file `config/env/development.js` to reflect your DB setup. (in format: `mongodb://localhost:27017/<databasename>`)
5) Run the app, this starts the NodeGoat application at http://localhost:4000/:
```
docker-compose up
```

* Populate MongoDB with seed data required for the app
* Run the npm-script below to populate the DB with seed data required for the application. Pass the desired environment as argument. If not passed, "development" is the default:
```
npm run db:seed
```
* Start server, this starts the NodeGoat application at url [http://localhost:4000/](http://localhost:4000/)
```
npm start
```

* Start server with nodemon, this starts the NodeGoat application at url [http://localhost:5000/](http://localhost:5000/)
```
npm run dev
```
### OPTION 3 - Deploy to Heroku

### OPTION 3 - Run NodeGoat on Docker
This option uses a free ($0/month) Heroku node server.

**You need to install [docker](https://docs.docker.com/installation/) and [docker compose](https://docs.docker.com/compose/install/) to be able to use this option**
Though not essential, it is recommended that you fork this repository and deploy the forked repo.
This will allow you to fix vulnerabilities in your own forked version, then deploy and test it on Heroku.

The repo includes the Dockerfile and docker-compose.yml necessary to setup the app and the db instance then connect them together.
1) Set up a publicly accessible MongoDB instance:
1) [Deploy a MongoDB Atlas free tier cluster](https://docs.atlas.mongodb.com/tutorial/deploy-free-tier-cluster/) (M0 Sandbox)
2) [Enable network access](https://docs.atlas.mongodb.com/security/ip-access-list/#add-ip-access-list-entries) to the cluster from anywhere (CIDR range 0.0.0.0/0)
3) [Add a database user](https://docs.atlas.mongodb.com/tutorial/create-mongodb-user-for-cluster/) to the cluster

* Change the db config in `config/env/development.js` to point to the respective Docker container.
```
db: "mongodb://mongo:27017/nodegoat",
```
* Build the images:
```
docker-compose build
```
* Run the app:
```
docker-compose up
```
2) Deploy NodeGoat to Heroku by clicking the button below:

[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)

In the Create New App dialog, set the `MONGODB_URI` config var to the connection string of your MongoDB Atlas cluster.
This can be viewed in the cluster's [connect dialog](https://docs.atlas.mongodb.com/tutorial/connect-to-your-cluster/#connect-to-your-atlas-cluster).
Select "Connect your application", set the driver to "Node.js" and the version to "2.2.12 or later".
This will give a connection string in the form:
```
mongodb://<username>:<password>@<cluster>/<dbname>?ssl=true&replicaSet=<rsname>&authSource=admin&retryWrites=true&w=majority
```
The `<username>` and `<password>` fields need filling in with the details of the database user added earlier. The `<dbname>` field sets the name of the
database nodegoat will use in the cluster (eg "nodegoat"). The other fields will already be filled in with the correct details for your cluster.

#### Customizing the Default Application Configuration
The default application settings (database url, http port, etc.) can be changed by updating the [config file] (https://github.com/OWASP/NodeGoat/blob/master/config/env/all.js).

## Report bugs, Feedback, Comments
* Open a new [issue](https://github.com/OWASP/NodeGoat/issues) or contact team by joining chat at [Slack](https://owasp.slack.com/messages/project-nodegoat/) or [![Join the chat at https://gitter.im/OWASP/NodeGoat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/OWASP/NodeGoat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Expand Down
18 changes: 12 additions & 6 deletions apps/server-render/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@
"postdeploy": "node artifacts/db-reset.js"
},
"env": {
"MONGODB_URI": {
"description": "Connection string for MongoDB database to use. Must be publicly accessible.",
"value": ""
},
"NODE_ENV": {
"value": "PRODUCTION"
"description": "NODE_ENV for build and runtime. Must be in lowercase for Heroku build process.",
"value": "production"
},
"NPM_CONFIG_ONLY": {
"description": "Controls devDependency install: \"production\" = skip, \"all\" = install",
"value": "production"
}
},
"addons": [
"mongolab:sandbox"
]
}
}
}
2 changes: 1 addition & 1 deletion apps/server-render/app/data/allocations-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const AllocationsDAO = function(db) {
const parsedThreshold = parseInt(threshold, 10);

if (parsedThreshold >= 0 && parsedThreshold <= 99) {
return {$where: `this.userId == ${parsedUserId} && this.stocks > ${threshold}`};
return {$where: `this.userId == ${parsedUserId} && this.stocks > ${parsedThreshold}`};
}
throw `The user supplied threshold: ${parsedThreshold} was not valid.`;
*/
Expand Down
6 changes: 5 additions & 1 deletion apps/server-render/app/routes/allocations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const AllocationsDAO = require("../data/allocations-dao").AllocationsDAO;
const {
environmentalScripts
} = require("../../config/config");

function AllocationsHandler(db) {
"use strict";
Expand All @@ -21,7 +24,8 @@ function AllocationsHandler(db) {
if (err) return next(err);
return res.render("allocations", {
userId,
allocations
allocations,
environmentalScripts
});
});
};
Expand Down
9 changes: 7 additions & 2 deletions apps/server-render/app/routes/benefits.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const {
BenefitsDAO
} = require("../data/benefits-dao");
const {
environmentalScripts
} = require("../../config/config");

function BenefitsHandler(db) {
"use strict";
Expand All @@ -17,7 +20,8 @@ function BenefitsHandler(db) {
users,
user: {
isAdmin: true
}
},
environmentalScripts
});
});
};
Expand All @@ -40,7 +44,8 @@ function BenefitsHandler(db) {
user: {
isAdmin: true
},
updateSuccess: true
updateSuccess: true,
environmentalScripts
};

return res.render("benefits", data);
Expand Down
19 changes: 15 additions & 4 deletions apps/server-render/app/routes/contributions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const ContributionsDAO = require("../data/contributions-dao").ContributionsDAO;
const {
environmentalScripts
} = require("../../config/config");

/* The ContributionsHandler must be constructed with a connected db */
function ContributionsHandler(db) {
Expand All @@ -15,7 +18,10 @@ function ContributionsHandler(db) {
if (error) return next(error);

contrib.userId = userId; //set for nav menu items
return res.render("contributions", contrib);
return res.render("contributions", {
...contrib,
environmentalScripts
});
});
};

Expand Down Expand Up @@ -43,14 +49,16 @@ function ContributionsHandler(db) {
if (isInvalid) {
return res.render("contributions", {
updateError: "Invalid contribution percentages",
userId
userId,
environmentalScripts
});
}
// Prevent more than 30% contributions
if (preTax + afterTax + roth > 30) {
return res.render("contributions", {
updateError: "Contribution percentages cannot exceed 30 %",
userId
userId,
environmentalScripts
});
}

Expand All @@ -59,7 +67,10 @@ function ContributionsHandler(db) {
if (err) return next(err);

contributions.updateSuccess = true;
return res.render("contributions", contributions);
return res.render("contributions", {
...contributions,
environmentalScripts
});
});

};
Expand Down
12 changes: 9 additions & 3 deletions apps/server-render/app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const ContributionsHandler = require("./contributions");
const AllocationsHandler = require("./allocations");
const MemosHandler = require("./memos");
const ResearchHandler = require("./research");

const {
environmentalScripts
} = require("../../config/config");
const ErrorHandler = require("./error").errorHandler;

const index = (app, db) => {
Expand Down Expand Up @@ -74,14 +76,18 @@ const index = (app, db) => {

// Handle redirect for learning resources link
app.get("/tutorial", (req, res) => {
return res.render("tutorial/a1");
return res.render("tutorial/a1", {
environmentalScripts
});
});

app.get("/tutorial/:page", (req, res) => {
const {
page
} = req.params
return res.render(`tutorial/${page}`);
return res.render(`tutorial/${page}`, {
environmentalScripts
});
});

// Research Page
Expand Down
6 changes: 5 additions & 1 deletion apps/server-render/app/routes/memos.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const MemosDAO = require("../data/memos-dao").MemosDAO;
const {
environmentalScripts
} = require("../../config/config");

function MemosHandler(db) {
"use strict";
Expand All @@ -23,7 +26,8 @@ function MemosHandler(db) {
if (err) return next(err);
return res.render("memos", {
memosList: docs,
userId: userId
userId: userId,
environmentalScripts
});
});
};
Expand Down
Loading