Read a signed user identifier after cookie-parser validates it.
Authentication
Express.js · Pipe
req.signedCookies is the request object containing signed cookies validated and unsigned by cookie-parser. It is an empty object when the request carries no signed cookies.
req.signedCookies is an object populated by cookie-parser when configured with a secret. It contains signed request cookies after validation, with their signatures removed so application code can use the resulting values; when no signed cookies are present, it is an empty object.
req.signedCookiesObject containing validated signed cookies with unsigned values; defaults to {} when no signed cookies are sent.
const express = require('express');
const cookieParser = require('cookie-parser');
const app = express();
app.use(cookieParser(process.env.COOKIE_SECRET || 'development-secret'));
app.get('/profile', (req, res) => {
const user = req.signedCookies.user;
if (typeof user !== 'string') return res.sendStatus(401);
res.json({ user });
});
app.listen(3000);The middleware verifies signed cookies and makes their unsigned values available through req.signedCookies.
Authentication
Tamper detection
Request context
It is an object on the request containing signed cookies after cookie-parser has checked them and removed their signatures. The values are therefore unsigned and ready for application use.
Follow-up: What middleware setup is required? Configure cookie-parser with the signing secret before the route that reads req.signedCookies.
The property is populated when cookie-parser middleware is used with signed-cookie support. A signed cookie is moved into this collection after validation instead of remaining in req.cookies.
Follow-up: What happens without a secret? Signed-cookie support is not configured, so the application should not expect verified signed values in this property.
Signing prevents tampering because validation depends on a private secret. It does not hide or encrypt the cookie value, so it must not be treated as confidential storage.
Follow-up: Where should sensitive data go? Store sensitive information in a protected server-side system and keep only a suitable identifier in the cookie.
req.cookiescookie-parsercookieParser.signedCookiecookieParser.signedCookiesres.cookie()