How it works...
Our Express app can read and write cookies using the cookie-parser middleware. This module adds new cookie features to both the response and request objects in our Express routes. By reading from these values, we can determine behaviors of our web server, such as writing a new session if it doesn't exist yet.
By signing our cookies, we use the secret key we configured in our /app.js cookie-parser configuration. Needless to say, this key should be considered secret and should not be checked into the source control for the purpose of keeping your application's cookies protected from forgery. Ultimately, session-based security, such as this secret key, is only as good as your own vigilance and encryption strength. A much safer ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access