@iasiv5/dsh-skip-browser-auth 0.3.11 → 0.3.12
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/lib/gate.js +21 -16
- package/lib/host.js +26 -4
- package/package.json +1 -1
package/lib/gate.js
CHANGED
|
@@ -113,25 +113,30 @@ export function evaluateGate(ctx) {
|
|
|
113
113
|
return new Function('ctx', 'expr', 'with (ctx) { return eval(expr) }')(ctx, GATE_PROBE_EXPRESSION);
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
116
|
-
* Node 侧宿主形态检测(apply backstop
|
|
117
|
-
*
|
|
118
|
-
* {url: string}(抛错/空值/url
|
|
119
|
-
* process.argv 含 `dsh-desktop-host`(与官方 isPackagedDesktopArgv
|
|
120
|
-
*
|
|
121
|
-
*
|
|
116
|
+
* Node 侧宿主形态检测(apply backstop 镜像 + apply 前置判别共用):与
|
|
117
|
+
* GATE_PROFILE_EXPRESSION 内联检测同语义,desktop 信号取或——① desktop 信号包自
|
|
118
|
+
* baseUrl 解析出合法 {url: string}(抛错/空值/url 非字符串视为不可达,继续②);
|
|
119
|
+
* ② 宿主进程 process.argv 含 `dsh-desktop-host`(与官方 isPackagedDesktopArgv
|
|
120
|
+
* 同款)。两信号皆否 ⇒ 'web'(fail-closed 兜底是后续版本对判定)。
|
|
121
|
+
* resolver 允许为 undefined(0.3.12 起 apply 在 presence 检查之前先调用本函数做
|
|
122
|
+
* 前置判别):信号① 对 undefined 的访问在自身 try/catch 内消化,其余信号不依赖
|
|
123
|
+
* resolver——undefined 一律按「信号①不可达」处理,语义不变。
|
|
122
124
|
*/
|
|
123
125
|
export function detectHostProfile(internal, baseUrl) {
|
|
124
126
|
const specifier = `${DESKTOP_HOST_PACKAGE}/package.json`;
|
|
125
|
-
try
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
127
|
+
// resolver 缺省 ⇒ 信号①按「不可达」处理(与原 try/catch 消化 TypeError 等价)。
|
|
128
|
+
if (internal !== undefined) {
|
|
129
|
+
try {
|
|
130
|
+
const resolved = internal.version === 'v2'
|
|
131
|
+
? internal.resolveSync(baseUrl, { specifier, attributes: {} })
|
|
132
|
+
: internal.resolveSync(specifier, baseUrl, {});
|
|
133
|
+
const url = resolved?.url;
|
|
134
|
+
if (typeof url === 'string')
|
|
135
|
+
return 'desktop';
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// 信号包不可达/解析异常 ⇒ 落到宿主进程 argv 判别
|
|
139
|
+
}
|
|
135
140
|
}
|
|
136
141
|
let slot = '';
|
|
137
142
|
try {
|
package/lib/host.js
CHANGED
|
@@ -24,6 +24,8 @@ export const name = '@iasiv5/dsh-skip-browser-auth';
|
|
|
24
24
|
export const inject = ['webServer'];
|
|
25
25
|
/** 启动警告固定文案(全局约束:Replacement 激活时逐字输出)。 */
|
|
26
26
|
const SKIP_WARNING = '@iasiv5/dsh-skip-browser-auth: BrowserAuth has been skipped. DSH Web is using the trusted-network behavior; this plugin does not verify any upstream proxy.';
|
|
27
|
+
/** desktop 休眠通知固定文案(0.3.12 起 apply 前置判别休眠时逐字输出;可 grep)。 */
|
|
28
|
+
const DESKTOP_DORMANT_NOTICE = '@iasiv5/dsh-skip-browser-auth: desktop host detected — dormant by design (web-only plugin); official connection untouched. Safe to uninstall.';
|
|
27
29
|
/** Headroom for RPC JSON fields around aggregate base64 image payloads. */
|
|
28
30
|
const REQUEST_ENVELOPE_HEADROOM_BYTES = 1024 * 1024;
|
|
29
31
|
const PROFILE_GLOBAL = '__DSH_SKIP_BROWSER_AUTH_PROFILE__';
|
|
@@ -46,8 +48,9 @@ function profileById(value) {
|
|
|
46
48
|
}
|
|
47
49
|
/**
|
|
48
50
|
* direct(无 loader/fiber entry)上下文的 profile 兜底:仅纯单测/dev 树可达。
|
|
49
|
-
* 宿主形态按 'web' 处理(dev 树即 web)——
|
|
50
|
-
*
|
|
51
|
+
* 宿主形态按 'web' 处理(dev 树即 web)——apply 的前置宿主判别(0.3.12)凭
|
|
52
|
+
* 槽位/argv/execPath 信号即可判 desktop,真 desktop 上必然先静默休眠,不会走到
|
|
53
|
+
* 这里;resolver 缺失不影响该判别(信号①自行消化 undefined)。
|
|
51
54
|
*/
|
|
52
55
|
function directProfile(requestedProfile) {
|
|
53
56
|
if (requestedProfile !== undefined) {
|
|
@@ -70,6 +73,11 @@ function directProfile(requestedProfile) {
|
|
|
70
73
|
* 产品组合中 loader / internal / current 任一缺失都意味着最后防线无法执行,
|
|
71
74
|
* 必须在创建 Connection 服务与注册 /api 之前 fail loud。没有 loader 与 entry
|
|
72
75
|
* 的直接单元测试上下文才跳过本 backstop。
|
|
76
|
+
*
|
|
77
|
+
* 0.3.12 起 desktop 分支由 apply 的前置宿主判别承接(静默休眠,见 apply),
|
|
78
|
+
* 本函数内的 desktop throw 正常不可达,保留为纵深防御(防未来调用路径回退);
|
|
79
|
+
* 本 backstop 实际只在 web 路径运行,四类契约破坏(锚点解析失败、版本对不在
|
|
80
|
+
* 白名单、profile mismatch、binding violated)照旧 fail loud。
|
|
73
81
|
*/
|
|
74
82
|
function assertGateBackstop(ctx, requestedProfile) {
|
|
75
83
|
const loader = ctx.get('loader');
|
|
@@ -88,8 +96,9 @@ function assertGateBackstop(ctx, requestedProfile) {
|
|
|
88
96
|
const baseUrl = ctx.baseUrl ?? '';
|
|
89
97
|
const internal = loader.internal;
|
|
90
98
|
// 宿主 profile 镜像检测(2026-10-07 web-only 门控,纵深防御层):desktop 信号在
|
|
91
|
-
// 场 ⇒ fail loud
|
|
92
|
-
//
|
|
99
|
+
// 场 ⇒ fail loud。0.3.12 起 apply 的前置判别已在 desktop 上静默休眠返回,此分支
|
|
100
|
+
// 正常不可达,保留为纵深防御(防未来重排序/调用路径回退)。语义与
|
|
101
|
+
// detectHostProfile/表达式层一致(docs/COMPATIBILITY.md §7/§7.8)。
|
|
93
102
|
const hostProfile = detectHostProfile(internal, baseUrl);
|
|
94
103
|
if (hostProfile === 'desktop') {
|
|
95
104
|
throw new Error(`@iasiv5/dsh-skip-browser-auth: desktop profile not supported; disable or uninstall the plugin (${DESKTOP_HOST_PACKAGE} present)`);
|
|
@@ -163,6 +172,19 @@ function createHostRuntime(profile, input) {
|
|
|
163
172
|
* identity layer exists beyond it.
|
|
164
173
|
*/
|
|
165
174
|
export async function apply(ctx, config) {
|
|
175
|
+
// 宿主形态判别最前置(0.3.12,运行时权威休眠):desktop ⇒ 静默休眠,无条件
|
|
176
|
+
// 先于一切配置校验与副作用。背景:用户层 patch 可按行 id 合法覆盖本插件
|
|
177
|
+
// patch 的 !!js disabled 表达式(dsh-m 插件开关 / `dsh plugin add` enable
|
|
178
|
+
// 通道的标准产物,2026-10-11 实录),组合期门控因此不承担语义;apply 内判定
|
|
179
|
+
// 是唯一权威。§7.4 教训(任何半区的 throw 都可能炸宿主):休眠路径零 throw、
|
|
180
|
+
// 零副作用,仅留一行可 grep 的通知;「激活需要正向 web 证明」的 default-deny
|
|
181
|
+
// 语义不变。resolver 缺失不阻碍判别(信号①自行消化 undefined)。
|
|
182
|
+
const earlyLoader = ctx.get('loader');
|
|
183
|
+
const earlyBaseUrl = ctx.baseUrl ?? '';
|
|
184
|
+
if (detectHostProfile(earlyLoader?.internal, earlyBaseUrl) === 'desktop') {
|
|
185
|
+
console.warn(DESKTOP_DORMANT_NOTICE);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
166
188
|
const trustedHosts = config?.trustedHosts ?? [];
|
|
167
189
|
const maxRequestBodyBytes = config?.maxRequestBodyBytes ?? DEFAULT_MAX_REQUEST_BODY_BYTES;
|
|
168
190
|
for (const entry of trustedHosts)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iasiv5/dsh-skip-browser-auth",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.12",
|
|
4
4
|
"description": "替换官方 Connection 提供方跳过 BrowserAuth,免输 Token;已适配 0.1.2-rc.1、0.1.5-rc.1/rc.2、0.1.7-rc.1/rc.2 与 0.2.0-rc.1/rc.2,详见仓库。仅支持 web(宿主二进制须为 node);desktop 宿主一律自动休眠(多进程树判别:安装槽位/启动器 argv/宿主二进制),属设计行为。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|