@snokam/auth 5.3.4 → 5.4.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [5.4.1](https://github.com/snokam/components/compare/@snokam/auth@5.4.0...@snokam/auth@5.4.1) (2026-10-15)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **auth:** no cross-origin access to tokens or Vis som; only the actor ends a session ([#2959](https://github.com/snokam/components/issues/2959)) ([d1eda77](https://github.com/snokam/components/commit/d1eda773459365cf6bd46bbc0de179d57763ad75))
11
+
12
+ # [5.4.0](https://github.com/snokam/components/compare/@snokam/auth@5.3.4...@snokam/auth@5.4.0) (2026-10-15)
13
+
14
+ ### Features
15
+
16
+ - Vis som is a platform admin's everywhere; the admin sync stays prod-only ([#2958](https://github.com/snokam/components/issues/2958)) ([a2f9824](https://github.com/snokam/components/commit/a2f982455d1c19c2028e181ed109fe1f3485de90))
17
+
6
18
  ## [5.3.4](https://github.com/snokam/components/compare/@snokam/auth@5.3.3...@snokam/auth@5.3.4) (2026-10-15)
7
19
 
8
20
  ### Bug Fixes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@snokam/auth",
3
3
  "description": "Snøkam auth components",
4
- "version": "5.3.4",
4
+ "version": "5.4.1",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
7
7
  "files": [
@@ -28,10 +28,10 @@
28
28
  "path-to-regexp": "^8.4.2",
29
29
  "@snokam/platform-client": "5.3.1",
30
30
  "@snokam/react-query": "1.1.0",
31
- "@snokam/sanity-page-content": "6.5.2",
32
31
  "@snokam/tenant": "4.3.1",
33
- "@snokam/identity": "1.1.0",
34
- "@snokam/ui": "6.1.0"
32
+ "@snokam/sanity-page-content": "6.5.2",
33
+ "@snokam/ui": "6.1.0",
34
+ "@snokam/identity": "1.1.0"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "next": "16.3.8",
@@ -6,8 +6,6 @@ import { impersonationPickerUrl } from "../../impersonation/required";
6
6
 
7
7
  const PICKER_BUSINESSES_PATH = "/api/impersonation/businesses";
8
8
 
9
- // The picker's businesses route answers 200 only with persona mode on and an operator's own
10
- // token, so a signed-in operator who is no employee here goes to pick a test user instead.
11
9
  export function usePickerRedirect(): boolean {
12
10
  const platformBaseUrl = useOptionalConfig()?.NEXT_PUBLIC_PLATFORM_BASE_URL;
13
11
  const [checking, setChecking] = useState(Boolean(platformBaseUrl));
@@ -0,0 +1,25 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+ import { allowsCrossOrigin } from "./cors-paths.ts";
4
+
5
+ describe("cross-origin access", () => {
6
+ it("is never granted to the routes that hand out tokens or Vis som sessions", () => {
7
+ for (const path of [
8
+ "/api/auth/token",
9
+ "/api/auth/session",
10
+ "/api/impersonation/start",
11
+ "/api/impersonation/adopt",
12
+ "/api/impersonation/businesses",
13
+ "/api/password/login",
14
+ "/handoff/start",
15
+ ]) {
16
+ assert.equal(allowsCrossOrigin(path), false, path);
17
+ }
18
+ });
19
+
20
+ it("is still granted to the app's other API routes", () => {
21
+ assert.equal(allowsCrossOrigin("/api/menu"), true);
22
+ assert.equal(allowsCrossOrigin("/api/events/random"), true);
23
+ assert.equal(allowsCrossOrigin("/api/authors"), true);
24
+ });
25
+ });
@@ -0,0 +1,10 @@
1
+ const SAME_ORIGIN_ONLY = [
2
+ "/api/auth/",
3
+ "/api/impersonation/",
4
+ "/api/password/",
5
+ "/handoff/",
6
+ ];
7
+
8
+ export function allowsCrossOrigin(pathname: string): boolean {
9
+ return !SAME_ORIGIN_ONLY.some((prefix) => pathname.startsWith(prefix));
10
+ }
@@ -5,6 +5,7 @@ import { NextResponse, NextFetchEvent } from "next/server";
5
5
  import { Auth } from "./types";
6
6
  import { getSessionCookieSettings, getAuthUrl } from "./session";
7
7
  import { addCorsHeaders } from "./cors";
8
+ import { allowsCrossOrigin } from "./cors-paths";
8
9
  import { hasImpersonationPass } from "./impersonation/pass-cookie";
9
10
 
10
11
  const TEST_ENVIRONMENT = "t";
@@ -143,7 +144,10 @@ export function buildAuthMiddleware({
143
144
  ) => {
144
145
  const origin = request.headers.get("origin");
145
146
  const isApiRoute = request.nextUrl.pathname.startsWith("/api/");
146
- const applyCors = corsEnabled && (isApiRoute || corsAllRoutes);
147
+ const applyCors =
148
+ corsEnabled &&
149
+ (isApiRoute || corsAllRoutes) &&
150
+ allowsCrossOrigin(request.nextUrl.pathname);
147
151
 
148
152
  if (applyCors && request.method === "OPTIONS") {
149
153
  const response = new NextResponse(null, { status: 204 });