@glazeen/mod-sdk 0.1.0 → 0.2.0
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/dist/cli.js +20 -3
- package/dist/index.js +18 -1
- package/docs/api.md +10 -1
- package/docs/manifest.md +11 -0
- package/docs/runtime.md +13 -7
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -16,6 +16,19 @@ function formatIssue(issue) {
|
|
|
16
16
|
return issue.path ? `${issue.path}: ${issue.message}` : issue.message;
|
|
17
17
|
}
|
|
18
18
|
const PERMISSION_PATTERN = /^(system|open-url|net:(\*\.)?[a-z0-9-]+(\.[a-z0-9-]+)*)$/i;
|
|
19
|
+
/**
|
|
20
|
+
* Hosts bearbar refuses whatever the manifest says (it checks the same at runtime): IP addresses,
|
|
21
|
+
* localhost and other names that only mean something on this PC or the LAN, and wildcards over a
|
|
22
|
+
* whole top-level domain.
|
|
23
|
+
*/
|
|
24
|
+
function netHostProblem(pattern) {
|
|
25
|
+
const wild = pattern.startsWith("*.");
|
|
26
|
+
const host = (wild ? pattern.slice(2) : pattern).toLowerCase();
|
|
27
|
+
if (/^[\d.]+$/.test(host)) return "IP addresses are not allowed, use a host name";
|
|
28
|
+
if (/(^|\.)(localhost|local|internal|home\.arpa)$/.test(host)) return "local network names are not allowed";
|
|
29
|
+
if (!host.includes(".")) return wild ? "a wildcard must cover a domain, not a top-level domain" : "use a full host name";
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
19
32
|
const SEMVER = /^\d+\.\d+\.\d+(-[0-9a-z.-]+)?(\+[0-9a-z.-]+)?$/i;
|
|
20
33
|
const MANIFEST_KEYS = [
|
|
21
34
|
"$schema",
|
|
@@ -131,7 +144,11 @@ function validateManifest(input) {
|
|
|
131
144
|
m.permissions.forEach((p, i) => {
|
|
132
145
|
if (typeof p !== "string" || !PERMISSION_PATTERN.test(p)) error(`permissions[${i}]`, `unknown permission ${json(p)} (use "net:<host>", "system" or "open-url")`);
|
|
133
146
|
else if (seen.has(p.toLowerCase())) error(`permissions[${i}]`, `duplicate ${json(p)}`);
|
|
134
|
-
else
|
|
147
|
+
else {
|
|
148
|
+
seen.add(p.toLowerCase());
|
|
149
|
+
const problem = p.toLowerCase().startsWith("net:") ? netHostProblem(p.slice(4)) : null;
|
|
150
|
+
if (problem) error(`permissions[${i}]`, `${json(p)}: ${problem}`);
|
|
151
|
+
}
|
|
135
152
|
});
|
|
136
153
|
}
|
|
137
154
|
}
|
|
@@ -230,7 +247,7 @@ function distance(a, b) {
|
|
|
230
247
|
*/
|
|
231
248
|
const MANIFEST = "bearbar.mod.json";
|
|
232
249
|
const SCHEMA_URL = "https://unpkg.com/@glazeen/mod-sdk/schema/bearbar.mod.schema.json";
|
|
233
|
-
const HELP = `bearbar-mod 0.
|
|
250
|
+
const HELP = `bearbar-mod 0.2.0: tools for bearbar dock mods
|
|
234
251
|
|
|
235
252
|
Usage:
|
|
236
253
|
bearbar-mod validate [dir...] Check mods: a mod folder, or a folder of mods (default ".")
|
|
@@ -268,7 +285,7 @@ function main(argv) {
|
|
|
268
285
|
}
|
|
269
286
|
});
|
|
270
287
|
const [command, ...rest] = positionals;
|
|
271
|
-
if (values.version) return print("0.
|
|
288
|
+
if (values.version) return print("0.2.0");
|
|
272
289
|
if (values.help || !command) return print(HELP);
|
|
273
290
|
if (command === "validate") return validate(rest.length ? rest : ["."], values);
|
|
274
291
|
if (command === "init") return init(rest[0] ?? ".", values.name);
|
package/dist/index.js
CHANGED
|
@@ -59,6 +59,19 @@ function formatIssue(issue) {
|
|
|
59
59
|
return issue.path ? `${issue.path}: ${issue.message}` : issue.message;
|
|
60
60
|
}
|
|
61
61
|
const PERMISSION_PATTERN = /^(system|open-url|net:(\*\.)?[a-z0-9-]+(\.[a-z0-9-]+)*)$/i;
|
|
62
|
+
/**
|
|
63
|
+
* Hosts bearbar refuses whatever the manifest says (it checks the same at runtime): IP addresses,
|
|
64
|
+
* localhost and other names that only mean something on this PC or the LAN, and wildcards over a
|
|
65
|
+
* whole top-level domain.
|
|
66
|
+
*/
|
|
67
|
+
function netHostProblem(pattern) {
|
|
68
|
+
const wild = pattern.startsWith("*.");
|
|
69
|
+
const host = (wild ? pattern.slice(2) : pattern).toLowerCase();
|
|
70
|
+
if (/^[\d.]+$/.test(host)) return "IP addresses are not allowed, use a host name";
|
|
71
|
+
if (/(^|\.)(localhost|local|internal|home\.arpa)$/.test(host)) return "local network names are not allowed";
|
|
72
|
+
if (!host.includes(".")) return wild ? "a wildcard must cover a domain, not a top-level domain" : "use a full host name";
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
62
75
|
const SEMVER = /^\d+\.\d+\.\d+(-[0-9a-z.-]+)?(\+[0-9a-z.-]+)?$/i;
|
|
63
76
|
const MANIFEST_KEYS = [
|
|
64
77
|
"$schema",
|
|
@@ -174,7 +187,11 @@ function validateManifest(input) {
|
|
|
174
187
|
m.permissions.forEach((p, i) => {
|
|
175
188
|
if (typeof p !== "string" || !PERMISSION_PATTERN.test(p)) error(`permissions[${i}]`, `unknown permission ${json(p)} (use "net:<host>", "system" or "open-url")`);
|
|
176
189
|
else if (seen.has(p.toLowerCase())) error(`permissions[${i}]`, `duplicate ${json(p)}`);
|
|
177
|
-
else
|
|
190
|
+
else {
|
|
191
|
+
seen.add(p.toLowerCase());
|
|
192
|
+
const problem = p.toLowerCase().startsWith("net:") ? netHostProblem(p.slice(4)) : null;
|
|
193
|
+
if (problem) error(`permissions[${i}]`, `${json(p)}: ${problem}`);
|
|
194
|
+
}
|
|
178
195
|
});
|
|
179
196
|
}
|
|
180
197
|
}
|
package/docs/api.md
CHANGED
|
@@ -151,12 +151,20 @@ if (res.ok) {
|
|
|
151
151
|
|
|
152
152
|
- the host isn't declared (`permission "net:<host>" not declared`),
|
|
153
153
|
- the URL isn't https or isn't valid,
|
|
154
|
+
- the host is an IP address, `localhost` or another local name (`host <name> is not allowed`),
|
|
155
|
+
- a redirect leads somewhere the first URL couldn't go: plain http, a host the mod didn't
|
|
156
|
+
declare, a local name (`redirect refused: ...`), or there are more than 5 redirects
|
|
157
|
+
(`too many redirects`),
|
|
154
158
|
- the request fails or takes longer than 15 seconds (`timed out`),
|
|
155
159
|
- the response is larger than 2 MB (`response too large`),
|
|
156
160
|
- the page is a preview (`no network in preview`).
|
|
157
161
|
|
|
158
162
|
An HTTP error status (404, 500) resolves with that `status`, `ok: false` and the body.
|
|
159
163
|
|
|
164
|
+
**Redirects** are followed only when the target passes the same checks as the first URL, so a
|
|
165
|
+
mod with `net:api.example.com` can't be redirected to another host, to the local network or to
|
|
166
|
+
http.
|
|
167
|
+
|
|
160
168
|
**Limits.** Requests carry no cookies or credentials. Response headers aren't exposed. Bodies
|
|
161
169
|
are text only: binary responses (images, archives) aren't supported, so images from the web
|
|
162
170
|
can't be shown.
|
|
@@ -202,7 +210,8 @@ Escape and clicking outside the panel also close it.
|
|
|
202
210
|
|
|
203
211
|
Opens an `http:` or `https:` link in the user's default browser. Needs the `open-url`
|
|
204
212
|
permission, or it rejects. Other schemes are ignored. Mod pages can't navigate or open windows
|
|
205
|
-
themselves, so links (`<a href>`) must go through this.
|
|
213
|
+
themselves, so links (`<a href>`) must go through this. Call it from a click: the dock opens at
|
|
214
|
+
most one link every 2 seconds and 5 a minute per mod, and quietly drops the rest.
|
|
206
215
|
|
|
207
216
|
```js
|
|
208
217
|
link.addEventListener("click", (e) => {
|
package/docs/manifest.md
CHANGED
|
@@ -102,11 +102,22 @@ must exist, or the tile shows an error.
|
|
|
102
102
|
|
|
103
103
|
- Hosts are matched case-insensitively and without a port or path: `net:api.example.com`, not
|
|
104
104
|
`net:https://api.example.com/v1`.
|
|
105
|
+
- Only public host names: IP addresses (`net:127.0.0.1`), `localhost`, single-label names
|
|
106
|
+
(`net:intranet`) and `.local` / `.internal` / `.home.arpa` names are an error, and the dock
|
|
107
|
+
refuses them at runtime too. A wildcard must cover a domain: `net:*.example.com`, not
|
|
108
|
+
`net:*.com`.
|
|
105
109
|
- Duplicates are an error. Unknown permissions are an error for the validator; the dock ignores
|
|
106
110
|
them.
|
|
107
111
|
- Without a permission, the matching call fails: `bb.fetch` resolves with `ok: false`, the
|
|
108
112
|
others reject.
|
|
109
113
|
|
|
114
|
+
A manifest only asks for permissions. A mod the user installed needs the user's approval, in
|
|
115
|
+
Settings › Mods, before its permissions apply. Until every permission it declares is approved
|
|
116
|
+
the mod is blocked: the dock shows a placeholder instead of its tile and grants it nothing. A
|
|
117
|
+
mod that declares no permissions needs no approval. If an update asks for more than was
|
|
118
|
+
approved, the mod is blocked again until the user approves the new list; asking for less needs
|
|
119
|
+
nothing. Mods bundled with bearbar don't need approval.
|
|
120
|
+
|
|
110
121
|
There is no permission for file system, clipboard, notifications or other native access.
|
|
111
122
|
|
|
112
123
|
### settings
|
package/docs/runtime.md
CHANGED
|
@@ -68,16 +68,22 @@ dock to open the widget menu (Settings, Size, Remove) instead.
|
|
|
68
68
|
|
|
69
69
|
All mods share the `bbmod://mods` origin for serving, so however many mods are on the dock they
|
|
70
70
|
cost one extra renderer process together, not one each. Isolation between them comes from the
|
|
71
|
-
sandbox, not from separate origins.
|
|
71
|
+
sandbox, not from separate origins. A mod's frame can only show pages from its own folder:
|
|
72
|
+
the dock refuses to navigate it to another mod or to the web.
|
|
72
73
|
|
|
73
74
|
## Permission checks
|
|
74
75
|
|
|
75
|
-
Permissions are checked by the dock, outside the page, against the manifest on disk
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
Permissions are checked by the dock, outside the page, against the manifest on disk and what
|
|
77
|
+
the user approved of it (a user mod waiting for approval gets none; see
|
|
78
|
+
[permissions](manifest.md#permissions)):
|
|
79
|
+
|
|
80
|
+
- `bb.fetch` runs in the main process. It requires `https:`, refuses IP addresses and local
|
|
81
|
+
names (`localhost`, `.local`...), matches the URL's host against the `net:` permissions,
|
|
82
|
+
sends no cookies or credentials, times out after 15 seconds and stops reading a response
|
|
83
|
+
past 2 MB. Each redirect is checked the same way before it is followed, up to 5.
|
|
84
|
+
- `bb.openUrl` checks `open-url`, only opens `http:` and `https:` URLs, and opens at most one
|
|
85
|
+
link every 2 seconds (5 a minute) per mod.
|
|
86
|
+
- `bb.storage` is saved by the dock, which refuses a store over `STORAGE_QUOTA` as well.
|
|
81
87
|
- The `system` subscription checks `system`.
|
|
82
88
|
|
|
83
89
|
The runtime in the page is a convenience: bypassing it gains nothing, since every privileged
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glazeen/mod-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Types, manifest schema, validator and CLI for bearbar dock mods, plus the bb runtime the dock injects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bearbar",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"sdk",
|
|
13
13
|
"windows"
|
|
14
14
|
],
|
|
15
|
-
"homepage": "https://github.com/
|
|
16
|
-
"bugs": "https://github.com/
|
|
15
|
+
"homepage": "https://github.com/Glazeen/bearbar/tree/main/packages/mod-sdk#readme",
|
|
16
|
+
"bugs": "https://github.com/Glazeen/bearbar/issues",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/
|
|
20
|
+
"url": "git+https://github.com/Glazeen/bearbar.git",
|
|
21
21
|
"directory": "packages/mod-sdk"
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|