tough-cookie

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

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

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
79 /100 Good
Development Activity 84
Maintenance 60
Community 84
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
78 /100 Good
Architecture 82
Code Quality 85
Innovation 65
Learning Curve 78

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

Developer Tools · Devops

9,083

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
TypeScript 49%
JavaScript 48%
Updated 1 weeks ago
TypeScript
73%
AGPL 3.0

Firecrawl

AI Development · Developer Tools

185,614

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
65
Dependency
Built with
TypeScript 73%
Python 13%
Updated 4 days ago
JavaScript
99%
GPL 3.0

homepage

Monitoring · Productivity

32,888

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
71
Dependency
Built with
JavaScript 99%
Updated 4 days ago
TypeScript
67%
MIT

Hoppscotch

Developer Tools

80,529

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
65
Dependency
Built with
TypeScript 67%
Vue 25%
Updated 6 days ago
TypeScript
98%
Other

Kibana

Analytics · Monitoring

21,301

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
63
Dependency
Built with
TypeScript 98%
Updated 4 days ago
JavaScript
88%
GPL 3.0

NodeBB

Community

15,227

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
70
Dependency
Built with
JavaScript 88%
Go Template 11%
Updated 4 days ago
JavaScript
64%
AGPL 3.0

overleaf

Collaboration · Productivity

18,188

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

View details
87
Repo Health
80
Technical
62
Dependency
Built with
JavaScript 64%
TypeScript 30%
Updated 2 weeks ago
TypeScript
100%
AGPL 3.0

RSSHub

Automation · Social Media

46,339

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

View details
94
Repo Health
82
Technical
72
Dependency
Built with
TypeScript 100%
Updated 5 days ago
JavaScript
57%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,007

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
63
Dependency
Built with
JavaScript 57%
TypeScript 36%
Updated 4 days ago

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