@kaviox/auth 0.1.0 → 0.1.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.
@@ -1,5 +1,10 @@
1
1
  /**
2
2
  * Where to go after signing in: a path on this app, never another site and never a sign-in step.
3
3
  * Anything else becomes "/".
4
+ *
5
+ * The answer is checked in the form it is used: as a path that the callback resolves against the
6
+ * app's origin. Checking only the input isn't enough, because normalising it can change what it
7
+ * points at: "/.//evil.example" and "/a/..//evil.example" become "//evil.example", which a browser
8
+ * reads as another site.
4
9
  */
5
10
  export declare function safeReturnTo(value: string | null | undefined): string;
package/dist/return-to.js CHANGED
@@ -1,15 +1,24 @@
1
+ const BASE = 'https://app.invalid';
1
2
  /**
2
3
  * Where to go after signing in: a path on this app, never another site and never a sign-in step.
3
4
  * Anything else becomes "/".
5
+ *
6
+ * The answer is checked in the form it is used: as a path that the callback resolves against the
7
+ * app's origin. Checking only the input isn't enough, because normalising it can change what it
8
+ * points at: "/.//evil.example" and "/a/..//evil.example" become "//evil.example", which a browser
9
+ * reads as another site.
4
10
  */
5
11
  export function safeReturnTo(value) {
6
- if (typeof value !== 'string' || !value.startsWith('/') || value.startsWith('//') || value.startsWith('/\\') || /[\u0000-\u001f\\]/.test(value))
12
+ if (typeof value !== 'string' || !value.startsWith('/') || /[\u0000-\u001f\\]/.test(value))
7
13
  return '/';
8
14
  try {
9
- const url = new URL(value, 'https://app.invalid');
10
- if (url.origin !== 'https://app.invalid' || url.pathname === '/auth' || url.pathname.startsWith('/auth/'))
15
+ const url = new URL(value, BASE);
16
+ const path = `${url.pathname}${url.search}${url.hash}`;
17
+ if (url.origin !== BASE || path.startsWith('//') || new URL(path, BASE).origin !== BASE)
11
18
  return '/';
12
- return `${url.pathname}${url.search}${url.hash}`;
19
+ if (url.pathname === '/auth' || url.pathname.startsWith('/auth/'))
20
+ return '/';
21
+ return path;
13
22
  }
14
23
  catch {
15
24
  return '/';
package/package.json CHANGED
@@ -1,18 +1,35 @@
1
1
  {
2
2
  "name": "@kaviox/auth",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Sign-in for Kaviox apps on Cloudflare Workers, through the Kaviox sign-in gateway: middleware, callback, sign-out, sessions and MCP token checks.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
7
7
  "sideEffects": false,
8
- "repository": { "type": "git", "url": "git+https://github.com/kaviox/platform.git", "directory": "packages/auth" },
9
- "engines": { "node": ">=22.13.0" },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/kaviox/platform.git",
11
+ "directory": "packages/auth"
12
+ },
13
+ "engines": {
14
+ "node": ">=22.13.0"
15
+ },
10
16
  "exports": {
11
- ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
12
- "./mcp": { "types": "./dist/mcp.d.ts", "default": "./dist/mcp.js" }
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "./mcp": {
22
+ "types": "./dist/mcp.d.ts",
23
+ "default": "./dist/mcp.js"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "README.md"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
13
32
  },
14
- "files": ["dist", "README.md"],
15
- "publishConfig": { "access": "public" },
16
33
  "scripts": {
17
34
  "build": "rm -rf dist && tsc -p tsconfig.build.json",
18
35
  "typecheck": "tsc --noEmit",