
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
modern-cookies
Advanced tools
modern-cookies
is a simple, type-safe, and secure cookie management utility for Express and Nest.js applications.
It provides a minimal API for setting, getting, and deleting cookies — with security best practices built in.
setCookie
, getCookie
, and deleteCookie
for effortless cookie management.false
on failures and provides a logError
flag for optional console logging.__Secure-
and __Host-
.npm install modern-cookies@latest
💡 Works with
npm
,pnpm
, andyarn
. You can use it in dev dependencies since it's typically used only for local HTTPS.
import express from 'express';
import { getCookie, setCookie, deleteCookie } from 'modern-cookies';
import { env } from './env';
function bootstrap() {
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.get('/get-cookie', (req, res) => {
const cookieValue = getCookie(req, 'myCookie');
res.json({ cookieValue });
});
app.get('/set-cookie', (req, res) => {
const isSet = setCookie(res, 'myCookie', 'SomeValue123', {
httpOnly: true,
maxAge: 60, // 1 minute
});
res.json({ message: isSet ? 'Cookie set successfully' : 'Failed to set cookie' });
});
app.get('/delete-cookie', (req, res) => {
const isDeleted = deleteCookie(res, 'myCookie');
res.json({ message: isDeleted ? 'Cookie deleted successfully' : 'Failed to delete cookie' });
});
app.listen(env.PORT || 3000, () => {
console.log(`🚀 Express server running on: http://localhost:${env.PORT || 3000}`);
});
}
bootstrap();
import { Controller, Get, Req, Res } from '@nestjs/common';
import type { Request, Response } from 'express';
import { getCookie, setCookie, deleteCookie } from 'modern-cookies';
@Controller('')
export class PublicController {
@Get('get-cookie')
getCookie(@Req() req: Request) {
const cookieValue = getCookie(req, 'myCookie');
return { cookieValue };
}
@Get('set-cookie')
setCookie(@Res() res: Response) {
const isSet = setCookie(res, 'myCookie', 'SomeValue123', {
httpOnly: true,
maxAge: 60, // 1 minute
});
// Since we used the `Res` we need to send the response manually
res.json({ message: isSet ? 'Cookie set successfully' : 'Failed to set cookie' });
}
@Get('delete-cookie')
deleteCookie(@Res() res: Response) {
const isDeleted = deleteCookie(res, 'myCookie');
res.json({ message: isDeleted ? 'Cookie deleted successfully' : 'Failed to delete cookie' });
}
}
We want to thank Cookie NPM package for the cookie parsing and serialization used in this package.
Want to contribute or suggest a feature?
This project is licensed under the MIT License.
Thank you!
FAQs
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.