@gruu6y/page-clean-login 0.2.3 → 0.2.5
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/README.en.md +1 -0
- package/README.md +1 -0
- package/lib/browser-launcher.mjs +61 -5
- package/lib/magpie-plugins.mjs +64 -4
- package/lib/native-signin.mjs +14 -3
- package/lib/provider-sources.mjs +27 -10
- package/lib/server.mjs +6 -5
- package/lib/signin-flow.mjs +32 -4
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -284,6 +284,7 @@ Run `bun bin/clean-login.mjs help` for the full command list. A remote service (
|
|
|
284
284
|
- No telemetry and no account. The only network calls are the ones you start: proxy tests, the trust-score page, the identity-check page, the runtime download, and the provider's own sign-in.
|
|
285
285
|
- Proxies, accounts, fingerprints and browser profiles live in `~/.config/magpie/magpie-clean-login/` (override with `MAGPIE_CLEAN_LOGIN_DATA`; the config root itself with `MAGPIE_CONFIG_DIR`). The market catalog is read from `~/.cache/magpie/` (`MAGPIE_CACHE_DIR`). Hosted-renewal switches and recent records live in `renew-hosting.json` in that same directory; it holds switches, times and outcomes, never a credential.
|
|
286
286
|
- The login browser unpacks to `%LOCALAPPDATA%/magpie-clean-login/camoufox` on Windows, `~/Library/Caches/magpie-clean-login/camoufox` on macOS, and `$XDG_CACHE_HOME/magpie-clean-login/camoufox` on Linux (all overridable with `MAGPIE_CLEAN_LOGIN_BROWSER_DIR`).
|
|
287
|
+
- On Linux without `DISPLAY` or `WAYLAND_DISPLAY`, opt into an X11 display (such as `:99`) with `MAGPIE_CLEAN_LOGIN_DISPLAY`; to opt into the system fontconfig instead of Camoufox's stock anti-fingerprinting config, set `MAGPIE_CLEAN_LOGIN_FONTCONFIG=system` (`/etc/fonts/fonts.conf`) or a custom `fonts.conf` path (an existing `FONTCONFIG_FILE` is never overridden).
|
|
287
288
|
- Stored proxy passwords never reach the page and are never logged. The page token is per-process and exists only in the page the service serves.
|
|
288
289
|
|
|
289
290
|
<a id="contributing"></a>
|
package/README.md
CHANGED
|
@@ -289,6 +289,7 @@ bun bin/clean-login.mjs score cancel # 停掉信任度评分
|
|
|
289
289
|
- 没有遥测,也没有账号。唯一的网络调用就是你自己发起的那些:代理测试、信任分页面、身份检测页面、运行时下载,以及供应商自己的登录。
|
|
290
290
|
- 代理、账号、指纹和浏览器配置都在 `~/.config/magpie/magpie-clean-login/`(用 `MAGPIE_CLEAN_LOGIN_DATA` 覆盖;配置根本身用 `MAGPIE_CONFIG_DIR`)。市场目录从 `~/.cache/magpie/` 读取(`MAGPIE_CACHE_DIR`)。续期托管的开通状态与最近记录在同一个目录下的 `renew-hosting.json`,里面只有开关、时间和结果,没有任何凭据。
|
|
291
291
|
- 登录浏览器在 Windows 上解包到 `%LOCALAPPDATA%/magpie-clean-login/camoufox`,在 macOS 上解包到 `~/Library/Caches/magpie-clean-login/camoufox`,在 Linux 上解包到 `$XDG_CACHE_HOME/magpie-clean-login/camoufox`(均可用 `MAGPIE_CLEAN_LOGIN_BROWSER_DIR` 覆盖)。
|
|
292
|
+
- 在无界面的 Linux 上,若未设置 `DISPLAY` 和 `WAYLAND_DISPLAY` 且需要把登录浏览器指向指定 X11 显示(如 `:99`),可用 `MAGPIE_CLEAN_LOGIN_DISPLAY` 显式开启;若需改用系统字体配置而非 Camoufox 默认的防指纹字体配置,可设置 `MAGPIE_CLEAN_LOGIN_FONTCONFIG=system`(`/etc/fonts/fonts.conf`)或自定义的 `fonts.conf` 路径(不会覆盖已有的 `FONTCONFIG_FILE`)。
|
|
292
293
|
- 存下来的代理密码不会到达页面,也不会写进日志。页面 token 每进程一份,只存在于服务送出的页面里。
|
|
293
294
|
|
|
294
295
|
<a id="contributing"></a>
|
package/lib/browser-launcher.mjs
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
// browser does not add per-launch canvas noise on top of the pinned identity.
|
|
21
21
|
|
|
22
22
|
import { fork } from "node:child_process";
|
|
23
|
+
import { existsSync } from "node:fs";
|
|
23
24
|
import { mkdir, stat } from "node:fs/promises";
|
|
24
25
|
import { fileURLToPath } from "node:url";
|
|
25
26
|
import { BROWSER_DIR_ENV, browserEnvironmentRoot, fingerprintModelDir } from "./browser-environment.mjs";
|
|
@@ -55,6 +56,10 @@ export function navigationWarning(error) {
|
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
export const DISPLAY_ENV = "MAGPIE_CLEAN_LOGIN_DISPLAY";
|
|
60
|
+
export const FONTCONFIG_ENV = "MAGPIE_CLEAN_LOGIN_FONTCONFIG";
|
|
61
|
+
export const SYSTEM_FONTCONFIG_PATH = "/etc/fonts/fonts.conf";
|
|
62
|
+
|
|
58
63
|
// The env the forked browser hosts run under. FPGEN_DATA_DIR is the name
|
|
59
64
|
// fpgen-js actually reads (only a fallback — the host also calls setModelDir
|
|
60
65
|
// from its launch input). camoufoxCacheEnv repeats the import-time cache
|
|
@@ -63,9 +68,40 @@ export function navigationWarning(error) {
|
|
|
63
68
|
// fontconfig's escape the sandbox. Because those overrides would also move
|
|
64
69
|
// browserEnvironmentRoot() inside the host, BROWSER_DIR_ENV is pinned so the
|
|
65
70
|
// host still finds the same sandbox root the parent computed.
|
|
66
|
-
|
|
71
|
+
//
|
|
72
|
+
// On Linux, DISPLAY and FONTCONFIG_FILE are explicit opt-ins via DISPLAY_ENV
|
|
73
|
+
// and FONTCONFIG_ENV: we never silently probe /tmp/.X11-unix/X99 or replace
|
|
74
|
+
// Camoufox's stock anti-fingerprinting fontconfig by default, and we never
|
|
75
|
+
// override an existing DISPLAY, WAYLAND_DISPLAY, or FONTCONFIG_FILE.
|
|
76
|
+
export function hostEnv(
|
|
77
|
+
env,
|
|
78
|
+
sandboxRoot,
|
|
79
|
+
modelDir,
|
|
80
|
+
platform = process.platform,
|
|
81
|
+
{ existsSync: exists = existsSync } = {},
|
|
82
|
+
) {
|
|
83
|
+
const baseEnv = env ?? {};
|
|
84
|
+
let display = {};
|
|
85
|
+
let fontEnv = {};
|
|
86
|
+
if (platform === "linux") {
|
|
87
|
+
if (!baseEnv.DISPLAY && !baseEnv.WAYLAND_DISPLAY) {
|
|
88
|
+
const requestedDisplay =
|
|
89
|
+
typeof baseEnv[DISPLAY_ENV] === "string" ? baseEnv[DISPLAY_ENV].trim() : "";
|
|
90
|
+
if (requestedDisplay) display = { DISPLAY: requestedDisplay };
|
|
91
|
+
}
|
|
92
|
+
if (!baseEnv.FONTCONFIG_FILE) {
|
|
93
|
+
const fc =
|
|
94
|
+
typeof baseEnv[FONTCONFIG_ENV] === "string" ? baseEnv[FONTCONFIG_ENV].trim() : "";
|
|
95
|
+
if (fc && fc.toLowerCase() !== "off") {
|
|
96
|
+
const candidate = fc.toLowerCase() === "system" ? SYSTEM_FONTCONFIG_PATH : fc;
|
|
97
|
+
if (exists(candidate)) fontEnv = { FONTCONFIG_FILE: candidate };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
67
101
|
return {
|
|
68
|
-
...
|
|
102
|
+
...baseEnv,
|
|
103
|
+
...display,
|
|
104
|
+
...fontEnv,
|
|
69
105
|
...camoufoxCacheEnv(sandboxRoot, platform),
|
|
70
106
|
[BROWSER_DIR_ENV]: sandboxRoot,
|
|
71
107
|
FPGEN_DATA_DIR: modelDir,
|
|
@@ -331,6 +367,7 @@ export async function launchSignInBrowser({
|
|
|
331
367
|
// pinned fingerprint and the same exit, but no window on the desktop.
|
|
332
368
|
headless = false,
|
|
333
369
|
env = process.env,
|
|
370
|
+
platform = process.platform,
|
|
334
371
|
deps = {},
|
|
335
372
|
} = {}) {
|
|
336
373
|
if (typeof url !== "string" || !url) {
|
|
@@ -364,7 +401,13 @@ export async function launchSignInBrowser({
|
|
|
364
401
|
child = spawnHost(deps.hostPath ?? HOST_PATH, [], {
|
|
365
402
|
stdio: ["pipe", "ignore", "pipe", "ipc"],
|
|
366
403
|
windowsHide: false,
|
|
367
|
-
env: hostEnv(
|
|
404
|
+
env: hostEnv(
|
|
405
|
+
env,
|
|
406
|
+
browserEnvironmentRoot(env),
|
|
407
|
+
resolvedModelDir,
|
|
408
|
+
platform,
|
|
409
|
+
deps.existsSync ? { existsSync: deps.existsSync } : undefined,
|
|
410
|
+
),
|
|
368
411
|
});
|
|
369
412
|
} catch (error) {
|
|
370
413
|
throw new SignInBrowserError(
|
|
@@ -555,7 +598,13 @@ export async function launchScoreBrowser({
|
|
|
555
598
|
child = spawnHost(deps.hostPath ?? SCORE_HOST_PATH, [], {
|
|
556
599
|
stdio: ["pipe", "ignore", "pipe", "ipc"],
|
|
557
600
|
windowsHide: false,
|
|
558
|
-
env: hostEnv(
|
|
601
|
+
env: hostEnv(
|
|
602
|
+
env,
|
|
603
|
+
browserEnvironmentRoot(env),
|
|
604
|
+
resolvedModelDir,
|
|
605
|
+
platform,
|
|
606
|
+
deps.existsSync ? { existsSync: deps.existsSync } : undefined,
|
|
607
|
+
),
|
|
559
608
|
});
|
|
560
609
|
} catch (error) {
|
|
561
610
|
throw new ScoreBrowserError(
|
|
@@ -719,6 +768,7 @@ export async function launchIdentityCheckBrowser({
|
|
|
719
768
|
timeoutMs,
|
|
720
769
|
launchTimeoutMs = 60_000,
|
|
721
770
|
env = process.env,
|
|
771
|
+
platform = process.platform,
|
|
722
772
|
deps = {},
|
|
723
773
|
} = {}) {
|
|
724
774
|
if (typeof url !== "string" || !url) {
|
|
@@ -752,7 +802,13 @@ export async function launchIdentityCheckBrowser({
|
|
|
752
802
|
child = spawnHost(deps.hostPath ?? IDENTITY_HOST_PATH, [], {
|
|
753
803
|
stdio: ["pipe", "ignore", "pipe", "ipc"],
|
|
754
804
|
windowsHide: false,
|
|
755
|
-
env: hostEnv(
|
|
805
|
+
env: hostEnv(
|
|
806
|
+
env,
|
|
807
|
+
browserEnvironmentRoot(env),
|
|
808
|
+
resolvedModelDir,
|
|
809
|
+
platform,
|
|
810
|
+
deps.existsSync ? { existsSync: deps.existsSync } : undefined,
|
|
811
|
+
),
|
|
756
812
|
});
|
|
757
813
|
} catch (error) {
|
|
758
814
|
throw new SignInBrowserError(
|
package/lib/magpie-plugins.mjs
CHANGED
|
@@ -210,6 +210,31 @@ function normalizeMethod(method) {
|
|
|
210
210
|
return classifyMethod(method);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
const PLUGIN_DIR_FORBIDDEN = /[\u0000-\u001f\u007f:]/;
|
|
214
|
+
|
|
215
|
+
// Validates and normalizes a scanned plugin's relative directory under
|
|
216
|
+
// `node_modules` into a bounded POSIX path, rejecting traversals, absolute
|
|
217
|
+
// paths, drive prefixes, control chars, and nested dependency subpaths.
|
|
218
|
+
export function normalizePluginDir(value) {
|
|
219
|
+
if (typeof value !== "string" || !value || value.length > 256) return null;
|
|
220
|
+
if (PLUGIN_DIR_FORBIDDEN.test(value)) return null;
|
|
221
|
+
const posix = value.replaceAll("\\", "/");
|
|
222
|
+
if (posix.startsWith("/") || posix.endsWith("/")) return null;
|
|
223
|
+
const segments = posix.split("/");
|
|
224
|
+
if (segments.some((segment) => !segment || segment === "." || segment === "..")) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
if (segments.length === 1) {
|
|
228
|
+
return segments[0].startsWith("@") || segments[0].startsWith(".") ? null : posix;
|
|
229
|
+
}
|
|
230
|
+
if (segments.length === 2) {
|
|
231
|
+
return segments[0].startsWith("@") && segments[0].length > 1 && !segments[1].startsWith(".")
|
|
232
|
+
? posix
|
|
233
|
+
: null;
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
|
|
213
238
|
// Accepts anything and returns the public-safe scan shape. Never throws and
|
|
214
239
|
// never carries a function or an unbounded field into the API response.
|
|
215
240
|
export function normalizeScan(raw) {
|
|
@@ -236,6 +261,7 @@ export function normalizeScan(raw) {
|
|
|
236
261
|
// the same registry file also holds.
|
|
237
262
|
api: typeof entry.api === "string" && entry.api.trim() ? entry.api.trim().slice(0, 512) : "",
|
|
238
263
|
package: typeof entry.package === "string" && entry.package ? entry.package : null,
|
|
264
|
+
dir: normalizePluginDir(entry.dir),
|
|
239
265
|
methods,
|
|
240
266
|
});
|
|
241
267
|
}
|
|
@@ -257,7 +283,7 @@ export function pluginRootDir(env = process.env) {
|
|
|
257
283
|
// line is parsed back.
|
|
258
284
|
const CHILD_SOURCE = String.raw`
|
|
259
285
|
import { readdirSync, readFileSync, existsSync } from "node:fs";
|
|
260
|
-
import { basename, join } from "node:path";
|
|
286
|
+
import { basename, join, relative, sep } from "node:path";
|
|
261
287
|
import { pathToFileURL } from "node:url";
|
|
262
288
|
|
|
263
289
|
const root = process.env.CLEAN_LOGIN_PLUGIN_ROOT || "";
|
|
@@ -269,6 +295,20 @@ const client = {
|
|
|
269
295
|
};
|
|
270
296
|
const providers = [];
|
|
271
297
|
|
|
298
|
+
// Direct dependencies declared in plugins/package.json help identify custom-named
|
|
299
|
+
// unscoped provider plugins without importing every transitive dependency.
|
|
300
|
+
const directDeps = new Set();
|
|
301
|
+
try {
|
|
302
|
+
const pluginPkgFile = join(root, "..", "package.json");
|
|
303
|
+
if (existsSync(pluginPkgFile)) {
|
|
304
|
+
const pluginPkg = JSON.parse(readFileSync(pluginPkgFile, "utf8"));
|
|
305
|
+
for (const section of [pluginPkg?.dependencies, pluginPkg?.optionalDependencies]) {
|
|
306
|
+
if (!section || typeof section !== "object" || Array.isArray(section)) continue;
|
|
307
|
+
for (const depName of Object.keys(section)) directDeps.add(depName);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
} catch {}
|
|
311
|
+
|
|
272
312
|
// Display names live in magpie's own plugin registry, one level above the
|
|
273
313
|
// packages: plugins/node_modules -> magpie/plugin-providers.json. Only id,
|
|
274
314
|
// name and the declared API base are read: that file also carries accounts and
|
|
@@ -299,15 +339,22 @@ function emit(payload) {
|
|
|
299
339
|
return new Promise((resolve) => process.stdout.write(text, () => resolve()));
|
|
300
340
|
}
|
|
301
341
|
|
|
342
|
+
const isDirLike = (entry) => entry.isDirectory() || entry.isSymbolicLink();
|
|
343
|
+
|
|
302
344
|
try {
|
|
303
345
|
const scopes = existsSync(root) ? readdirSync(root, { withFileTypes: true }) : [];
|
|
304
346
|
const dirs = [];
|
|
305
347
|
for (const scope of scopes) {
|
|
306
|
-
if (!scope.
|
|
348
|
+
if (!isDirLike(scope) || scope.name.startsWith(".")) continue;
|
|
349
|
+
if (!scope.name.startsWith("@")) {
|
|
350
|
+
const pkgDir = join(root, scope.name);
|
|
351
|
+
if (existsSync(join(pkgDir, "package.json"))) dirs.push(pkgDir);
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
307
354
|
const scopeDir = join(root, scope.name);
|
|
308
355
|
const entries = existsSync(scopeDir) ? readdirSync(scopeDir, { withFileTypes: true }) : [];
|
|
309
356
|
for (const dirent of entries) {
|
|
310
|
-
if (dirent.
|
|
357
|
+
if (isDirLike(dirent) && !dirent.name.startsWith(".")) dirs.push(join(scopeDir, dirent.name));
|
|
311
358
|
}
|
|
312
359
|
}
|
|
313
360
|
for (const dir of dirs) {
|
|
@@ -321,12 +368,24 @@ try {
|
|
|
321
368
|
if (!existsSync(pkgFile)) continue;
|
|
322
369
|
let pkg = null;
|
|
323
370
|
try { pkg = JSON.parse(readFileSync(pkgFile, "utf8")); } catch { continue; }
|
|
371
|
+
if (pkg?.magpie?.page) continue;
|
|
324
372
|
// A manifest without a name is legal (a bundled browser build ships one),
|
|
325
373
|
// so fall back to the directory name. Do NOT reach for dirent here: it
|
|
326
374
|
// only exists inside the scope loop above, and reading it threw a
|
|
327
375
|
// ReferenceError that took the whole scan down.
|
|
328
376
|
const packageName =
|
|
329
377
|
typeof pkg?.name === "string" && pkg.name ? pkg.name : basename(dir);
|
|
378
|
+
const relDir = relative(root, dir).split(sep).join("/");
|
|
379
|
+
if (
|
|
380
|
+
!relDir.startsWith("@") &&
|
|
381
|
+
!packageName.startsWith("@") &&
|
|
382
|
+
!directDeps.has(relDir) &&
|
|
383
|
+
!Boolean(pkg?.magpie) &&
|
|
384
|
+
!/^(?:opencode|magpie)-/.test(packageName) &&
|
|
385
|
+
!/^(?:opencode|magpie)-/.test(relDir)
|
|
386
|
+
) {
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
330
389
|
const entry = typeof pkg?.main === "string" && pkg.main ? pkg.main : "index.mjs";
|
|
331
390
|
const mainFile = join(dir, entry);
|
|
332
391
|
if (!existsSync(mainFile)) continue;
|
|
@@ -366,6 +425,7 @@ try {
|
|
|
366
425
|
// means this provider cannot be a probe target.
|
|
367
426
|
api: apis.get(auth.provider) || "",
|
|
368
427
|
package: packageName,
|
|
428
|
+
dir: relDir,
|
|
369
429
|
methods: list.map((method) => ({
|
|
370
430
|
type: typeof method?.type === "string" ? method.type : "",
|
|
371
431
|
label: typeof method?.label === "string" ? method.label : "",
|
|
@@ -419,7 +479,7 @@ export async function scanMagpiePlugins({
|
|
|
419
479
|
env = process.env,
|
|
420
480
|
execFile: execFileImpl = execFile,
|
|
421
481
|
execPath = process.execPath,
|
|
422
|
-
timeoutMs =
|
|
482
|
+
timeoutMs = 30_000,
|
|
423
483
|
} = {}) {
|
|
424
484
|
const root = pluginRootDir(env);
|
|
425
485
|
try {
|
package/lib/native-signin.mjs
CHANGED
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
// user pastes when the callback cannot reach this machine.
|
|
19
19
|
|
|
20
20
|
import { spawn as spawnChild } from "node:child_process";
|
|
21
|
+
import { isAllowedSignInUrl } from "./open-external.mjs";
|
|
22
|
+
|
|
23
|
+
export { isAllowedSignInUrl as isSignInUrl };
|
|
21
24
|
|
|
22
25
|
export const NATIVE_SIGNIN_STATES = Object.freeze([
|
|
23
26
|
"starting",
|
|
@@ -35,13 +38,15 @@ const TERMINAL = new Set(["done", "error", "cancelled"]);
|
|
|
35
38
|
// parsers below never depend on that.
|
|
36
39
|
const ANSI = /\u001b\[[0-9;]*[A-Za-z]/g;
|
|
37
40
|
|
|
38
|
-
const URL_LINE = /https?:\/\/[^\s"'<>]
|
|
41
|
+
const URL_LINE = /https?:\/\/[^\s"'<>]+/g;
|
|
39
42
|
const CODE_LINE = /\bconfirm the code\s+([A-Z0-9][A-Z0-9-]{2,})\b/i;
|
|
40
43
|
const RISK_PROMPT = /sign in anyway\?\s*\[y\/N\]/i;
|
|
41
44
|
const PASTE_CODE = /paste the code the page shows here/i;
|
|
42
45
|
const PASTE_CALLBACK = /paste its whole address here/i;
|
|
43
46
|
const PASTE_ANY = /paste (?:its whole address|the code)/i;
|
|
44
47
|
const INSTALLING = /^installing /i;
|
|
48
|
+
const UNSUPPORTED_ACCOUNT = /only .* can be added and switched/i;
|
|
49
|
+
const PROXY_ENV_LINE = /^\s*(?:https?|all)_proxy\s*=/i;
|
|
45
50
|
const TIMED_OUT = /timed out|didn't finish/i;
|
|
46
51
|
|
|
47
52
|
export class NativeSignInError extends Error {
|
|
@@ -81,9 +86,15 @@ export function readNativeLine(raw) {
|
|
|
81
86
|
if (PASTE_CALLBACK.test(line)) return { kind: "paste", what: "callback" };
|
|
82
87
|
if (PASTE_ANY.test(line)) return { kind: "paste", what: "callback" };
|
|
83
88
|
if (INSTALLING.test(line.trim())) return { kind: "installing", text: line.trim() };
|
|
89
|
+
if (UNSUPPORTED_ACCOUNT.test(line)) return { kind: "failed", text: line.trim() };
|
|
84
90
|
const code = line.match(CODE_LINE);
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
if (!PROXY_ENV_LINE.test(line)) {
|
|
92
|
+
for (const m of line.matchAll(URL_LINE)) {
|
|
93
|
+
if (isAllowedSignInUrl(m[0])) {
|
|
94
|
+
return { kind: "url", url: m[0], code: code ? code[1] : "" };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
87
98
|
if (code) return { kind: "code", code: code[1] };
|
|
88
99
|
if (TIMED_OUT.test(line)) return { kind: "failed", text: line.trim() };
|
|
89
100
|
return null;
|
package/lib/provider-sources.mjs
CHANGED
|
@@ -260,6 +260,19 @@ function slug(value) {
|
|
|
260
260
|
.replace(/^-+|-+$/g, "");
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
// Built-in agents supported by `magpie accounts add <agent>`. Any other id is
|
|
264
|
+
// rejected by magpie's CLI ("only ... can be added and switched"), so custom
|
|
265
|
+
// providers without a plugin must not be given a dead native door.
|
|
266
|
+
export const NATIVE_ACCOUNT_AGENTS = Object.freeze(
|
|
267
|
+
new Set(["claude", "codex", "copilot", "gemini", "antigravity", "zed", "factory", "mimo"]),
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
/** Return the canonical built-in native account agent id, or null if unsupported. */
|
|
271
|
+
export function nativeAgentId(value) {
|
|
272
|
+
const id = slug(value);
|
|
273
|
+
return NATIVE_ACCOUNT_AGENTS.has(id) ? id : null;
|
|
274
|
+
}
|
|
275
|
+
|
|
263
276
|
function itemFromEntry(entry) {
|
|
264
277
|
if (typeof entry === "string") {
|
|
265
278
|
const id = slug(entry);
|
|
@@ -383,13 +396,13 @@ function magpieOnlyProvider(item, pluginItem, scanFailure) {
|
|
|
383
396
|
...flags,
|
|
384
397
|
signInProvider: pluginItem ? pluginItem.id : null,
|
|
385
398
|
pluginPackage: pluginItem ? pluginItem.package : null,
|
|
386
|
-
// magpie signs
|
|
387
|
-
//
|
|
388
|
-
//
|
|
389
|
-
//
|
|
390
|
-
//
|
|
391
|
-
// sign-in.
|
|
392
|
-
nativeSignIn: !pluginItem,
|
|
399
|
+
// magpie signs only its built-in account agents in itself (`magpie accounts
|
|
400
|
+
// add <agent>`). Custom/non-built-in magpie providers without an installed
|
|
401
|
+
// plugin cannot be added that way and must not get a dead native door.
|
|
402
|
+
// Built-ins still defer to an installed plugin when one exists, so a plugin
|
|
403
|
+
// that offers only a key or a local session is not quietly turned into a
|
|
404
|
+
// browser sign-in.
|
|
405
|
+
nativeSignIn: !pluginItem && Boolean(nativeAgentId(item.id)),
|
|
393
406
|
};
|
|
394
407
|
}
|
|
395
408
|
|
|
@@ -649,9 +662,13 @@ export function mergeProviderSources({ local = [], magpie, plugins, catalog } =
|
|
|
649
662
|
// the registry's own `browser-oauth` entries keep their entry instead of
|
|
650
663
|
// losing the only door they have (the plugin layer below is not gated on
|
|
651
664
|
// that read either, for the same reason). A list that WAS read keeps the
|
|
652
|
-
// final say: not in it means no native door. A token-import provider
|
|
653
|
-
// not a browser door,
|
|
654
|
-
nativeSignIn:
|
|
665
|
+
// final say: not in it means no native door. A token-import provider or
|
|
666
|
+
// non-built-in agent is not a native browser door, even when magpie lists it.
|
|
667
|
+
nativeSignIn:
|
|
668
|
+
!pluginItem &&
|
|
669
|
+
provider.signInMode === "browser-oauth" &&
|
|
670
|
+
Boolean(nativeAgentId(provider.agentId || provider.id)) &&
|
|
671
|
+
(inMagpie || !available),
|
|
655
672
|
});
|
|
656
673
|
}
|
|
657
674
|
|
package/lib/server.mjs
CHANGED
|
@@ -941,13 +941,14 @@ export async function startServer({
|
|
|
941
941
|
// request blocks until the download job settles, so a caller that just
|
|
942
942
|
// started a prepare makes one request instead of one per poll. A request
|
|
943
943
|
// with no wait reads once and returns immediately.
|
|
944
|
-
// The environment routes answer {environment, job},
|
|
945
|
-
// status carries absolute paths (executablePath, installDir, modelDir)
|
|
946
|
-
//
|
|
947
|
-
//
|
|
944
|
+
// The environment routes answer {environment, job}, and the manager's
|
|
945
|
+
// status carries absolute paths (executablePath, installDir, modelDir).
|
|
946
|
+
// `installDir` stays so the UI can show where the sandboxed browser lives
|
|
947
|
+
// instead of falling back to "Unknown"; `executablePath` and `modelDir` stay
|
|
948
|
+
// stripped so internal launch details are never published.
|
|
948
949
|
function publicEnvironmentStatus(status) {
|
|
949
950
|
if (!status || typeof status !== "object") return status;
|
|
950
|
-
const { executablePath,
|
|
951
|
+
const { executablePath, modelDir, ...rest } = status;
|
|
951
952
|
return rest;
|
|
952
953
|
}
|
|
953
954
|
|
package/lib/signin-flow.mjs
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import { randomUUID } from "node:crypto";
|
|
19
19
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
20
|
-
import { join } from "node:path";
|
|
20
|
+
import { isAbsolute, join, relative } from "node:path";
|
|
21
21
|
import { pathToFileURL } from "node:url";
|
|
22
22
|
import { readAuthKeys } from "./account-keys.mjs";
|
|
23
23
|
import { readAuthEntries, signInKey, writeBack } from "./signin-writeback.mjs";
|
|
@@ -248,15 +248,43 @@ export async function defaultLoadProvider({ provider, env = process.env, client,
|
|
|
248
248
|
let scan = pluginScanner?.get ? pluginScanner.get() : null;
|
|
249
249
|
if (!scan?.available && pluginScanner?.refresh) scan = await pluginScanner.refresh();
|
|
250
250
|
const entry = scan?.providers?.find?.((item) => item?.id === provider);
|
|
251
|
-
|
|
251
|
+
const rawPath = typeof entry?.dir === "string" && entry.dir ? entry.dir : entry?.package;
|
|
252
|
+
if (!entry || typeof rawPath !== "string" || !rawPath) {
|
|
252
253
|
throw new SignInFlowError(
|
|
253
254
|
"plugin_missing",
|
|
254
255
|
`No installed provider plugin provides "${provider}".`,
|
|
255
256
|
404,
|
|
256
257
|
);
|
|
257
258
|
}
|
|
259
|
+
if (
|
|
260
|
+
rawPath.startsWith("/") ||
|
|
261
|
+
rawPath.startsWith("\\") ||
|
|
262
|
+
/[\u0000-\u001f\u007f:]/.test(rawPath)
|
|
263
|
+
) {
|
|
264
|
+
throw new SignInFlowError(
|
|
265
|
+
"plugin_load_failed",
|
|
266
|
+
`Invalid plugin directory for "${provider}".`,
|
|
267
|
+
502,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
const segments = rawPath.split(/[/\\]+/).filter(Boolean);
|
|
271
|
+
if (!segments.length || segments.some((segment) => segment === "." || segment === "..")) {
|
|
272
|
+
throw new SignInFlowError(
|
|
273
|
+
"plugin_load_failed",
|
|
274
|
+
`Invalid plugin directory for "${provider}".`,
|
|
275
|
+
502,
|
|
276
|
+
);
|
|
277
|
+
}
|
|
258
278
|
const root = pluginRootDir(env);
|
|
259
|
-
const dir = join(root, ...
|
|
279
|
+
const dir = join(root, ...segments);
|
|
280
|
+
const rel = relative(root, dir);
|
|
281
|
+
if (!rel || rel.startsWith("..") || isAbsolute(rel)) {
|
|
282
|
+
throw new SignInFlowError(
|
|
283
|
+
"plugin_load_failed",
|
|
284
|
+
`Invalid plugin directory for "${provider}".`,
|
|
285
|
+
502,
|
|
286
|
+
);
|
|
287
|
+
}
|
|
260
288
|
let mod;
|
|
261
289
|
try {
|
|
262
290
|
mod = await import(pathToFileURL(await readPluginEntry(dir)).href);
|
|
@@ -302,7 +330,7 @@ export async function defaultLoadProvider({ provider, env = process.env, client,
|
|
|
302
330
|
}
|
|
303
331
|
const auth = hooks?.auth;
|
|
304
332
|
if (auth && auth.provider === provider && Array.isArray(auth.methods)) {
|
|
305
|
-
return { methods: auth.methods, package: entry.package };
|
|
333
|
+
return { methods: auth.methods, package: entry.package || entry.dir };
|
|
306
334
|
}
|
|
307
335
|
}
|
|
308
336
|
throw new SignInFlowError(
|