@celestia-island/hikari 0.55.383 → 0.55.386

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/package.json CHANGED
@@ -1,111 +1,111 @@
1
1
  {
2
- "name": "@celestia-island/hikari",
3
- "version": "0.55.383",
4
- "private": false,
5
- "type": "module",
6
- "description": "Hikari UI library, Vue 3 runtime — one design system for Vue 3 and Rust/WASM applications",
7
- "license": "SySL-1.0",
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/celestia-island/hikari"
2
+ "name": "@celestia-island/hikari",
3
+ "version": "0.55.386",
4
+ "private": false,
5
+ "type": "module",
6
+ "description": "Hikari UI library, Vue 3 runtime — one design system for Vue 3 and Rust/WASM applications",
7
+ "license": "SySL-1.0",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/celestia-island/hikari"
11
+ },
12
+ "homepage": "https://github.com/celestia-island/hikari",
13
+ "keywords": [
14
+ "vue3",
15
+ "ui-components",
16
+ "design-system",
17
+ "hikari",
18
+ "celestia-island"
19
+ ],
20
+ "main": "./src/index.ts",
21
+ "types": "./src/index.ts",
22
+ "exports": {
23
+ ".": {
24
+ "import": "./src/index.ts",
25
+ "types": "./src/index.ts"
11
26
  },
12
- "homepage": "https://github.com/celestia-island/hikari",
13
- "keywords": [
14
- "vue3",
15
- "ui-components",
16
- "design-system",
17
- "hikari",
18
- "celestia-island"
19
- ],
20
- "main": "./src/index.ts",
21
- "types": "./src/index.ts",
22
- "exports": {
23
- ".": {
24
- "import": "./src/index.ts",
25
- "types": "./src/index.ts"
26
- },
27
- "./mermaid": {
28
- "import": "./src/mermaid/index.ts",
29
- "types": "./src/mermaid/index.ts"
30
- },
31
- "./runtime": {
32
- "import": "./src/runtime/index.ts",
33
- "types": "./src/runtime/index.ts"
34
- },
35
- "./styles": {
36
- "import": "./src/styles/index.scss"
37
- },
38
- "./styles/*": "./src/styles/*",
39
- "./theme/*": "./src/theme/*",
40
- "./components/*": "./src/components/*",
41
- "./plugins": {
42
- "import": "./src/plugins/index.ts",
43
- "types": "./src/plugins/index.ts"
44
- },
45
- "./plugins/boot-chrome": {
46
- "import": "./src/plugins/boot-chrome.js",
47
- "types": "./src/plugins/boot-chrome.d.ts"
48
- },
49
- "./plugins/boot-recovery": {
50
- "import": "./src/plugins/boot-recovery.js",
51
- "types": "./src/plugins/boot-recovery.d.ts"
52
- },
53
- "./shared": {
54
- "import": "./src/shared.ts",
55
- "types": "./src/shared.ts"
56
- }
27
+ "./mermaid": {
28
+ "import": "./src/mermaid/index.ts",
29
+ "types": "./src/mermaid/index.ts"
57
30
  },
58
- "files": [
59
- "src/",
60
- "package.json"
61
- ],
62
- "scripts": {
63
- "dev": "vite",
64
- "build": "vue-tsc --noEmit",
65
- "build:docs": "vite build",
66
- "lint": "vue-tsc --noEmit",
67
- "test": "vitest run",
68
- "test:watch": "vitest",
69
- "gen:boot-landing-css": "node scripts/gen-boot-landing-css.js",
70
- "prepublishOnly": "vue-tsc --noEmit"
31
+ "./runtime": {
32
+ "import": "./src/runtime/index.ts",
33
+ "types": "./src/runtime/index.ts"
71
34
  },
72
- "peerDependencies": {
73
- "@types/three": "^0.185",
74
- "pinia": "^3",
75
- "three": "^0.185",
76
- "vue": "^3"
35
+ "./styles": {
36
+ "import": "./src/styles/index.scss"
77
37
  },
78
- "dependencies": {
79
- "@bytecodealliance/preview2-shim": "^0.31",
80
- "@celestia-island/tairitsu-transport": "^0.2",
81
- "@xterm/addon-fit": "^0.11",
82
- "@xterm/addon-image": "^0.10.0-beta.301",
83
- "@xterm/xterm": "^6.1.0-beta.304",
84
- "dompurify": "^3",
85
- "lucide-vue-next": "^1",
86
- "marked": "^18"
38
+ "./styles/*": "./src/styles/*",
39
+ "./theme/*": "./src/theme/*",
40
+ "./components/*": "./src/components/*",
41
+ "./plugins": {
42
+ "import": "./src/plugins/index.ts",
43
+ "types": "./src/plugins/index.ts"
87
44
  },
88
- "devDependencies": {
89
- "@types/node": "^*",
90
- "@types/three": "^0.185",
91
- "@vitejs/plugin-vue": "^*",
92
- "@vitejs/plugin-vue-jsx": "^*",
93
- "@vue/server-renderer": "^*",
94
- "happy-dom": "^*",
95
- "sass": "^*",
96
- "three": "^0.185",
97
- "typescript": "^*",
98
- "vite": "^*",
99
- "vitest": "^*",
100
- "vue-tsc": "^*"
45
+ "./plugins/boot-chrome": {
46
+ "import": "./src/plugins/boot-chrome.js",
47
+ "types": "./src/plugins/boot-chrome.d.ts"
101
48
  },
102
- "sideEffects": [
103
- "**/*.scss",
104
- "**/*.css"
105
- ],
106
- "peerDependenciesMeta": {
107
- "pinia": {
108
- "optional": true
109
- }
49
+ "./plugins/boot-recovery": {
50
+ "import": "./src/plugins/boot-recovery.js",
51
+ "types": "./src/plugins/boot-recovery.d.ts"
52
+ },
53
+ "./shared": {
54
+ "import": "./src/shared.ts",
55
+ "types": "./src/shared.ts"
56
+ }
57
+ },
58
+ "files": [
59
+ "src/",
60
+ "package.json"
61
+ ],
62
+ "scripts": {
63
+ "dev": "vite",
64
+ "build": "vue-tsc --noEmit",
65
+ "build:docs": "vite build",
66
+ "lint": "vue-tsc --noEmit",
67
+ "test": "vitest run",
68
+ "test:watch": "vitest",
69
+ "gen:boot-landing-css": "node scripts/gen-boot-landing-css.js",
70
+ "prepublishOnly": "vue-tsc --noEmit"
71
+ },
72
+ "peerDependencies": {
73
+ "@types/three": "^0.185",
74
+ "pinia": "^3",
75
+ "three": "^0.185",
76
+ "vue": "^3"
77
+ },
78
+ "dependencies": {
79
+ "@bytecodealliance/preview2-shim": "^0.31",
80
+ "@celestia-island/tairitsu-transport": "^0.2",
81
+ "@xterm/addon-fit": "^0.11",
82
+ "@xterm/addon-image": "^0.10.0-beta.301",
83
+ "@xterm/xterm": "^6.1.0-beta.304",
84
+ "dompurify": "^3",
85
+ "lucide-vue-next": "^1",
86
+ "marked": "^18"
87
+ },
88
+ "devDependencies": {
89
+ "@types/node": "^*",
90
+ "@types/three": "^0.185",
91
+ "@vitejs/plugin-vue": "^*",
92
+ "@vitejs/plugin-vue-jsx": "^*",
93
+ "@vue/server-renderer": "^*",
94
+ "happy-dom": "^*",
95
+ "sass": "^*",
96
+ "three": "^0.185",
97
+ "typescript": "^*",
98
+ "vite": "^*",
99
+ "vitest": "^*",
100
+ "vue-tsc": "^*"
101
+ },
102
+ "sideEffects": [
103
+ "**/*.scss",
104
+ "**/*.css"
105
+ ],
106
+ "peerDependenciesMeta": {
107
+ "pinia": {
108
+ "optional": true
110
109
  }
110
+ }
111
111
  }
@@ -136,6 +136,19 @@ describe("HkAboutModal branding", () => {
136
136
  expect(chips[0]!.getAttribute("href")).toBe("https://github.com/celestia-island");
137
137
  });
138
138
 
139
+ it("neutralizes a script scheme in the anchor itself (audit PS-18)", async () => {
140
+ mountAbout({
141
+ credits: [{ text: "来自 " }, { name: "恶意", href: "javascript:alert(1)" }],
142
+ });
143
+ await flushModal();
144
+ const anchor = document.body.querySelector<HTMLAnchorElement>(".s-about-modal-credit-link");
145
+ expect(anchor).not.toBeNull();
146
+ // The coordinator refuses script schemes on activation, but the ATTRIBUTE
147
+ // still has to be inert: a middle-click or "open link in new tab" bypasses
148
+ // the click handler entirely.
149
+ expect(anchor!.getAttribute("href")).toBe("#");
150
+ });
151
+
139
152
  it("renders a credit name as a plain text link when the entry asks for it", async () => {
140
153
  mountAbout({
141
154
  credits: [
@@ -4,6 +4,7 @@ import { HBadge, HModal } from "@celestia-island/hikari";
4
4
 
5
5
  import { useI18n } from "../i18n/context";
6
6
  import { openHyperlink } from "../runtime/hyperlink";
7
+ import { safeHref } from "../utils/safeHref";
7
8
 
8
9
  import "./HkAboutModal.scss";
9
10
 
@@ -175,7 +176,7 @@ export const HkAboutBody = defineComponent({
175
176
  key={key}
176
177
  class={classes}
177
178
  data-face={item.face ?? "chip"}
178
- href={item.href}
179
+ href={safeHref(item.href)}
179
180
  target="_blank"
180
181
  rel="noopener noreferrer"
181
182
  // The activation rides the hyperlink coordinator (runtime/
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
2
2
 
3
3
  import {
4
4
  classifyHyperlink,
5
+ isDangerousHref,
5
6
  openExternalHyperlink,
6
7
  openHyperlink,
7
8
  provideHyperlinkCoordinator,
@@ -229,3 +230,159 @@ describe("openExternalHyperlink floor", () => {
229
230
  expect(await openExternalHyperlink("https://example.com")).toBe(false);
230
231
  });
231
232
  });
233
+
234
+ /**
235
+ * SECURITY (audit PS-18, 2026-11-15): the `other` bucket must keep carrying
236
+ * custom protocols to the OS handler, so the fix is a scheme BLOCKLIST —
237
+ * never an allowlist like `safeHref` enforces for anchors. These pins hold
238
+ * both halves of that: script schemes must never reach a navigation sink,
239
+ * and a legitimate custom scheme must keep flowing.
240
+ */
241
+ describe("isDangerousHref", () => {
242
+ it("blocks the script and local-file schemes", () => {
243
+ expect(isDangerousHref("javascript:alert(1)")).toBe(true);
244
+ expect(isDangerousHref("JaVaScRiPt:alert(1)")).toBe(true);
245
+ expect(isDangerousHref(" javascript:alert(1)")).toBe(true);
246
+ expect(isDangerousHref("vbscript:msgbox(1)")).toBe(true);
247
+ expect(isDangerousHref("data:text/html,<script>alert(1)</script>")).toBe(true);
248
+ expect(isDangerousHref("file:///etc/passwd")).toBe(true);
249
+ // A page-minted blob is same-origin HTML: assigning location.href to it
250
+ // runs script here. `filesystem:` is the old Chrome spelling of the same.
251
+ expect(isDangerousHref("blob:https://app.example/uuid-1")).toBe(true);
252
+ expect(isDangerousHref("filesystem:https://app.example/temporary/x")).toBe(true);
253
+ });
254
+
255
+ it("sees through the control characters engines skip", () => {
256
+ // Browsers drop tab/LF/CR inside the scheme — `java\tscript:` still runs.
257
+ expect(isDangerousHref("java\tscript:alert(1)")).toBe(true);
258
+ expect(isDangerousHref("java\nscript:alert(1)")).toBe(true);
259
+ expect(isDangerousHref("j\u0000avascript:alert(1)")).toBe(true);
260
+ });
261
+
262
+ it("leaves every legitimate navigation form alone", () => {
263
+ expect(isDangerousHref("https://docs.celestia.world/x")).toBe(false);
264
+ expect(isDangerousHref("mailto:security@celestia.world")).toBe(false);
265
+ expect(isDangerousHref("tel:+8610000000000")).toBe(false);
266
+ expect(isDangerousHref("cla.md")).toBe(false);
267
+ expect(isDangerousHref("#section")).toBe(false);
268
+ // The whole point of `other`: custom protocols must keep working.
269
+ expect(isDangerousHref("vscode://file/x")).toBe(false);
270
+ expect(isDangerousHref("zoommtg://zoom.us/join?confno=1")).toBe(false);
271
+ expect(isDangerousHref("ftp://example.com/pub")).toBe(false);
272
+ });
273
+ });
274
+
275
+ describe("openHyperlink refuses script schemes (PS-18)", () => {
276
+ /**
277
+ * Capture `location.href` writes. Unlike a bare stub, this RETURNS a
278
+ * restore handle — `vi.restoreAllMocks()` cannot undo an
279
+ * `Object.defineProperty`, so every caller MUST run the returned
280
+ * `restore()` in a `finally` (a leaked proxy breaks any later test that
281
+ * touches `window.location`, with a misleading private-member error).
282
+ */
283
+ function stubLocation(): { writes: string[]; restore: () => void } {
284
+ const writes: string[] = [];
285
+ const original = window.location;
286
+ Object.defineProperty(window, "location", {
287
+ configurable: true,
288
+ writable: true,
289
+ value: new Proxy(original, {
290
+ set(_t, prop, value) {
291
+ if (prop === "href") writes.push(String(value));
292
+ return true;
293
+ },
294
+ }),
295
+ });
296
+ const restore = () => {
297
+ Object.defineProperty(window, "location", {
298
+ configurable: true,
299
+ writable: true,
300
+ value: original,
301
+ });
302
+ };
303
+ return { writes, restore };
304
+ }
305
+
306
+ it("never assigns location.href for a javascript: link", async () => {
307
+ const open = vi.fn();
308
+ vi.stubGlobal("open", open);
309
+ const { writes, restore } = stubLocation();
310
+ try {
311
+ expect(await openHyperlink("javascript:alert(1)")).toBeNull();
312
+ expect(writes).toEqual([]);
313
+ expect(open).not.toHaveBeenCalled();
314
+ } finally {
315
+ restore();
316
+ vi.unstubAllGlobals();
317
+ vi.restoreAllMocks();
318
+ }
319
+ });
320
+
321
+ it("refuses a dangerous URL the RESOLVER minted, not just the href", async () => {
322
+ const open = vi.fn();
323
+ vi.stubGlobal("open", open);
324
+ const { writes, restore } = stubLocation();
325
+ provideHyperlinkCoordinator({
326
+ resolve: () => "javascript:alert(1)",
327
+ });
328
+ try {
329
+ expect(await openHyperlink("https://docs.celestia.world/x")).toBeNull();
330
+ expect(writes).toEqual([]);
331
+ expect(open).not.toHaveBeenCalled();
332
+ } finally {
333
+ restore();
334
+ provideHyperlinkCoordinator(null);
335
+ vi.unstubAllGlobals();
336
+ vi.restoreAllMocks();
337
+ }
338
+ });
339
+
340
+ it("guards its own last-resort sink (openExternalHyperlink)", async () => {
341
+ // Publicly exported => a host may call it directly. A guard that lives
342
+ // only in the callers would leave this window.open reachable.
343
+ const open = vi.fn();
344
+ vi.stubGlobal("open", open);
345
+ try {
346
+ expect(await openExternalHyperlink("javascript:alert(1)")).toBe(false);
347
+ expect(open).not.toHaveBeenCalled();
348
+ } finally {
349
+ vi.unstubAllGlobals();
350
+ vi.restoreAllMocks();
351
+ }
352
+ });
353
+
354
+ it("never hands a dangerous URL to a host-provided open", async () => {
355
+ // Pins the guard at the ENTRY, not just the default opener. The inner
356
+ // default-opener guard is a redundant belt (mutation-tested: removing it
357
+ // alone stays green because the entry guard pre-empts it) — it exists for
358
+ // hosts that drive `useHyperlinkCoordinator().open()` directly.
359
+ const seen: string[] = [];
360
+ provideHyperlinkCoordinator({
361
+ open: (url) => {
362
+ seen.push(url);
363
+ return true;
364
+ },
365
+ });
366
+ try {
367
+ expect(await openHyperlink("javascript:alert(1)")).toBeNull();
368
+ expect(seen).toEqual([]);
369
+ } finally {
370
+ provideHyperlinkCoordinator(null);
371
+ }
372
+ });
373
+
374
+ it("still hands a custom scheme to the OS handler", async () => {
375
+ const open = vi.fn();
376
+ vi.stubGlobal("open", open);
377
+ const { writes, restore } = stubLocation();
378
+ try {
379
+ expect(await openHyperlink("vscode://file/x")).toBe("vscode://file/x");
380
+ expect(writes).toEqual(["vscode://file/x"]);
381
+ expect(open).not.toHaveBeenCalled();
382
+ } finally {
383
+ restore();
384
+ vi.unstubAllGlobals();
385
+ vi.restoreAllMocks();
386
+ }
387
+ });
388
+ });
@@ -86,6 +86,41 @@ export function classifyHyperlink(href: string): HyperlinkKind {
86
86
  return "other";
87
87
  }
88
88
 
89
+ /**
90
+ * Schemes that execute script (or re-enter the local filesystem) the moment
91
+ * a browser navigates to them. SECURITY (2026-11-15, audit PS-18): the
92
+ * `other` bucket exists so custom protocols (`vscode:`, `zoommtg:`, …) reach
93
+ * the OS handler — `safeHref`'s allowlist would kill every one of them, so
94
+ * this is deliberately a BLOCKLIST applied on top.
95
+ *
96
+ * Obfuscation: engines drop ASCII tab/LF/CR anywhere inside the scheme, so
97
+ * `java\tscript:` still runs. Matching therefore retries on a
98
+ * control-character-squeezed copy rather than trusting the raw prefix.
99
+ */
100
+ // `blob:` and `filesystem:` join the list because the web face of this
101
+ // module ASSIGNS `location.href` (navigating the app away) and a blob minted
102
+ // by the page is same-origin HTML — one click away from running script here.
103
+ // A legitimate download should carry `download`, not ride a hyperlink.
104
+ const DANGEROUS_SCHEME = /^(?:javascript|vbscript|data|file|blob|filesystem)$/;
105
+
106
+ function schemeOf(candidate: string): string | null {
107
+ const match = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(candidate.trim());
108
+ return match?.[1]?.toLowerCase() ?? null;
109
+ }
110
+
111
+ /** True when `href` would execute script (or reach local files) if a browser
112
+ * navigated to it. Never true for http(s)/mailto/tel/relative/fragment, and
113
+ * never true for a custom scheme such as `vscode:` — those stay in `other`
114
+ * and keep flowing to the OS handler. */
115
+ export function isDangerousHref(href: string): boolean {
116
+ if (typeof href !== "string") return false;
117
+ const direct = schemeOf(href);
118
+ if (direct !== null) return DANGEROUS_SCHEME.test(direct);
119
+ // No clean scheme at the front: re-test after removing what engines skip.
120
+ const squeezed = schemeOf(href.replace(/[\u0000-\u0020]/g, ""));
121
+ return squeezed !== null && DANGEROUS_SCHEME.test(squeezed);
122
+ }
123
+
89
124
  /** True when an absolute http(s) URL points at the CURRENT app origin.
90
125
  * Only used by the default native opener — a system browser must never
91
126
  * be pointed at the shell's own origin (a local server URL the user
@@ -114,6 +149,10 @@ interface TauriOpenerScope {
114
149
  * Returns false when every bridge refused (the caller may surface that;
115
150
  * the click still never navigates the webview). */
116
151
  export async function openExternalHyperlink(url: string): Promise<boolean> {
152
+ // SECURITY (PS-18 follow-up): this one is publicly exported, so a host may
153
+ // call it directly — a guard living only in its callers would leave the last
154
+ // `window.open` sink reachable. Cheap, so it guards itself.
155
+ if (isDangerousHref(url)) return false;
117
156
  if (typeof window === "undefined") return false;
118
157
  const scope = window as unknown as TauriOpenerScope;
119
158
 
@@ -179,6 +218,11 @@ export async function openExternalHyperlink(url: string): Promise<boolean> {
179
218
  * new tab resolved against the document base on the web. */
180
219
  async function defaultOpenHyperlink(url: string, info: HyperlinkInfo): Promise<boolean> {
181
220
  if (typeof window === "undefined") return false;
221
+ // SECURITY (PS-18): belt to openHyperlink's braces — this is the function
222
+ // that actually assigns `window.location.href` / calls `window.open`, so it
223
+ // must never be reachable with a script scheme even if a caller bypasses
224
+ // the entry (or a host wires this half in directly).
225
+ if (isDangerousHref(url)) return false;
182
226
 
183
227
  // The native shell must never hand its own origin to the system browser.
184
228
  if (isNative() && info.kind === "external" && isSameOriginUrl(url)) {
@@ -271,6 +315,11 @@ export async function openHyperlink(
271
315
 
272
316
  let url = await coordinator.resolve(info);
273
317
  if (typeof url !== "string" || url === "") return null;
318
+ // SECURITY (PS-18): the resolver may hand back anything — including a
319
+ // `javascript:` URL minted from the href it was given. Refuse here, at the
320
+ // ONE entry every component drives, so a future sink cannot forget the
321
+ // check. A host-supplied `open` never sees a dangerous URL at all.
322
+ if (isDangerousHref(url)) return null;
274
323
  if (url === info.href && info.kind === "internal") {
275
324
  // The resolver left a relative link untouched — give it its absolute
276
325
  // form so the opener decides on a real origin (native refuses it,