@farm.js/workos 0.1.31 → 0.1.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -7,7 +7,17 @@ export interface WorkOSIntegrationInput {
7
7
  clientId?: string;
8
8
  apiKey?: string;
9
9
  cookiePassword?: string;
10
+ /**
11
+ * Session cookie name. A `__Host-` name (`__Host-wos-session`) cannot be set or shadowed by a
12
+ * sibling subdomain; Farm adds the `Secure` and `Path=/` it requires.
13
+ * @default "wos-session"
14
+ */
10
15
  cookieName?: string;
16
+ /**
17
+ * Login state cookie name, held between the redirect to AuthKit and the callback.
18
+ * @default "farm_workos_state"
19
+ */
20
+ stateCookieName?: string;
11
21
  loginPath?: string;
12
22
  signUpPath?: string;
13
23
  callbackPath?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAuC,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAgBhG,OAAO,KAAK,EAAuB,oBAAoB,EAAuB,MAAM,aAAa,CAAC;AAQlG,MAAM,WAAW,sBAAsB;IACrC,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,yBAAyB,CAAC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACpC;;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C,EAAE,MAAM,EAAE,CAAC;IAC1B,GAAG,CAAC,EAAE,qBAAqB,CAAC;CAC7B;AAED,MAAM,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAc/C,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB;AAgGD,wBAAgB,MAAM,CAAC,KAAK,GAAE,sBAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAgPG,MAAM;;;;yBAyE7B,OAAO;;mDAe3C"}
package/dist/index.js CHANGED
@@ -68,10 +68,27 @@ async function getSession(workos, request, cookieName, cookiePassword) {
68
68
  authentication,
69
69
  };
70
70
  }
71
+ function resolveCookieName(value, fallback, option) {
72
+ if (value === undefined)
73
+ return fallback;
74
+ // RFC 6265 token: no separators, whitespace, or control characters.
75
+ if (!/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(value)) {
76
+ throw new Error(`WorkOS integration ${option} must be a valid cookie name, got ${JSON.stringify(value)}.`);
77
+ }
78
+ return value;
79
+ }
71
80
  export function workos(input = {}) {
72
81
  const { clientId, apiKey, cookiePassword } = resolveEnv(input);
73
82
  const protectedMatchers = normalizeMatchers(input.protectedRoutes);
74
- const cookieName = input.cookieName ?? "wos-session";
83
+ const cookieName = resolveCookieName(input.cookieName, "wos-session", "cookieName");
84
+ // The OAuth `state` must be unguessable and bound to the browser that started
85
+ // the flow. We keep a random nonce in an HMAC-signed, http-only cookie and
86
+ // require the callback's state to match it, so an attacker cannot feed a
87
+ // victim a code/state pair from their own login (login CSRF / code injection).
88
+ const stateCookieName = resolveCookieName(input.stateCookieName, "farm_workos_state", "stateCookieName");
89
+ if (stateCookieName === cookieName) {
90
+ throw new Error("WorkOS integration cookieName and stateCookieName must differ.");
91
+ }
75
92
  const loginPath = input.loginPath ?? "/login";
76
93
  const signUpPath = input.signUpPath ?? "/signup";
77
94
  const callbackPath = input.callbackPath ?? "/callback";
@@ -83,11 +100,6 @@ export function workos(input = {}) {
83
100
  apiKey,
84
101
  clientId,
85
102
  });
86
- // The OAuth `state` must be unguessable and bound to the browser that started
87
- // the flow. We keep a random nonce in an HMAC-signed, http-only cookie and
88
- // require the callback's state to match it, so an attacker cannot feed a
89
- // victim a code/state pair from their own login (login CSRF / code injection).
90
- const stateCookieName = "farm_workos_state";
91
103
  function signState(payload) {
92
104
  const encoded = Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
93
105
  const signature = createHmac("sha256", cookiePassword).update(encoded).digest("hex");
@@ -102,9 +114,12 @@ export function workos(input = {}) {
102
114
  const encoded = signed.slice(0, separator);
103
115
  const signature = signed.slice(separator + 1);
104
116
  const expected = createHmac("sha256", cookiePassword).update(encoded).digest("hex");
105
- if (signature.length !== expected.length)
106
- return null;
107
- if (!timingSafeEqual(Buffer.from(signature, "utf8"), Buffer.from(expected, "utf8"))) {
117
+ // Compare byte lengths: a multibyte signature can match the hex digest's
118
+ // character count, and timingSafeEqual throws on unequal buffers.
119
+ const signatureBytes = Buffer.from(signature, "utf8");
120
+ const expectedBytes = Buffer.from(expected, "utf8");
121
+ if (signatureBytes.length !== expectedBytes.length ||
122
+ !timingSafeEqual(signatureBytes, expectedBytes)) {
108
123
  return null;
109
124
  }
110
125
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/workos",
3
- "version": "0.1.31",
3
+ "version": "0.1.35",
4
4
  "description": "WorkOS integration for Farm.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@workos-inc/node": "^8.9.0",
33
- "@farm.js/core": "0.1.31",
34
- "@farm.js/integration-utils": "0.1.31"
33
+ "@farm.js/core": "0.1.35",
34
+ "@farm.js/integration-utils": "0.1.35"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc",