tough-cookie

RFC 6265-compliant cookie parsing and CookieJar for Node.js

Library
npm
v6.0.2
1,065stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
78/100Good
Development Activity80
Maintenance60
Community84
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture82
Code Quality85
Innovation65
Learning Curve78

tough-cookie is the reference implementation of the HTTP cookie specification (RFC 6265, with legacy RFC 2965 support) for JavaScript. It parses Set-Cookie headers, enforces domain and path matching rules, expiration and max-age handling, and cookie-ordering semantics, then stores them in a pluggable CookieJar so HTTP clients can round-trip cookies correctly across requests.

It underpins cookie handling in Node’s most widely used HTTP client libraries (request, axios’s cookie-jar-support ecosystem, and many scraping/testing tools) and is a transitive dependency of a huge share of the npm ecosystem. Public suffix matching is delegated to tldts so domain-boundary cookie rules stay correct as the public suffix list evolves.

What You Get

  • RFC 6265-compliant Cookie.parse() for Set-Cookie header strings, including legacy RFC 2965 compatibility
  • CookieJar with domain-matching, path-matching, and expiration-aware cookie storage and retrieval
  • Pluggable Store interface (with an in-memory MemoryCookieStore default) so cookies can be persisted to Redis, a database, or disk
  • Correct public-suffix-aware domain matching via the tldts dependency, preventing cross-site cookie leakage on shared suffixes
  • Serialization/deserialization of the entire jar to JSON for persisting sessions across process restarts

Common Use Cases

  • Building an HTTP client or scraper that needs to persist and replay cookies correctly across multiple requests and redirects
  • Implementing session-aware testing tools that must simulate a browser’s cookie jar behavior
  • Writing a custom cookie store backend (Redis, SQL) by implementing the Store interface for multi-process or distributed session sharing
  • Validating that a server’s Set-Cookie headers are RFC 6265-compliant during API or security testing

Under The Hood

Architecture The library separates parsing/validation logic from storage: lib/cookie/ holds the Cookie class (parsing, serialization, attribute validation) while lib/store.ts defines the abstract Store interface and lib/memstore.ts provides the default in-memory implementation; supporting modules (permuteDomain.ts, pathMatch.ts, domainMatch logic, getPublicSuffix.ts) implement the RFC 6265 matching algorithms as small, independently testable functions, and CookieJar composes all of these to expose the public get/set/remove API — a clean separation that lets consumers swap storage without touching parsing logic.

Tech Stack Written in TypeScript, built with tsup to dual-publish ESM and CJS (dist/index.js / dist/index.cjs) with generated .d.ts types, tested with Vitest, API-surface-checked with Microsoft’s api-extractor/api-documenter, and linted with the modern flat-config ESLint plus typescript-eslint; its only runtime dependency is tldts for public suffix list lookups, keeping the dependency footprint minimal for a package this widely depended-upon.

Code Quality The lib/__tests__/ directory contains over 20 dedicated spec files covering parsing, domain/path matching, cookie sorting, prefixes (__Secure-, __Host-), SameSite behavior, jar serialization, and even an explicit regression.spec.ts for previously-reported bugs — an unusually thorough test suite for a utility library, reflecting its role as security-sensitive infrastructure with a documented CVE history (prototype pollution, ReDoS) that has driven this test rigor.

API Design The Cookie.parse() / CookieJar.setCookie() / CookieJar.getCookies() surface is small and mirrors familiar cookie-jar mental models from browsers, and the Store interface is a clean extension point (three or four methods to implement) for custom backends; async/callback and promise-based APIs are both supported for CookieJar methods, easing migration from older callback-style Node code, though the coexistence of both calling conventions adds a small amount of surface area new users need to learn.

Used by 11 apps in this directory

TypeScript
49%
MPL 2.0

Artillery

Devops · Developer Tools

9,054

Cloud-scale load testing and functional testing for APIs, WebSockets, gRPC, and headless browsers, distributed across AWS Lambda or Fargate with zero infrastructure to manage.

View details
89
Repo Health
73
Technical
68
Dependency
Built with
TypeScript49%
JavaScript48%
Updated 5 days ago
TypeScript
72%
AGPL 3.0

Firecrawl

AI Development · Developer Tools

169,311

Turn any website into clean, LLM-ready data with a single API call — no proxy headaches, no scraping complexity.

View details
89
Repo Health
83
Technical
66
Dependency
Built with
TypeScript72%
Python14%
Updated today
JavaScript
99%
GPL 3.0

homepage

Monitoring · Productivity

32,092

A fast, fully static, and secure self-hosted startpage with Docker service discovery and integrations for over 160 services.

View details
91
Repo Health
86
Technical
74
Dependency
Built with
JavaScript99%
Updated today
TypeScript
67%
MIT

Hoppscotch

Developer Tools

80,055

A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.

View details
91
Repo Health
83
Technical
66
Dependency
Built with
TypeScript67%
Vue23%
Updated 3 days ago
TypeScript
97%
Other

Kibana

Analytics · Monitoring

21,251

Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.

View details
98
Repo Health
87
Technical
68
Dependency
Built with
TypeScript97%
Updated today
JavaScript
87%
GPL 3.0

NodeBB

Community

15,199

Modern Node.js forum software with real-time WebSockets, multi-database support, and a plugin ecosystem — the community platform built for the open web and the Fediverse.

View details
97
Repo Health
78
Technical
71
Dependency
Built with
JavaScript87%
Go Template12%
Updated today
JavaScript
63%
AGPL 3.0

overleaf

Collaboration · Productivity

18,035

Open-source, real-time collaborative LaTeX editor with sandboxed compilation and full TeXLive support for self-hosted academic and research teams.

View details
84
Repo Health
80
Technical
67
Dependency
Built with
JavaScript63%
TypeScript29%
Updated 1 months ago
TypeScript
92%
AGPL 3.0

RSSHub

Automation · Social Media

45,802

Turn any website into an RSS feed — social media, streaming platforms, and niche sites all become subscribable in seconds.

View details
83
Repo Health
82
Technical
74
Dependency
Built with
TypeScript92%
Updated yesterday
JavaScript
59%
AGPL 3.0

ToolJet

Low Code Platforms · No Code Platforms · AI Agents

40,458

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
65
Dependency
Built with
JavaScript59%
TypeScript33%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search