NodeGoat lab: the OWASP Top 10 in a vulnerable Node.js and MongoDB application
OWASP NodeGoat is a Node.js and Express website on a MongoDB database that is insecure on purpose. It pretends to be a staff benefits site, and has the OWASP Top 10 for Node.js built into it: server-side JavaScript injection, NoSQL injection, insecure direct object references, missing access control, cross-site scripting, CSRF, weak session cookies, an open redirect, an old vulnerable library and a regular expression that can be made to hang. This lab starts it, with its database, in each student’s own private copy.
Every target is inside the student’s own lab copy, which has no route to the internet and none to any other student, so the only thing a student can attack is the application the lab started for them. The rule is said at the top of the lab: attack your own copy, never a site you do not own.
What students learn
The OWASP Top 10 in JavaScript, which many web back ends are written in. JavaScript on the server brings weaknesses a PHP or Java lab does not show: text passed to eval is run as code, and a MongoDB query written in JavaScript can be changed by what a user types, so a NoSQL database is injected as surely as an SQL one. NodeGoat writes the fix beside each weakness as a comment in its source, so every attack can be followed by the line of code that stops it. It suits a unit on secure coding or web security for students who know a little JavaScript.
Run it in your browser
The lab fills the database with NodeGoat’s own accounts each time it starts, so there is nothing to set up, and it says it is running only once the site serves a page.
- Open the Container page. Open Build on the bar and choose Run a container. Anybody may open it, and the Git lab and the SQL lab start with no account. Every other lab needs a free account: create one, sign in, then press Start.
- Find the lab. The Sample labs card lists every sample. Find OWASP NodeGoat.
- Press Start. Start runs it as it is, in one press. Edit the file first opens the compose file so you can change it before you start.
- Open it. On the lab’s page, press Open and sign in as user1 with the password User1_123, or as admin with Admin_123. The Tutorial Guide on the sign-in page explains every weakness. From the terminal the site is http://nodegoat:4000, and docker exec nodegoat reads its source. Stopping and starting the lab gives a fresh site.
What to ask students to hand in
For each weakness they try, the request they sent and what came back, a sentence in their own words on why it worked, and the line of NodeGoat’s source that fixes it. For stronger work ask them to explain why the fix works, for example why reading the account number from the session and not from the address stops one account reading another’s data.
A basic lesson on this lab
NodeGoat Basics is a small lesson worked in this lab, starting with the rule that a student attacks their own copy and nothing else. From the terminal they sign in with curl, send the Contributions page a sum and then code that lists the server’s folder, change the Allocations query so it returns every account, open another account’s allocations by changing a number in the address, and read the fix for each in the source.
Free personal accounts have it in the Basics module, which is on Home, and every college can copy it from the Library’s Basics folder. It is deliberately small: it shows a teacher what a lesson worked in a lab is, and the lab does the rest. Copy it into a module of your own to change it.
The code on GitHub
The compose file runs two images. One is the official MongoDB 4.4 image, pinned by digest and run as its own unprivileged account, because NodeGoat’s database driver is too old for anything newer. The other is our own image of NodeGoat: OWASP publishes NodeGoat as source code only, so mitsurutech/nodegoat-image on GitHub builds it in the open from the project’s source at one pinned commit, with its dependencies installed from its own lock file when the image is built, so nothing is downloaded when a student starts the lab. NodeGoat is Apache-2.0 licensed and belongs to its authors; nothing in it is changed. The lab has no way out to the internet, so the open redirect and the Research page have nothing outside to reach.
Set it as work
Say in the task which weaknesses to try and what to hand in.
- Make the lab. In your module add a task and choose the Container lab card, then In a GitHub repository. Give https://github.com/mitsurutech/lab-nodegoat-lab with the branch main. The compose file is the default, compose.yaml. Fork the repository first if you want to change it.
- Publish and try it. Publish pins the commit you were shown, so a later change in the repository does not alter a lab you have already set. Start your own copy first.
- Hand it out. Assign it like any task, with a due date if you want one, and say in the task what to do and what to hand in.
- Mark what is handed in. Open a student’s copy and the work they handed in, mark it, and send it back with a reason if it needs more.
Try this lab, and what it costs
A free personal account can work through the basic lessons in this lab, with enough free credit each month to follow most lessons and no card. For a class, a school or college has its first 365 days free for up to 50 students, then pays per student a year, with every lab included and staff free.
Questions people ask
- What are the sign-in details?
- user1 with the password User1_123, user2 with User2_123, and admin with Admin_123, the same in every copy, and anybody can make another account on the Sign up page. A copy is private to the student who started it, and nothing outside it can reach it.
- Why does the site go back to the start after a restart?
- The database is filled with NodeGoat’s own accounts each time the lab starts and is not saved, so a site broken by an exercise is cured by stopping and starting the lab.
- Why MongoDB 4.4 and not a newer version?
- NodeGoat’s database driver is the version the project pins, and it speaks a form of the MongoDB protocol that version 5.1 and later no longer accept. 4.4 is the newest that works, and since nothing outside the copy can reach the database its age matters only as part of the lesson on vulnerable components.
- How much memory does it need?
- The lab is two programs, the website and its database, limited to 256 and 384 megabytes. Together they use about 105 megabytes when idle, well inside a copy’s allowance.