{"author":{"name":"Jeremy Stashewsky","email":"jstash@gmail.com"},"contributors":[{"name":"Ivan Nikulin"},{"name":"Shivan Kaul Sahib"},{"name":"Clint Ruoho"},{"name":"Ian Livingstone"},{"name":"Andrew Waterman"},{"name":"Michael de Libero"},{"name":"Jonathan Stewmon"},{"name":"Miguel Roncancio"},{"name":"Sebastian Mayr"},{"name":"Alexander Savin"},{"name":"Lalit Kapoor"},{"name":"Sam Thompson"},{"name":"Colin Casey"},{"name":"Will Harney"}],"license":"BSD-3-Clause","name":"tough-cookie","description":"RFC6265 Cookies and Cookie Jar for node.js","keywords":["HTTP","cookie","cookies","set-cookie","cookiejar","jar","RFC6265","RFC2965"],"version":"6.0.2","homepage":"https://github.com/salesforce/tough-cookie","repository":{"type":"git","url":"git://github.com/salesforce/tough-cookie.git"},"bugs":{"url":"https://github.com/salesforce/tough-cookie/issues"},"type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{"import":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","require":"./dist/index.cjs"}},"scripts":{"build":"tsup lib/cookie/index.ts --format cjs,esm --dts --clean --sourcemap","lint":"npm run _lint:check","prepack":"npm run build","prepare-pr":"npm run build && npm test -- run && npm run _api:update && npm run _docs:generate && npm run _format:fix && npm run _lint:fix && npm run _lint:types","test":"vitest","version":"npm run _version:generate && npm run prepare-pr && git add --renormalize .","_api:check":"api-extractor run --verbose","_api:update":"api-extractor run --verbose --local","_docs:generate":"api-documenter generate --input-folder ./tmp --output-folder ./api/docs","_format:check":"prettier . --check","_format:fix":"prettier . --write","_lint:check":"eslint .","_lint:fix":"eslint . --fix","_lint:types":"attw --pack .","_version:generate":"genversion --template version-template.ejs --force lib/version.ts"},"//":"We only support node LTS versions, but v16 still works. We won't block v16 until it becomes a burden.","engines":{"node":">=16"},"devDependencies":{"@arethetypeswrong/cli":"^0.18.2","@eslint/js":"^10.0.0","@microsoft/api-documenter":"^7.26.20","@microsoft/api-extractor":"^7.52.3","@types/node":"^20.19.6","@vitest/eslint-plugin":"^1.1.40","eslint":"^10.0.0","eslint-config-prettier":"^10.1.2","eslint-import-resolver-typescript":"^4.4.4","eslint-plugin-import-x":"^4.16.2","eslint-plugin-prettier":"^5.2.6","genversion":"^3.2.0","globals":"^17.4.0","prettier":"^3.5.3","tsup":"^8.5.0","typescript":"5.5.3","typescript-eslint":"^8.46.3","vitest":"^4.0.7"},"dependencies":{"tldts":"^7.0.5"},"gitHead":"40708dd809cfb1dd658270dc85597bf9f68a6ccc","_id":"tough-cookie@6.0.2","_nodeVersion":"24.18.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-exgYmnmL/sJpR3upZfXG5PoatXQii55xAiXGXzY+sROLZ/Y+SLcp9PgJNI9Vz37HpQ74WvDcLT8eqm+kV3FzrA==","shasum":"7b1f22fcf2daf06c4ff9d53ec1845f44c6627062","tarball":"http://registry-npm.ywwl.com/tough-cookie/download/tough-cookie-6.0.2.tgz","fileCount":9,"unpackedSize":759679,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/tough-cookie@6.0.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDwLpxr7p3mYv9l7+Jkmg4xgPoZaLetEBjf8eKTDvWTHQIhAPHQh6tp8JLVtrI5PZgAfIKM+mMbnr75K2HAk3NNsnZt"}],"size":159373,"noattachment":false,"key":"/tough-cookie/-/tough-cookie-6.0.2.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:4d3f0462-3fa8-4f47-ac17-5149dfa11915"}},"directories":{},"maintainers":[{"name":"awaterma","email":"awaterma@awaterma.net"},{"name":"ccasey","email":"ccasey@salesforce.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tough-cookie_6.0.2_1783449142645_0.5345270862657683"},"_hasShrinkwrap":false,"readme":"# Tough Cookie &middot; [![RFC6265][rfc6265-badge]][rfc6265-tracker] [![RFC6265bis][rfc6265bis-badge]][rfc6265bis-tracker] [![npm version][npm-badge]][npm-repo] [![CI on Github Actions: salesforce/tough-cookie][ci-badge]][ci-url] ![PRs Welcome][prs-welcome-badge]\n\nA Node.js implementation of [RFC6265][rfc6265-tracker] for cookie parsing, storage, and retrieval.\n\n## Getting Started\n\nInstall Tough Cookie using [`npm`][npm-repo]:\n\n```shell\nnpm install tough-cookie\n```\n\nor [`yarn`][yarn-repo]:\n\n```shell\nyarn add tough-cookie\n```\n\n## Usage\n\n```typescript\nimport { Cookie, CookieJar } from 'tough-cookie'\n\n// parse a `Cookie` request header\nconst reqCookies = 'ID=298zf09hf012fh2; csrf=u32t4o3tb3gg43; _gat=1'\n  .split(';')\n  .map(Cookie.parse)\n// generate a `Cookie` request header\nconst cookieHeader = reqCookies.map((cookie) => cookie.cookieString()).join(';')\n\n// parse a Set-Cookie response header\nconst resCookie = Cookie.parse(\n  'foo=bar; Domain=example.com; Path=/; Expires=Tue, 21 Oct 2025 00:00:00 GMT',\n)\n// generate a Set-Cookie response header\nconst setCookieHeader = cookie.toString()\n\n// store and retrieve cookies\nconst cookieJar = new CookieJar() // uses the in-memory store by default\nawait cookieJar.setCookie(resCookie, 'https://example.com/')\nconst matchingCookies = await cookieJar.getCookies('https://example.com/')\n```\n\n> [!IMPORTANT]\n> For more detailed usage information, refer to the [API docs](./api/docs/tough-cookie.md).\n\n## RFC6265bis\n\nSupport for [RFC6265bis][rfc6265bis-tracker] is being developed. As these revisions to [RFC6252][rfc6265-tracker] are\nstill in `Active Internet-Draft` state, the areas of support that follow are subject to change.\n\n### SameSite Cookies\n\nThis change makes it possible for servers, and supporting clients, to mitigate certain types of CSRF\nattacks by disallowing `SameSite` cookies from being sent cross-origin.\n\n#### Example\n\n```typescript\nimport { CookieJar } from 'tough-cookie'\n\nconst cookieJar = new CookieJar() // uses the in-memory store by default\n\n// storing cookies with various SameSite attributes\nawait cookieJar.setCookie(\n  'strict=authorized; SameSite=strict',\n  'http://example.com/index.html',\n)\nawait cookieJar.setCookie(\n  'lax=okay; SameSite=lax',\n  'http://example.com/index.html',\n)\nawait cookieJar.setCookie('normal=whatever', 'http://example.com/index.html')\n\n// retrieving cookies using a SameSite context\nconst laxCookies = await cookieJar.getCookies('http://example.com/index.html', {\n  // the first cookie (strict=authorized) will not be returned if the context is 'lax'\n  // but the other two cookies will be returned\n  sameSiteContext: 'lax',\n})\n```\n\n> [!NOTE]\n> It is highly recommended that you read [RFC6265bis - Section 8.8][samesite-implementation] for more details on SameSite cookies, security considerations, and defense in depth.\n\n### Cookie Prefixes\n\nCookie prefixes are a way to indicate that a given cookie was set with a set of attributes simply by\ninspecting the first few characters of the cookie's name.\n\nTwo prefixes are defined:\n\n- `\"__Secure-\"`\n\n  If a cookie's name begins with a case-sensitive match for the string `__Secure-`, then the cookie was set with a \"Secure\" attribute.\n\n- `\"__Host-\"`\n\n  If a cookie's name begins with a case-sensitive match for the string `__Host-`, then the cookie was set with a \"Secure\" attribute, a \"Path\" attribute with a value of \"/\", and no \"Domain\" attribute.\n\nIf `prefixSecurity` is enabled for `CookieJar`, then cookies that match the prefixes defined above but do\nnot obey the attribute restrictions are not added.\n\nYou can define this functionality by passing in the `prefixSecurity` option to `CookieJar`. It can be one of 3 values:\n\n1. `silent`: (**default**) Enable cookie prefix checking but silently fail to add the cookie if conditions are not met.\n2. `strict`: Enable cookie prefix checking and error out if conditions are not met.\n3. `unsafe-disabled`: Disable cookie prefix checking.\n\n> If `ignoreError` is passed in as `true` when setting a cookie then the error is silent regardless of the `prefixSecurity` option (assuming it's enabled).\n\n#### Example\n\n```typescript\nimport { CookieJar, MemoryCookieStore } from 'tough-cookie'\n\nconst cookieJar = new CookieJar(new MemoryCookieStore(), {\n  prefixSecurity: 'silent',\n})\n\n// this cookie will be silently ignored since the url is insecure (http)\nawait cookieJar.setCookie(\n  '__Secure-SID=12345; Domain=example.com; Secure;',\n  'http://example.com',\n)\n\n// this cookie will be stored since the url is secure (https)\nawait cookieJar.setCookie(\n  '__Secure-SID=12345; Domain=example.com; Secure;',\n  'https://example.com',\n)\n```\n\n> [!NOTE]\n> It is highly recommended that you read [RFC6265bis - Section 4.1.3][cookie-prefixes-implementation] for more details on Cookie Prefixes.\n\n### Potentially Trustworthy Origins are considered \"Secure\"\n\nThe definition of a \"Secure\" connection is not explicitly defined by [RFC6265bis][rfc6265bis-tracker] but the following text is\nprovided in [RFC6265bis - Section 5.8.3][secure-connection-note]:\n\n> [!NOTE]\n> Typically, user agents consider a connection secure if the connection makes use of transport-layer security, such as\n> SSL or TLS, or if the host is trusted. For example, most user agents consider \"https\" to be a scheme that denotes a\n> secure protocol and \"localhost\" to be trusted host.\n\nAs well as a note to [Appendix A. Changes from RFC6265][secure-connection-appendix-a] which refers to **\"potentially trustworthy\norigins\"** which are defined in the [Secure Contexts - W3C Candidate Recommendation Draft][potentially-trustworthy-origin]:\n\n> [!Note]\n> Considers potentially trustworthy origins as \"secure\".\n\nSince most web browsers treat `localhost` as a trustworthy origin, by default, so does `tough-cookie`. To disable this\nbehavior, the `CookieStore` must be configured with:\n\n```typescript\nimport { CookieJar, MemoryCookieStore } from 'tough-cookie'\n\nconst cookieJar = new CookieJar(new MemoryCookieStore(), {\n  // add configuration so localhost will not be considered trustworthy\n  // (fyi - this doesn't apply to https cookies on localhost as those use a secure protocol)\n  allowSecureOnLocal: false,\n})\n\n// this cookie will be persisted to storage\nawait cookieJar.setCookie(\n  'SID=12345; Domain=localhost; Secure;',\n  'http://localhost',\n)\n\n// but, on retrieval, it will not be returned\nawait cookieJar.getCookiesSync('http://localhost')\n```\n\n## Node.js Version Support\n\nWe follow the [Node.js release schedule](https://github.com/nodejs/Release#release-schedule) and support\nall versions that are in Active LTS or Maintenance. We will always do a major release when dropping support\nfor older versions of node, and we will do so in consultation with our community.\n\n[npm-badge]: https://img.shields.io/npm/v/tough-cookie.svg?style=flat\n[npm-repo]: https://www.npmjs.com/package/tough-cookie\n[ci-badge]: https://github.com/salesforce/tough-cookie/actions/workflows/ci.yaml/badge.svg\n[ci-url]: https://github.com/salesforce/tough-cookie/actions/workflows/ci.yaml\n[rfc6265-badge]: https://img.shields.io/badge/RFC-6265-flat?labelColor=000000&color=666666\n[rfc6265-tracker]: https://datatracker.ietf.org/doc/rfc6265/\n[rfc6265bis-badge]: https://img.shields.io/badge/RFC-6265bis-flat?labelColor=000000&color=666666\n[rfc6265bis-tracker]: https://datatracker.ietf.org/doc/draft-ietf-httpbis-rfc6265bis/\n[samesite-implementation]: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-8.8\n[cookie-prefixes-implementation]: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.3\n[secure-connection-note]: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-19#section-5.8.3-2.1.2.3.1\n[secure-connection-appendix-a]: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-19#appendix-A-1.7.1\n[potentially-trustworthy-origin]: https://www.w3.org/TR/secure-contexts/#is-origin-trustworthy\n[prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg\n[yarn-repo]: https://yarnpkg.com/package?name=tough-cookie\n","publish_time":1783449142813,"_cnpm_publish_time":1783449142813,"dist-tags":{"latest":"6.1.0","next":"6.0.0-rc.2"}}