M5 - Securing Node-based application
M5 - Securing Node-based application
Encryption in transit
HTTPS: Hypertext Transfer Protocol Secure is an extension of the Hypertext Transfer
Protocol. It uses encryption for secure communication over a computer network and is
widely used on the Internet. In HTTPS, the communication protocol is encrypted using
Transport Layer Security TLS or, formerly, Secure Sockets Layer (SSL)
If your app deals with or transmits sensitive data, use TLS to secure the connection and
the data. This technology encrypts data before it is sent from the client to the server,
thus preventing some common (and easy) hacks
SSL CERTIFICATE
You require an SSL certificate and an SSL key to do it. We created a self-signed SSL certificate
and added it to the Trusted Root Certificate Authorities Store.
Generate your own: using openssl, rsa command line tools in Unix-like platform
$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout
./demo.key -out demo.crt
For Windows environments, use Putty, which comes with PuttyGen; a GUI for creating keys and
certificates.
It's also possible to create your own self-signed certificate using openssl CLI.
Another way to get a ready certificate from a public service provider such as : Let's encrypt.
const fs = require("fs");
const https = require("https");
const express = require("express");
server.listen(8443)
app.listen(3000)
app.listen(3000)
Application
Role-based authentication policy
Try to implement a hasRole(string role) middleware that checks if the request user has the in
args given role.
5.5 Securing request headers
CORS: Cross-Origin Resource Sharing
app.listen(3000)
Application:
Create your CORS middleware
Create a middleware that sets cors policy for your API, and use it for all requests.
Push your work to npm once you've got satisfied by your implementation.
Use Helmet: Helmet can help protect your app from some well-known web vulnerabilities by
setting HTTP headers appropriately. It's a collection of several smaller middleware functions
that set security-related HTTP response headers. Some examples include
app.listen(3000)
Other known vulnerabilities
XSS: Cross-site scripting (JavaScript injection) where attackers try to send a malicious
JavaScript code and try to execute it on your running server.
CSRF: Cross-site Request Forgery
Cross-Site Request Forgery (CSRF) is an attack that forces a user to execute unwanted actions
on a web application in which they’re currently logged in.