Problem: the hexagonal refactor churns the backend tree for nine more phases; the UI delivery stack (web/ SPA, cmd/desktop Wails wrapper, compose/web image) must move to its own repo first so doc/layout rewrites land once on a backend-only tree. Change: - New repo git.hubris.network/dtoro/oikos-web (v0.33.0): web/, desktop/ (updateURL repointed to oikos-web releases), compose/, own CI (web + desktop jobs), own deploy script (CI-green gate, TOCTOU guard, version-tagged images, prune-to-3), own webhook receiver on :9798 + launchd unit, own compose project publishing the same 8091:80. - Cutover executed on mac-mini in order: oikos stack's web service stopped+removed, oikos-web project brought up on 8091; outer Caddy untouched (targets the published port) — serving + Authentik flow + /wails 404 quirk verified post-cutover. - Stripped from oikos: web/, cmd/desktop/, compose/web/, desktop CI workflow, ci.yml web job, Makefile ui/desktop/desktop-package/install targets, the compose web service, oikos-web from deploy.sh's fallback prune list; wails + go-keyring dropped from go.mod, vendor synced. - README / CONTRIBUTING / AGENTS.md / .agents dev+operations docs now point at the new repo; mbse + mascot design docs carry a path note. Risk: production SPA serving depends on the new pipeline now; rollback is versioned-image re-up of the old web service from a pre-split checkout (port 8091). Desktop builds installed before the split still check dtoro/oikos releases — one manual reinstall, noted in the oikos-web release notes. Verification: go vet, make test (race), make generate-check, golangci (no new findings; baseline down 400→365); post-cutover curls — localhost:8091 200, /wails/runtime.js 404, outer Caddy 302 Authentik.
6.0 KiB
Tough Cookie ·

A Node.js implementation of RFC6265 for cookie parsing, storage, and retrieval.
Getting Started
Install Tough Cookie using npm:
npm install tough-cookie
or yarn:
yarn add tough-cookie
Usage
import { Cookie, CookieJar } from 'tough-cookie'
// parse a `Cookie` request header
const reqCookies = 'ID=298zf09hf012fh2; csrf=u32t4o3tb3gg43; _gat=1'
.split(';')
.map(Cookie.parse)
// generate a `Cookie` request header
const cookieHeader = reqCookies.map((cookie) => cookie.cookieString()).join(';')
// parse a Set-Cookie response header
const resCookie = Cookie.parse(
'foo=bar; Domain=example.com; Path=/; Expires=Tue, 21 Oct 2025 00:00:00 GMT',
)
// generate a Set-Cookie response header
const setCookieHeader = cookie.toString()
// store and retrieve cookies
const cookieJar = new CookieJar() // uses the in-memory store by default
await cookieJar.setCookie(resCookie, 'https://example.com/')
const matchingCookies = await cookieJar.getCookies('https://example.com/')
Important
For more detailed usage information, refer to the API docs.
RFC6265bis
Support for RFC6265bis is being developed. As these revisions to RFC6252 are
still in Active Internet-Draft state, the areas of support that follow are subject to change.
SameSite Cookies
This change makes it possible for servers, and supporting clients, to mitigate certain types of CSRF
attacks by disallowing SameSite cookies from being sent cross-origin.
Example
import { CookieJar } from 'tough-cookie'
const cookieJar = new CookieJar() // uses the in-memory store by default
// storing cookies with various SameSite attributes
await cookieJar.setCookie(
'strict=authorized; SameSite=strict',
'http://example.com/index.html',
)
await cookieJar.setCookie(
'lax=okay; SameSite=lax',
'http://example.com/index.html',
)
await cookieJar.setCookie('normal=whatever', 'http://example.com/index.html')
// retrieving cookies using a SameSite context
const laxCookies = await cookieJar.getCookies('http://example.com/index.html', {
// the first cookie (strict=authorized) will not be returned if the context is 'lax'
// but the other two cookies will be returned
sameSiteContext: 'lax',
})
Note
It is highly recommended that you read RFC6265bis - Section 8.8 for more details on SameSite cookies, security considerations, and defense in depth.
Cookie Prefixes
Cookie prefixes are a way to indicate that a given cookie was set with a set of attributes simply by inspecting the first few characters of the cookie's name.
Two prefixes are defined:
-
"__Secure-"If a cookie's name begins with a case-sensitive match for the string
__Secure-, then the cookie was set with a "Secure" attribute. -
"__Host-"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.
If prefixSecurity is enabled for CookieJar, then cookies that match the prefixes defined above but do
not obey the attribute restrictions are not added.
You can define this functionality by passing in the prefixSecurity option to CookieJar. It can be one of 3 values:
silent: (default) Enable cookie prefix checking but silently fail to add the cookie if conditions are not met.strict: Enable cookie prefix checking and error out if conditions are not met.unsafe-disabled: Disable cookie prefix checking.
If
ignoreErroris passed in astruewhen setting a cookie then the error is silent regardless of theprefixSecurityoption (assuming it's enabled).
Example
import { CookieJar, MemoryCookieStore } from 'tough-cookie'
const cookieJar = new CookieJar(new MemoryCookieStore(), {
prefixSecurity: 'silent',
})
// this cookie will be silently ignored since the url is insecure (http)
await cookieJar.setCookie(
'__Secure-SID=12345; Domain=example.com; Secure;',
'http://example.com',
)
// this cookie will be stored since the url is secure (https)
await cookieJar.setCookie(
'__Secure-SID=12345; Domain=example.com; Secure;',
'https://example.com',
)
Note
It is highly recommended that you read RFC6265bis - Section 4.1.3 for more details on Cookie Prefixes.
Node.js Version Support
We follow the Node.js release schedule and support all versions that are in Active LTS or Maintenance. We will always do a major release when dropping support for older versions of node, and we will do so in consultation with our community.