@farm.js/workos 0.1.0-beta.98 → 0.1.0-beta.99

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
@@ -14,6 +14,12 @@ export interface WorkOSIntegrationInput {
14
14
  logoutPath?: string;
15
15
  sessionPath?: string;
16
16
  protectedRoutes?: string | string[];
17
+ /**
18
+ * Additional origins allowed to post the sign-out route, using the same
19
+ * pattern syntax as `serverActions.allowedOrigins`. The app's own origin is
20
+ * always trusted.
21
+ */
22
+ allowedOrigins?: string[];
17
23
  log?: FarmIntegrationLogger;
18
24
  }
19
25
  export type WorkOSIntegrationInstance = WorkOS;
@@ -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;AAWhG,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,GAAG,CAAC,EAAE,qBAAqB,CAAC;CAC7B;AAED,MAAM,MAAM,yBAAyB,GAAG,MAAM,CAAC;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C;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB;AAqFD,wBAAgB,MAAM,CAAC,KAAK,GAAE,sBAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAoOG,MAAM;;;;yBAyE7B,OAAO;;GAe3C"}
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
2
2
  import { WorkOS } from "@workos-inc/node";
3
3
  import { defineIntegration, integrationRoute } from "@farm.js/core";
4
+ import { describeIntegrationOriginRejection, resolveIntegrationAllowedOrigins, validateIntegrationRequestOrigin, } from "@farm.js/core/integrations";
4
5
  import { clearRequestCookie, createPathInferredClientApi, createDocumentNavigationMatchers, createRequestCookie, getCookieValue, getReturnTo, integrationConfig, normalizeMatchers, } from "@farm.js/integration-utils";
5
6
  import { workosClient } from "./client.js";
6
7
  const DEV_COOKIE_PASSWORD = "farmjs-workos-cookie-password-development-2026";
@@ -76,6 +77,7 @@ export function workos(input = {}) {
76
77
  const callbackPath = input.callbackPath ?? "/callback";
77
78
  const logoutPath = input.logoutPath ?? "/logout";
78
79
  const sessionPath = input.sessionPath ?? "/auth/session";
80
+ const allowedOrigins = resolveIntegrationAllowedOrigins(input.allowedOrigins, "workos.allowedOrigins");
79
81
  const workos = input.instance ??
80
82
  new WorkOS({
81
83
  apiKey,
@@ -118,6 +120,27 @@ export function workos(input = {}) {
118
120
  return null;
119
121
  }
120
122
  }
123
+ /**
124
+ * Reject a sign-out request that did not come from this app. Returns the
125
+ * response to send, or null when the request may proceed.
126
+ */
127
+ function rejectForeignOrigin(request) {
128
+ const result = validateIntegrationRequestOrigin(request, {
129
+ allowedOrigins,
130
+ requireOriginMetadata: request.method === "POST",
131
+ });
132
+ if (result.ok) {
133
+ return null;
134
+ }
135
+ const message = describeIntegrationOriginRejection(result.reason);
136
+ if (request.headers.get("x-farm-integration-client") === "1") {
137
+ return Response.json({ error: message }, { status: 403 });
138
+ }
139
+ return new Response(message, {
140
+ status: 403,
141
+ headers: { "content-type": "text/plain; charset=utf-8" },
142
+ });
143
+ }
121
144
  async function redirectToAuth(request, screenHint) {
122
145
  const requestUrl = new URL(request.url);
123
146
  const returnTo = getReturnTo(requestUrl.searchParams.get("returnTo"), "/dashboard");
@@ -243,6 +266,10 @@ export function workos(input = {}) {
243
266
  integrationRoute.post(logoutPath, {
244
267
  responseFormat: "json",
245
268
  async handler(request) {
269
+ const rejected = rejectForeignOrigin(request);
270
+ if (rejected) {
271
+ return rejected;
272
+ }
246
273
  const requestUrl = new URL(request.url);
247
274
  const sessionState = await getSession(workos, request, cookieName, cookiePassword);
248
275
  const headers = new Headers();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/workos",
3
- "version": "0.1.0-beta.98",
3
+ "version": "0.1.0-beta.99",
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.0-beta.98",
34
- "@farm.js/integration-utils": "0.1.0-beta.98"
33
+ "@farm.js/integration-utils": "0.1.0-beta.99",
34
+ "@farm.js/core": "0.1.0-beta.99"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc",