@celestia-island/hikari 0.55.381 → 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 +102 -102
- package/src/components/HkAboutModal.test.tsx +13 -0
- package/src/components/HkAboutModal.tsx +2 -1
- package/src/composables/useHighlight.languageForPath.test.ts +48 -0
- package/src/composables/useHighlight.ts +117 -3
- package/src/runtime/hyperlink.test.ts +157 -0
- package/src/runtime/hyperlink.ts +49 -0
- package/src/wasm/highlight/hikari_wasm_highlight.js +1 -1
package/package.json
CHANGED
|
@@ -1,111 +1,111 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
"
|
|
73
|
-
|
|
74
|
-
"pinia": "^3",
|
|
75
|
-
"three": "^0.185",
|
|
76
|
-
"vue": "^3"
|
|
35
|
+
"./styles": {
|
|
36
|
+
"import": "./src/styles/index.scss"
|
|
77
37
|
},
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
"
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
"
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
"
|
|
107
|
-
|
|
108
|
-
|
|
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/
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { languageForPath } from "./useHighlight";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The wasm-highlight rewrite (#1313) replaced languageForPath with a
|
|
7
|
+
* bare extension lookup and dropped PATH_FILENAME_LANG + EXT_TABLE —
|
|
8
|
+
* extensionless files triaged as a bogus basename language ("readme"),
|
|
9
|
+
* dotfiles/build files lost their mapping (chest FileBrowser preview
|
|
10
|
+
* caught it downstream, 0.55.381 pickup). These pins hold the restored
|
|
11
|
+
* surface: bare-name build files, dialect stems, dotfiles, and the
|
|
12
|
+
* extensionless → "" (plaintext) contract.
|
|
13
|
+
*/
|
|
14
|
+
describe("languageForPath", () => {
|
|
15
|
+
it("extensionless files are plaintext (no language)", () => {
|
|
16
|
+
expect(languageForPath("README")).toBe("");
|
|
17
|
+
expect(languageForPath("LICENSE")).toBe("");
|
|
18
|
+
expect(languageForPath("dir/notes")).toBe("");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("whole-filename build scripts keep their dialect", () => {
|
|
22
|
+
expect(languageForPath("Dockerfile")).toBe("dockerfile");
|
|
23
|
+
expect(languageForPath("dockerfile.prod")).toBe("dockerfile");
|
|
24
|
+
expect(languageForPath("Makefile")).toBe("makefile");
|
|
25
|
+
expect(languageForPath("Jenkinsfile")).toBe("groovy");
|
|
26
|
+
expect(languageForPath("CMakeLists.txt")).toBe("cmake");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("dotfiles map to ini/bash", () => {
|
|
30
|
+
expect(languageForPath(".env")).toBe("ini");
|
|
31
|
+
expect(languageForPath(".gitignore")).toBe("ini");
|
|
32
|
+
expect(languageForPath(".bashrc")).toBe("bash");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("extension mapping stays canonical", () => {
|
|
36
|
+
expect(languageForPath("main.rs")).toBe("rust");
|
|
37
|
+
expect(languageForPath("app.tsx")).toBe("typescript");
|
|
38
|
+
expect(languageForPath("notes.txt")).toBe("plaintext");
|
|
39
|
+
expect(languageForPath("run.log")).toBe("plaintext");
|
|
40
|
+
expect(languageForPath("spec/api.yaml")).toBe("yaml");
|
|
41
|
+
expect(languageForPath("page.vue")).toBe("xml");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("the basename is lowercased before any lookup", () => {
|
|
45
|
+
expect(languageForPath("DOCKERFILE")).toBe("dockerfile");
|
|
46
|
+
expect(languageForPath("README.MD")).toBe("markdown");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -81,12 +81,126 @@ export function highlight(code: string, lang?: string): string {
|
|
|
81
81
|
return escapeHtml(code);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
/**
|
|
84
|
+
/** Whole filenames (lowercased) that carry no useful extension, or whose
|
|
85
|
+
* dialect is decided by the name: `Dockerfile.dev`, `CMakeLists.txt`. */
|
|
86
|
+
const PATH_FILENAME_LANG: Record<string, string> = {
|
|
87
|
+
dockerfile: "dockerfile",
|
|
88
|
+
makefile: "makefile",
|
|
89
|
+
gnumakefile: "makefile",
|
|
90
|
+
"cmakelists.txt": "cmake",
|
|
91
|
+
jenkinsfile: "groovy",
|
|
92
|
+
nginx: "nginx",
|
|
93
|
+
"cargo.lock": "toml",
|
|
94
|
+
".env": "ini",
|
|
95
|
+
".gitignore": "ini",
|
|
96
|
+
".gitattributes": "ini",
|
|
97
|
+
".gitmodules": "ini",
|
|
98
|
+
".editorconfig": "ini",
|
|
99
|
+
".bashrc": "bash",
|
|
100
|
+
".zshrc": "bash",
|
|
101
|
+
".profile": "bash",
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** Extension (lowercased) → canonical highlight.js language id. Only ids
|
|
105
|
+
* that exist in LANGUAGE_LOADERS: anything else would render plaintext
|
|
106
|
+
* anyway, just with a misleading promise attached. */
|
|
107
|
+
const EXT_TABLE: Record<string, string> = {
|
|
108
|
+
rs: "rust",
|
|
109
|
+
ts: "typescript", tsx: "typescript", mts: "typescript", cts: "typescript",
|
|
110
|
+
js: "javascript", jsx: "javascript", mjs: "javascript", cjs: "javascript",
|
|
111
|
+
json: "json", jsonc: "json",
|
|
112
|
+
py: "python", pyi: "python", pyw: "python",
|
|
113
|
+
rb: "ruby",
|
|
114
|
+
go: "go",
|
|
115
|
+
java: "java",
|
|
116
|
+
kt: "kotlin", kts: "kotlin",
|
|
117
|
+
scala: "scala", sc: "scala",
|
|
118
|
+
groovy: "groovy", gradle: "groovy",
|
|
119
|
+
c: "c", h: "c",
|
|
120
|
+
cpp: "cpp", cc: "cpp", cxx: "cpp", hpp: "cpp", hh: "cpp", hxx: "cpp",
|
|
121
|
+
cs: "csharp",
|
|
122
|
+
fs: "fsharp", fsx: "fsharp",
|
|
123
|
+
php: "php",
|
|
124
|
+
swift: "swift",
|
|
125
|
+
m: "objectivec", mm: "objectivec",
|
|
126
|
+
dart: "dart",
|
|
127
|
+
ex: "elixir", exs: "elixir",
|
|
128
|
+
erl: "erlang", hrl: "erlang",
|
|
129
|
+
hs: "haskell", lhs: "haskell",
|
|
130
|
+
elm: "elm",
|
|
131
|
+
lua: "lua",
|
|
132
|
+
pl: "perl", pm: "perl",
|
|
133
|
+
r: "r",
|
|
134
|
+
jl: "julia",
|
|
135
|
+
nim: "nim",
|
|
136
|
+
cr: "crystal",
|
|
137
|
+
ml: "ocaml", mli: "ocaml", mll: "ocaml", mly: "ocaml",
|
|
138
|
+
vb: "vbnet",
|
|
139
|
+
pas: "delphi", dpr: "delphi",
|
|
140
|
+
bas: "basic",
|
|
141
|
+
f: "fortran", f90: "fortran", f95: "fortran", f03: "fortran", for: "fortran",
|
|
142
|
+
coffee: "coffeescript",
|
|
143
|
+
ls: "livescript",
|
|
144
|
+
clj: "clojure", cljs: "clojure", cljc: "clojure", edn: "clojure",
|
|
145
|
+
scm: "scheme", ss: "scheme", el: "lisp", lisp: "lisp",
|
|
146
|
+
xml: "xml", html: "xml", htm: "xml", svg: "xml", vue: "xml", xhtml: "xml",
|
|
147
|
+
cshtml: "xml", jsp: "xml", erb: "erb", ejs: "xml",
|
|
148
|
+
hbs: "handlebars", handlebars: "handlebars",
|
|
149
|
+
twig: "twig",
|
|
150
|
+
haml: "haml",
|
|
151
|
+
dust: "dust",
|
|
152
|
+
css: "css", scss: "scss", less: "less",
|
|
153
|
+
yml: "yaml", yaml: "yaml",
|
|
154
|
+
toml: "toml",
|
|
155
|
+
ini: "ini", cfg: "ini", conf: "ini", properties: "properties", env: "ini",
|
|
156
|
+
md: "markdown", markdown: "markdown",
|
|
157
|
+
graphql: "graphql", gql: "graphql",
|
|
158
|
+
http: "http",
|
|
159
|
+
sh: "bash", bash: "bash", zsh: "bash", shell: "bash", fish: "bash",
|
|
160
|
+
ps1: "powershell", psm1: "powershell",
|
|
161
|
+
bat: "dos", cmd: "dos",
|
|
162
|
+
mk: "makefile",
|
|
163
|
+
cmake: "cmake",
|
|
164
|
+
dockerfile: "dockerfile",
|
|
165
|
+
nginx: "nginx",
|
|
166
|
+
awk: "awk",
|
|
167
|
+
tcl: "tcl",
|
|
168
|
+
vim: "vim",
|
|
169
|
+
sql: "sql", psql: "pgsql",
|
|
170
|
+
proto: "protobuf",
|
|
171
|
+
thrift: "thrift",
|
|
172
|
+
glsl: "glsl", vert: "glsl", frag: "glsl", geom: "glsl",
|
|
173
|
+
wasm: "wasm",
|
|
174
|
+
asm: "x86asm",
|
|
175
|
+
v: "verilog", sv: "verilog",
|
|
176
|
+
vhd: "vhdl", vhdl: "vhdl",
|
|
177
|
+
tex: "latex", sty: "latex",
|
|
178
|
+
diff: "diff", patch: "diff",
|
|
179
|
+
txt: "plaintext", text: "plaintext", log: "plaintext",
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* A file path → the canonical highlight.js language id for it, or "" when
|
|
184
|
+
* nothing sensible is known (callers pass "" as "no language" and the
|
|
185
|
+
* block renders plaintext or auto-detects). One mapping for every code
|
|
186
|
+
* surface — diff panes, file browsers, markdown fences — so the same
|
|
187
|
+
* path always highlights the same way; aliases are resolved by
|
|
188
|
+
* `normalize()` at highlight time, so the table lists canonical ids.
|
|
189
|
+
*/
|
|
85
190
|
export function languageForPath(path: string): string {
|
|
86
|
-
const
|
|
87
|
-
|
|
191
|
+
const name = path.split("/").pop()?.trim().toLowerCase() ?? "";
|
|
192
|
+
if (!name) return "";
|
|
193
|
+
// Extensionless build scripts: `Dockerfile`, `Jenkinsfile`, `Makefile`.
|
|
194
|
+
const bare = PATH_FILENAME_LANG[name];
|
|
195
|
+
if (bare) return bare;
|
|
196
|
+
// `Dockerfile.dev` / `dockerfile.prod` — the dialect IS the stem.
|
|
197
|
+
if (name.startsWith("dockerfile")) return "dockerfile";
|
|
198
|
+
if (name.startsWith("makefile")) return "makefile";
|
|
199
|
+
const ext = name.includes(".") ? name.split(".").pop()! : "";
|
|
200
|
+
return EXT_TABLE[ext] ?? "";
|
|
88
201
|
}
|
|
89
202
|
|
|
203
|
+
|
|
90
204
|
export function useHighlight() {
|
|
91
205
|
return { highlight, version };
|
|
92
206
|
}
|
|
@@ -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
|
+
});
|
package/src/runtime/hyperlink.ts
CHANGED
|
@@ -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,
|