dsh-cookie-cleaner 0.6.4 → 0.7.2
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/CHANGELOG.md +270 -242
- package/LICENSE +21 -21
- package/README.md +432 -432
- package/cordis.patch.yml +5 -5
- package/dsh.plugin.json +1 -1
- package/lib/client.js +336 -8
- package/lib/client.js.map +1 -1
- package/package.json +1 -1
- package/scripts/gen-locales.mjs +82 -82
- package/scripts/hosts.mjs +57 -57
- package/scripts/sync-hosts.mjs +80 -80
- package/src/api-routes.js +144 -138
- package/src/cli.js +281 -236
- package/src/client/card.tsx +315 -253
- package/src/client/index.ts +129 -129
- package/src/client/locales.ts +91 -84
- package/src/client/routes.ts +138 -118
- package/src/client/star-row-copy.ts +256 -0
- package/src/core.js +669 -531
- package/src/i18n.js +140 -140
- package/src/index.js +426 -394
- package/src/jar-live.js +365 -365
- package/src/legacy-injection.js +137 -0
- package/src/locales-advise-owner.js +39 -39
- package/src/locales-dict.js +220 -220
- package/src/locales-dict2.js +214 -214
- package/src/locales-patch.js +207 -207
- package/src/patch-guard.js +509 -416
- package/src/patch-model.js +271 -271
- package/src/patch-read.js +251 -199
- package/src/report.js +243 -243
- package/src/runtime-guard.js +14 -4
- package/src/settings-waist.js +37 -37
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-cookie-cleaner — 历史注入残留的识别与清理(纯函数面,可单测)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要这个模块:
|
|
5
|
+
* 0.2.1 之前,本插件曾在面板/命令面上提供过「应用端口」动作,把 `webserver` 行的
|
|
6
|
+
* `port` 改写成表达式 `ctx.webStartup.port ?? +<用户填的数>`(见 556e37b 及更早)。
|
|
7
|
+
* 2026-11-05 的裁决把端口写入能力整体删除(端口属启动行为面,不在本工具职责内),
|
|
8
|
+
* 但**已经写进用户 profile 的那一行不会自己消失**——它留在 `cordis.patch.yml` 里继续生效。
|
|
9
|
+
*
|
|
10
|
+
* 这一行的危害不是"插件又写端口了",而是:
|
|
11
|
+
* 1. 用户以为本工具已经不碰端口,实际 profile 里还钉着当年填的数;
|
|
12
|
+
* 2. 该表达式与 bundle 层原值可能已经不同(用户后来改过启动参数/升级过宿主),
|
|
13
|
+
* 表现为「启动层没传 --port 时落在旧数字上」这种难以归因的行为;
|
|
14
|
+
* 3. 卸载插件后残留仍在,用户找不到是谁写的。
|
|
15
|
+
*
|
|
16
|
+
* 清理原则(为什么只在 0.2.2-rc.2+ 执行):
|
|
17
|
+
* - 0.2.2-rc.2 起桌面外壳自带 `removeLegacyHostCookies`,cookie 侧的历史包袱由官方接管,
|
|
18
|
+
* 插件不再需要用"钉端口"这条侧路去压 cookie 增长;此时回收旧注入是纯收益。
|
|
19
|
+
* - 更早的宿主上,钉端口仍是上游 discussions 给的可选缓解之一,贸然回收可能让用户
|
|
20
|
+
* 重新落回"每次启动随机端口 → cookie 累积"的老路,所以那一段只**报告不清理**。
|
|
21
|
+
*
|
|
22
|
+
* 安全边界(这条最重要):**只删本插件自己写过的那一种形态**。
|
|
23
|
+
* 判定必须同时满足:值是指向 `webStartup.port` 的 `!!js` 表达式。用户自己手写的
|
|
24
|
+
* 字面量端口(P8 报的那类)、用户自己写的别的表达式,一律不碰——"看到但不替你改"。
|
|
25
|
+
*/
|
|
26
|
+
import { isExpression } from './patch-model.js'
|
|
27
|
+
|
|
28
|
+
/** 本插件历史版本写过的端口表达式形态:`ctx.webStartup.port ?? <fallback>`。 */
|
|
29
|
+
const LEGACY_PORT_EXPRESSION = /^\s*ctx\.webStartup\.port\s*\?\?\s*(\+?\s*\d+)\s*$/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 判断一个 `!!js` 表达式值是否为本插件历史注入的端口表达式。
|
|
33
|
+
* @param {unknown} value 运行态配置里的值(表达式已被内核转成 `{__jsExpr}`)
|
|
34
|
+
* @returns {{ legacy: boolean, fallback?: number, expression?: string }}
|
|
35
|
+
*/
|
|
36
|
+
export function classifyLegacyPort(value) {
|
|
37
|
+
if (!isExpression(value)) return { legacy: false }
|
|
38
|
+
const expression = value.__jsExpr
|
|
39
|
+
const hit = LEGACY_PORT_EXPRESSION.exec(expression)
|
|
40
|
+
if (hit === null) return { legacy: false, expression }
|
|
41
|
+
const fallback = Number(hit[1].replace(/[+\s]/g, ''))
|
|
42
|
+
return {
|
|
43
|
+
legacy: true,
|
|
44
|
+
fallback: Number.isInteger(fallback) ? fallback : undefined,
|
|
45
|
+
expression,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 扫描一行 config,找出本插件历史注入的残留。
|
|
51
|
+
*
|
|
52
|
+
* @param {{rowId?: string, current?: Record<string, unknown>, inherited?: Record<string, unknown>}} input
|
|
53
|
+
* `current` = 运行时组合后的配置;`inherited` = bundle 层原值(用于给出「还原成什么」)
|
|
54
|
+
* @returns {{ found: boolean, rowId: string, key: string, expression?: string, fallback?: number, restoreTo?: unknown }}
|
|
55
|
+
*/
|
|
56
|
+
export function findLegacyInjection(input = {}) {
|
|
57
|
+
const rowId = String(input.rowId ?? 'webserver')
|
|
58
|
+
const current = input.current ?? {}
|
|
59
|
+
const inherited = input.inherited ?? {}
|
|
60
|
+
const classified = classifyLegacyPort(current.port)
|
|
61
|
+
if (!classified.legacy) {
|
|
62
|
+
return { found: false, rowId, key: 'port' }
|
|
63
|
+
}
|
|
64
|
+
const bundleValue = inherited.port
|
|
65
|
+
return {
|
|
66
|
+
found: true,
|
|
67
|
+
rowId,
|
|
68
|
+
key: 'port',
|
|
69
|
+
expression: classified.expression,
|
|
70
|
+
fallback: classified.fallback,
|
|
71
|
+
// 还原目标:bundle 层原值(通常是另一个表达式,也可能是字面量)。
|
|
72
|
+
// 拿不到 bundle 值时给 undefined,调用方据此只删覆盖行、不猜值。
|
|
73
|
+
restoreTo: isExpression(bundleValue) || typeof bundleValue === 'number' ? bundleValue : undefined,
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 产出去掉历史注入后的 config。
|
|
79
|
+
*
|
|
80
|
+
* 语义选择:**删除该键**而不是写回 bundle 原值。
|
|
81
|
+
* 理由:覆盖行里少一个键 = 该键回落到 bundle 层默认,这正是"清理掉插件写的东西"该有的结果;
|
|
82
|
+
* 把 bundle 表达式抄进 profile 反而把上游实现细节固化进了用户配置(上游一改就脱节)。
|
|
83
|
+
*
|
|
84
|
+
* @param {{current: Record<string, unknown>, key?: string}} input
|
|
85
|
+
* @returns {{ next: Record<string, unknown>, changed: string[] }}
|
|
86
|
+
*/
|
|
87
|
+
export function withoutLegacyInjection(input) {
|
|
88
|
+
const current = input.current ?? {}
|
|
89
|
+
const key = String(input.key ?? 'port')
|
|
90
|
+
if (!(key in current)) return { next: { ...current }, changed: [] }
|
|
91
|
+
const next = { ...current }
|
|
92
|
+
delete next[key]
|
|
93
|
+
return { next, changed: [key] }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 清理是否可执行 —— **以官方清理能力为准**,而不是版本号字符串。
|
|
98
|
+
*
|
|
99
|
+
* 为什么不判版本号:宿主 `ctx` 并不暴露版本(已核对 cordis/core 的 ctx 面),
|
|
100
|
+
* 插件能拿到的只有"外壳里有没有 `removeLegacyHostCookies`"这个**事实**。
|
|
101
|
+
* 而它恰好就是 0.2.2-rc.2 那条线的分界——官方接管了 cookie 清理,
|
|
102
|
+
* 插件才不需要再用钉端口去压 cookie 增长,回收旧注入才是纯收益。
|
|
103
|
+
*
|
|
104
|
+
* @param {{nativeCleanup?: boolean}} input
|
|
105
|
+
* @returns {boolean}
|
|
106
|
+
*/
|
|
107
|
+
export function canCleanLegacy(input = {}) {
|
|
108
|
+
return input.nativeCleanup === true
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 宿主版本是否达到「可以安全回收旧注入」的线(0.2.2-rc.2+)。
|
|
113
|
+
*
|
|
114
|
+
* 不引入 semver 依赖:本插件只判这一条线,手写比较足够,且规则显式可测。
|
|
115
|
+
* 版本串形态(上游实际发布):`0.2.2-rc.2` / `0.2.2` / `0.2.1-rc.5`。
|
|
116
|
+
*
|
|
117
|
+
* @param {string} version 宿主版本(如 `0.2.2-rc.3`)
|
|
118
|
+
* @returns {boolean}
|
|
119
|
+
*/
|
|
120
|
+
export function supportsLegacyCleanup(version) {
|
|
121
|
+
const parsed = parseVersion(version)
|
|
122
|
+
if (parsed === undefined) return false
|
|
123
|
+
const [major, minor, patch, rc] = parsed
|
|
124
|
+
if (major !== 0) return major > 0
|
|
125
|
+
if (minor !== 2) return minor > 2
|
|
126
|
+
if (patch !== 2) return patch > 2
|
|
127
|
+
// 0.2.2 线:正式版(rc === null)或 rc >= 2 都可以;rc.0/rc.1 不行。
|
|
128
|
+
return rc === null || rc >= 2
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** 解析 `x.y.z[-rc.n]`;解析不了返回 undefined(调用方按「不支持」处理,fail-safe)。 */
|
|
132
|
+
function parseVersion(version) {
|
|
133
|
+
if (typeof version !== 'string') return undefined
|
|
134
|
+
const m = /^(\d+)\.(\d+)\.(\d+)(?:-rc\.(\d+))?$/.exec(version.trim())
|
|
135
|
+
if (m === null) return undefined
|
|
136
|
+
return [Number(m[1]), Number(m[2]), Number(m[3]), m[4] === undefined ? null : Number(m[4])]
|
|
137
|
+
}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dsh-cookie-cleaner — 「文件属于别的用户」这一档的 9 语文案(单文件集中放,便于核对)。
|
|
3
|
-
*
|
|
4
|
-
* 触发条件见 core.js 的 classifyOpenFailure:POSIX 上 stat.uid ≠ process.getuid()。
|
|
5
|
-
* 实测 node:sqlite 在权限不足时**不报 EACCES**(只报 unable to open database file),
|
|
6
|
-
* 所以这一档不能靠错误码判定,只能自己探属主。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/** @type {Record<string,string>} */
|
|
10
|
-
export const ADVISE_OWNER = {
|
|
11
|
-
zh: ' 处置:这个文件属于另一个用户(不是跑本命令的你)。用那个账号跑,或用 --db=<完整路径> 指向你自己那份库。',
|
|
12
|
-
en: ' What to do: this file belongs to another user, not the one running this command. Run it as that account, or point at your own store with --db=<full path>.',
|
|
13
|
-
ja: ' 対処:このファイルは別ユーザーの所有です(本コマンドの実行者ではありません)。そのアカウントで実行するか、--db=<フルパス> で自身のデータベースを指定してください。',
|
|
14
|
-
ko: ' 조치: 이 파일은 다른 사용자의 소유입니다(본 명령의 실행자가 아님). 해당 계정으로 실행하거나 --db=<전체 경로>로 자신의 데이터베이스를 지정하세요.',
|
|
15
|
-
fr: ' À faire : ce fichier appartient à un autre utilisateur que celui qui lance la commande. Exécutez-le sous ce compte, ou désignez votre propre base avec --db=<chemin complet>.',
|
|
16
|
-
de: ' Vorgehen: diese Datei gehört einem anderen Nutzer als dem, der diesen Befehl ausführt. Führen Sie ihn als diesen Nutzer aus, oder zeigen Sie mit --db=<vollständiger Pfad> auf Ihre eigene Datenbank.',
|
|
17
|
-
it: ' Cosa fare: questo file appartiene a un utente diverso da chi esegue il comando. Esegilo come quell’account, oppure indica il tuo archivio con --db=<percorso completo>.',
|
|
18
|
-
ru: ' Что делать: этот файл принадлежит другому пользователю, а не тому, кто запускает команду. Запустите её от того аккаунта или укажите свою базу через --db=<полный путь>.',
|
|
19
|
-
es: ' Qué hacer: este archivo pertenece a otro usuario, no al que ejecuta este comando. Ejecútalo con esa cuenta, o señala tu propio almacén con --db=<ruta completa>.',
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 「读不到 = 库里没这个文件」的统计行(9 语)。跟 classifyOpenFailure 的 missing 档配对;
|
|
24
|
-
* 实测:首次使用前的空目录、自定义安装位置都会落在这里,归成 busy 就是误报。
|
|
25
|
-
*/
|
|
26
|
-
/** @type {Record<string,string>} */
|
|
27
|
-
export const STAT_MISSING = {
|
|
28
|
-
zh: 'cookie 库不在这个位置(客户端从未起过、或装在了别处):{path}',
|
|
29
|
-
en: 'No cookie database at this location (the client never ran, or it lives elsewhere): {path}',
|
|
30
|
-
ja: 'この位置に cookie データベースがありません(クライアント未起動、か別の場所にあります):{path}',
|
|
31
|
-
ko: '이 위치에 cookie 데이터베이스가 없습니다(클라이언트를 실행한 적 없거나 다른 곳에 있습니다): {path}',
|
|
32
|
-
fr: 'Pas de base de cookies à cet emplacement (le client n’a jamais tourné, ou elle est ailleurs) : {path}',
|
|
33
|
-
de: 'Keine Cookie-Datenbank an diesem Ort (der Client lief nie, oder sie liegt woanders): {path}',
|
|
34
|
-
it: 'Nessun database dei cookie in questa posizione (il client non è mai partito, oppure sta altrove): {path}',
|
|
35
|
-
ru: 'Базы cookie в этом месте нет (клиент не запускался или хранится elsewhere): {path}',
|
|
36
|
-
es: 'No hay base de cookies en esta ubicación (el cliente nunca se ejecutó, o está en otro sitio): {path}',
|
|
37
|
-
}
|
|
38
|
-
// ru 文案里的英文残留清掉
|
|
39
|
-
STAT_MISSING.ru = STAT_MISSING.ru.replace('хранится elsewhere', 'лежит в другом месте')
|
|
1
|
+
/**
|
|
2
|
+
* dsh-cookie-cleaner — 「文件属于别的用户」这一档的 9 语文案(单文件集中放,便于核对)。
|
|
3
|
+
*
|
|
4
|
+
* 触发条件见 core.js 的 classifyOpenFailure:POSIX 上 stat.uid ≠ process.getuid()。
|
|
5
|
+
* 实测 node:sqlite 在权限不足时**不报 EACCES**(只报 unable to open database file),
|
|
6
|
+
* 所以这一档不能靠错误码判定,只能自己探属主。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** @type {Record<string,string>} */
|
|
10
|
+
export const ADVISE_OWNER = {
|
|
11
|
+
zh: ' 处置:这个文件属于另一个用户(不是跑本命令的你)。用那个账号跑,或用 --db=<完整路径> 指向你自己那份库。',
|
|
12
|
+
en: ' What to do: this file belongs to another user, not the one running this command. Run it as that account, or point at your own store with --db=<full path>.',
|
|
13
|
+
ja: ' 対処:このファイルは別ユーザーの所有です(本コマンドの実行者ではありません)。そのアカウントで実行するか、--db=<フルパス> で自身のデータベースを指定してください。',
|
|
14
|
+
ko: ' 조치: 이 파일은 다른 사용자의 소유입니다(본 명령의 실행자가 아님). 해당 계정으로 실행하거나 --db=<전체 경로>로 자신의 데이터베이스를 지정하세요.',
|
|
15
|
+
fr: ' À faire : ce fichier appartient à un autre utilisateur que celui qui lance la commande. Exécutez-le sous ce compte, ou désignez votre propre base avec --db=<chemin complet>.',
|
|
16
|
+
de: ' Vorgehen: diese Datei gehört einem anderen Nutzer als dem, der diesen Befehl ausführt. Führen Sie ihn als diesen Nutzer aus, oder zeigen Sie mit --db=<vollständiger Pfad> auf Ihre eigene Datenbank.',
|
|
17
|
+
it: ' Cosa fare: questo file appartiene a un utente diverso da chi esegue il comando. Esegilo come quell’account, oppure indica il tuo archivio con --db=<percorso completo>.',
|
|
18
|
+
ru: ' Что делать: этот файл принадлежит другому пользователю, а не тому, кто запускает команду. Запустите её от того аккаунта или укажите свою базу через --db=<полный путь>.',
|
|
19
|
+
es: ' Qué hacer: este archivo pertenece a otro usuario, no al que ejecuta este comando. Ejecútalo con esa cuenta, o señala tu propio almacén con --db=<ruta completa>.',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 「读不到 = 库里没这个文件」的统计行(9 语)。跟 classifyOpenFailure 的 missing 档配对;
|
|
24
|
+
* 实测:首次使用前的空目录、自定义安装位置都会落在这里,归成 busy 就是误报。
|
|
25
|
+
*/
|
|
26
|
+
/** @type {Record<string,string>} */
|
|
27
|
+
export const STAT_MISSING = {
|
|
28
|
+
zh: 'cookie 库不在这个位置(客户端从未起过、或装在了别处):{path}',
|
|
29
|
+
en: 'No cookie database at this location (the client never ran, or it lives elsewhere): {path}',
|
|
30
|
+
ja: 'この位置に cookie データベースがありません(クライアント未起動、か別の場所にあります):{path}',
|
|
31
|
+
ko: '이 위치에 cookie 데이터베이스가 없습니다(클라이언트를 실행한 적 없거나 다른 곳에 있습니다): {path}',
|
|
32
|
+
fr: 'Pas de base de cookies à cet emplacement (le client n’a jamais tourné, ou elle est ailleurs) : {path}',
|
|
33
|
+
de: 'Keine Cookie-Datenbank an diesem Ort (der Client lief nie, oder sie liegt woanders): {path}',
|
|
34
|
+
it: 'Nessun database dei cookie in questa posizione (il client non è mai partito, oppure sta altrove): {path}',
|
|
35
|
+
ru: 'Базы cookie в этом месте нет (клиент не запускался или хранится elsewhere): {path}',
|
|
36
|
+
es: 'No hay base de cookies en esta ubicación (el cliente nunca se ejecutó, o está en otro sitio): {path}',
|
|
37
|
+
}
|
|
38
|
+
// ru 文案里的英文残留清掉
|
|
39
|
+
STAT_MISSING.ru = STAT_MISSING.ru.replace('хранится elsewhere', 'лежит в другом месте')
|