@tensile-tools/auth-client 0.3.0 → 0.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.
@@ -3,8 +3,11 @@ export declare const returnToParam = "return_to";
3
3
  /**
4
4
  * `s` when sign-in may send the browser there, or undefined: a path that
5
5
  * starts with one `/`, with no scheme, host, or fragment, no backslash,
6
- * space, or control character, no decoded path that starts with `//`, and
7
- * at most 2048 characters. It matches authhttp.SafeReturnTo.
6
+ * space, or control character, no decoded path that starts with `//`, no
7
+ * `.` or `..` segment, plain or percent-encoded, and at most 2048
8
+ * characters. A URL parser removes dot segments, so `/.//evil.example`
9
+ * would resolve to `//evil.example`, another host. It matches
10
+ * authhttp.SafeReturnTo.
8
11
  */
9
12
  export declare function safeReturnTo(s: string | null | undefined): string | undefined;
10
13
  /** The safe return-to path in a query string such as `location.search`, or undefined. */
@@ -8,23 +8,29 @@ const maxReturnTo = 2048;
8
8
  /**
9
9
  * `s` when sign-in may send the browser there, or undefined: a path that
10
10
  * starts with one `/`, with no scheme, host, or fragment, no backslash,
11
- * space, or control character, no decoded path that starts with `//`, and
12
- * at most 2048 characters. It matches authhttp.SafeReturnTo.
11
+ * space, or control character, no decoded path that starts with `//`, no
12
+ * `.` or `..` segment, plain or percent-encoded, and at most 2048
13
+ * characters. A URL parser removes dot segments, so `/.//evil.example`
14
+ * would resolve to `//evil.example`, another host. It matches
15
+ * authhttp.SafeReturnTo.
13
16
  */
14
17
  export function safeReturnTo(s) {
15
18
  if (!s || s.length > maxReturnTo || s[0] !== '/' || s.startsWith('//') || s.startsWith('/\\'))
16
19
  return undefined;
17
20
  if (/[\u0000- \u007f\\#]/.test(s))
18
21
  return undefined;
22
+ const raw = s.split('?')[0];
19
23
  let path;
20
24
  try {
21
- path = decodeURIComponent(s.split('?')[0]);
25
+ path = decodeURIComponent(raw);
22
26
  }
23
27
  catch {
24
28
  return undefined;
25
29
  }
26
30
  if (path.startsWith('//') || path.startsWith('/\\') || /[\\\r\n]/.test(path))
27
31
  return undefined;
32
+ if (hasDotSegment(raw) || hasDotSegment(path))
33
+ return undefined;
28
34
  try {
29
35
  const base = 'https://origin.invalid';
30
36
  if (new URL(s, base).origin !== base)
@@ -35,6 +41,13 @@ export function safeReturnTo(s) {
35
41
  }
36
42
  return s;
37
43
  }
44
+ /** Whether `p` has a `.` or `..` segment, where `%2e` and `%2E` count as `.`. */
45
+ function hasDotSegment(p) {
46
+ return p.split('/').some(seg => {
47
+ const d = seg.replace(/%2e/gi, '.');
48
+ return d === '.' || d === '..';
49
+ });
50
+ }
38
51
  /** The safe return-to path in a query string such as `location.search`, or undefined. */
39
52
  export function returnToFrom(search) {
40
53
  return safeReturnTo(new URLSearchParams(search).get(returnToParam));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tensile-tools/auth-client",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Browser client for tensile-auth, like Better Auth but built for AI agents: passkey ceremonies with honest outcomes, one problem shape, step-up and approval challenges, password-manager sync, and tab sync.",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [