Node.js Security and Architecture Flashcards
What is OWASP?
Open Web Application Security Project.
It’s a useful resource for threat prevention advice
Name the three security risks that we studies that are applicable to node.js
Code Injection
Cross Site Scripting (XSS)
Malicious Packages
What is Code Injection?
Inserting (‘injecting’) data into an application, which is then interpreted as a command
A SERVER SIDE vulnrability
How do you protect against Code Injection?
Validating Data - ensuring that the data you have received is of the correct type (eg expecting a String but receiving a JS object)
What is XSS?
Cross Site Scripting
A specific type of injection attack - a CLIENT SIDE vulnerability
An attacker submits untrusted data, which the browser then re-displays. It could seem legitimate (eg a facebook post or fake listing on a shopping site), which tricks users into trusting it and passing the code. Code is then passed back to the user in a way that causes the browser to parse the code as if it were part of the application.
How do you protect against XSS?
Sanitising Input - check whether the input matches the expectation
Never print input from a user to a HTML page without sanitising it (removing undesirable parts of the code)
Use a trusted library to do this
What is a Malicious Package?
Packages downloaded from npm that do not do what they day they do, or are malicious copies of legitimate packages
Why are Malicious Packages dangerous?
When installing from npm, you:
- execute code from someone else
- expose users to code not written by you, often for code that hasn’t been written yet (libraries get updated)
By allowing others to run code on your machine with user privileges, you are giving them a lot of power
How do you protect against malicious packages?
Check npm trust indicators
Lock down the package version when downloading
Check for typos when installing
What is ODM?
Object Document Mapping
Maps documents in a database to objects in the code
- exists for document-oriented databases
Provides abstraction for the basic CRUD methods and other operations on documents
What does using ODM mean in practice?
You can write code in your app’s naive language (eg JS)
If used properly, ODM will take care of object persistance
How does ODM help to achieve a three-tier architecture?
It abstracts away the details of database calls