@celestia-island/hikari 0.55.474 → 0.55.475

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.
@@ -78,8 +78,9 @@ export interface HkLoginPlanCopy {
78
78
  */
79
79
  export declare function hkLoginPlanFromDiscovery(d: HkLoginDiscovery, copy?: HkLoginPlanCopy): HkLoginPlan;
80
80
  /** True for a path hikari may forward as a return address: absolute,
81
- * same-origin by construction (`/x`), and not a protocol-relative URL
82
- * (`//evil.example`) or the bare root. */
81
+ * same-origin by construction (`/x`), not a protocol-relative URL
82
+ * (`//evil.example`), not the bare root, and free of backslashes, control
83
+ * and format characters (see `UNSAFE_IN_A_LOCATION`). */
83
84
  export declare function hkIsSameOriginPath(raw: string): boolean;
84
85
  /**
85
86
  * The navigation target of a relay entry, or `null` when the document is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celestia-island/hikari",
3
- "version": "0.55.474",
3
+ "version": "0.55.475",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Hikari UI library, Vue 3 runtime — one design system for Vue 3 and Rust/WASM applications",
@@ -142,6 +142,25 @@ describe("hkIsSameOriginPath", () => {
142
142
  expect(hkIsSameOriginPath("https://evil.example")).toBe(false);
143
143
  expect(hkIsSameOriginPath("console")).toBe(false);
144
144
  expect(hkIsSameOriginPath("")).toBe(false);
145
+ // MUT:no-backslash — a path with a backslash (browsers turn `/\host`
146
+ // into `//host`), a control character (C0, DEL and the C1 range), a
147
+ // line separator or a display-reshaping format character never passes,
148
+ // because the value ends up in a `Location` header; an internationalised
149
+ // path always does. The same rule as kirino's navigation-target check.
150
+ for (const bad of [
151
+ "/\\evil.example/x",
152
+ "/\nevil",
153
+ "/in\u{007f}box",
154
+ "/\u{2028}x",
155
+ "/in\u{200b}box",
156
+ "/\u{202e}xp",
157
+ "/in\u{feff}box",
158
+ ]) {
159
+ expect(hkIsSameOriginPath(bad)).toBe(false);
160
+ }
161
+ // Internationalised paths are untouched by the rule.
162
+ expect(hkIsSameOriginPath("/收件箱")).toBe(true);
163
+ expect(hkIsSameOriginPath("/café/x?y=日本語")).toBe(true);
145
164
  });
146
165
  });
147
166
 
@@ -134,11 +134,26 @@ export function hkLoginPlanFromDiscovery(
134
134
  return { mode: d.mode, channels: [channel], defaultChannel: key };
135
135
  }
136
136
 
137
+ /** Characters a navigation target must never contain. A backslash is read
138
+ * as a slash by browsers, so `/` + backslash + host leaves the origin;
139
+ * control characters, the line/paragraph separators and the format
140
+ * characters that reshape how a path is displayed or ordered (soft hyphen,
141
+ * zero-width marks, bidi controls, BOM) are refused because the value ends
142
+ * up in a `Location` header and may be shown to a user. The same rule as
143
+ * kirino's `relay::is_unsafe_in_a_location`; keep the two in step. */
144
+ const UNSAFE_IN_A_LOCATION = /[\u0000-\u001f\u007f-\u009f\u2028\u2029\u00ad\u200b-\u200f\u202a-\u202e\u2066-\u2069\ufeff\\]/;
145
+
137
146
  /** True for a path hikari may forward as a return address: absolute,
138
- * same-origin by construction (`/x`), and not a protocol-relative URL
139
- * (`//evil.example`) or the bare root. */
147
+ * same-origin by construction (`/x`), not a protocol-relative URL
148
+ * (`//evil.example`), not the bare root, and free of backslashes, control
149
+ * and format characters (see `UNSAFE_IN_A_LOCATION`). */
140
150
  export function hkIsSameOriginPath(raw: string): boolean {
141
- return raw.startsWith("/") && !raw.startsWith("//") && raw !== "/";
151
+ return (
152
+ raw.startsWith("/") &&
153
+ !raw.startsWith("//") &&
154
+ raw !== "/" &&
155
+ !UNSAFE_IN_A_LOCATION.test(raw)
156
+ );
142
157
  }
143
158
 
144
159
  /**