Agenda
<aside> 📌 Reminders
HTTPS provides two critical features:
To enable HTTPS in an Express app, you need two assets:
server.key)server.crt)These can be generated using openssl:
$ openssl req -x509 -nodes -newkey rsa:4096 -keyout server.key -out server.crt
Configuring HTTPS in Express
import { readFileSync } from "fs";
import { createServer } from "https";
const privateKey = readFileSync('server.key');
const certificate = readFileSync('server.crt');
const config = { key: privateKey, cert: certificate };
createServer(config, app).listen(3000, () => {
console.log("HTTPS server on https://localhost:3000");
});
To prevent attacks such as Cross-Site Scripting (XSS) and Content Spoofing, validate all user inputs both on the client-side and server-side.
express-validator to sanitize and validate HTTP request data.Prevents cookies from being accessed by JavaScript, reducing the risk of XSS attacks.