@duckmind/dm-windows-x64 0.63.0 → 0.63.6
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/dm.exe +0 -0
- package/extensions/.dm-extensions.json +200 -4
- package/extensions/dm-context/package.json +1 -1
- package/extensions/dm-context/skills/context-management/SKILL.md +173 -223
- package/extensions/dm-context/skills/context-management/references/development-and-troubleshooting.md +75 -0
- package/extensions/dm-context/skills/context-management/references/interleaved-async-work.md +143 -0
- package/extensions/dm-context/skills/context-management/references/planning-and-execution.md +81 -0
- package/extensions/dm-context/skills/context-management/references/repeated-items-and-batch-work.md +69 -0
- package/extensions/dm-context/skills/context-management/references/retry-branch-and-pivot.md +80 -0
- package/extensions/dm-context/skills/context-management/references/search-research-and-reading.md +103 -0
- package/extensions/dm-context/skills/context-management/references/task-switching-and-cleanup.md +73 -0
- package/extensions/dm-context/src/context.js +3 -2
- package/extensions/dm-context/src/index.js +168 -84
- package/extensions/dm-skills-manager/THIRD_PARTY_NOTICES.md +27 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/components.js +265 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/constants.js +31 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/creation-fallback.js +20 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/creation.js +145 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/dialog.js +738 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/dm-ai-compat.js +15 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/format.js +125 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/glyphs.js +142 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/layout.js +93 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/paths.js +76 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/registry.js +95 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/settings.js +93 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/startup.js +32 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/toggle.js +54 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/types.js +14 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/ui.js +121 -0
- package/extensions/dm-skills-manager/extensions/skills-manager.js +111 -0
- package/extensions/dm-skills-manager/package.json +121 -0
- package/extensions/dm-web-access/SECURITY.md +5 -0
- package/extensions/dm-web-access/activity.js +65 -0
- package/extensions/dm-web-access/anysearch.js +158 -0
- package/extensions/dm-web-access/auth-fetch.js +131 -0
- package/extensions/dm-web-access/bocha.js +214 -0
- package/extensions/dm-web-access/brave.js +196 -0
- package/extensions/dm-web-access/brightdata-unlocker.js +202 -0
- package/extensions/dm-web-access/brightdata.js +334 -0
- package/extensions/dm-web-access/chrome-cookies.js +627 -0
- package/extensions/dm-web-access/content-find.js +114 -0
- package/extensions/dm-web-access/credential-source.js +150 -0
- package/extensions/dm-web-access/curator-page.js +3559 -0
- package/extensions/dm-web-access/curator-server.js +691 -0
- package/extensions/dm-web-access/data-uri-sanitize.js +312 -0
- package/extensions/dm-web-access/datalab-pdf-extract.js +346 -0
- package/extensions/dm-web-access/declared-web-links.js +167 -0
- package/extensions/dm-web-access/dm-web-fetch-demo.mp4 +0 -0
- package/extensions/dm-web-access/duckduckgo.js +118 -0
- package/extensions/dm-web-access/exa.js +401 -0
- package/extensions/dm-web-access/extract.js +1220 -0
- package/extensions/dm-web-access/feature-config.js +24 -0
- package/extensions/dm-web-access/fetch-params.js +81 -0
- package/extensions/dm-web-access/firecrawl.js +378 -0
- package/extensions/dm-web-access/gemini-adc.js +241 -0
- package/extensions/dm-web-access/gemini-api.js +258 -0
- package/extensions/dm-web-access/gemini-pdf-extract.js +74 -0
- package/extensions/dm-web-access/gemini-search.js +889 -0
- package/extensions/dm-web-access/gemini-url-context.js +97 -0
- package/extensions/dm-web-access/gemini-web-config.js +84 -0
- package/extensions/dm-web-access/gemini-web.js +351 -0
- package/extensions/dm-web-access/github-api.js +166 -0
- package/extensions/dm-web-access/github-extract.js +991 -0
- package/extensions/dm-web-access/github-issue-pr.js +750 -0
- package/extensions/dm-web-access/index.js +3117 -0
- package/extensions/dm-web-access/jina-search.js +242 -0
- package/extensions/dm-web-access/kagi.js +255 -0
- package/extensions/dm-web-access/kimi-search.js +214 -0
- package/extensions/dm-web-access/ollama.js +209 -0
- package/extensions/dm-web-access/openai-search.js +510 -0
- package/extensions/dm-web-access/package.json +34 -0
- package/extensions/dm-web-access/page-query.js +124 -0
- package/extensions/dm-web-access/parallel-mcp.js +223 -0
- package/extensions/dm-web-access/parallel.js +345 -0
- package/extensions/dm-web-access/pdf-extract.js +257 -0
- package/extensions/dm-web-access/perplexity.js +151 -0
- package/extensions/dm-web-access/querit.js +327 -0
- package/extensions/dm-web-access/query-rewrite.js +40 -0
- package/extensions/dm-web-access/render-search-error.js +80 -0
- package/extensions/dm-web-access/rsc-extract.js +347 -0
- package/extensions/dm-web-access/search1api.js +245 -0
- package/extensions/dm-web-access/searchinfinity.js +221 -0
- package/extensions/dm-web-access/searxng.js +223 -0
- package/extensions/dm-web-access/serpbase.js +205 -0
- package/extensions/dm-web-access/serpdive.js +238 -0
- package/extensions/dm-web-access/serper.js +200 -0
- package/extensions/dm-web-access/source-check.js +198 -0
- package/extensions/dm-web-access/ssrf-protection.js +436 -0
- package/extensions/dm-web-access/storage.js +451 -0
- package/extensions/dm-web-access/summary-model-scope.js +83 -0
- package/extensions/dm-web-access/summary-review.js +364 -0
- package/extensions/dm-web-access/tavily.js +199 -0
- package/extensions/dm-web-access/tinyfish.js +325 -0
- package/extensions/dm-web-access/utils.js +476 -0
- package/extensions/dm-web-access/valyu.js +189 -0
- package/extensions/dm-web-access/video-extract.js +336 -0
- package/extensions/dm-web-access/xai-search.js +285 -0
- package/extensions/dm-web-access/xcrawl.js +221 -0
- package/extensions/dm-web-access/youtube-extract.js +279 -0
- package/package.json +9 -1
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { pbkdf2Sync, createDecipheriv } from "node:crypto";
|
|
3
|
+
import { copyFileSync, existsSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir, homedir } from "node:os";
|
|
5
|
+
import { isAbsolute, join, sep } from "node:path";
|
|
6
|
+
import { isBrowserCookieAccessAllowed } from "./gemini-web-config.js";
|
|
7
|
+
const GOOGLE_ORIGINS = [
|
|
8
|
+
"https://gemini.google.com",
|
|
9
|
+
"https://accounts.google.com",
|
|
10
|
+
"https://www.google.com"
|
|
11
|
+
];
|
|
12
|
+
const ALL_COOKIE_NAMES = new Set([
|
|
13
|
+
"__Secure-1PSID",
|
|
14
|
+
"__Secure-1PSIDTS",
|
|
15
|
+
"__Secure-1PSIDCC",
|
|
16
|
+
"__Secure-1PAPISID",
|
|
17
|
+
"NID",
|
|
18
|
+
"AEC",
|
|
19
|
+
"SOCS",
|
|
20
|
+
"__Secure-BUCKET",
|
|
21
|
+
"__Secure-ENID",
|
|
22
|
+
"SID",
|
|
23
|
+
"HSID",
|
|
24
|
+
"SSID",
|
|
25
|
+
"APISID",
|
|
26
|
+
"SAPISID",
|
|
27
|
+
"__Secure-3PSID",
|
|
28
|
+
"__Secure-3PSIDTS",
|
|
29
|
+
"__Secure-3PAPISID",
|
|
30
|
+
"SIDCC"
|
|
31
|
+
]);
|
|
32
|
+
const MACOS_BROWSER_CONFIGS = [
|
|
33
|
+
{ id: "helium", name: "Helium", baseDir: "Library/Application Support/net.imput.helium", keychainService: "Helium Storage Key", keychainAccount: "Helium" },
|
|
34
|
+
{ id: "chrome", name: "Chrome", baseDir: "Library/Application Support/Google/Chrome", keychainService: "Chrome Safe Storage", keychainAccount: "Chrome" },
|
|
35
|
+
{ id: "brave", name: "Brave", baseDir: "Library/Application Support/BraveSoftware/Brave-Browser", keychainService: "Brave Safe Storage", keychainAccount: "Brave" },
|
|
36
|
+
{ id: "arc", name: "Arc", baseDir: "Library/Application Support/Arc/User Data", keychainService: "Arc Safe Storage", keychainAccount: "Arc" }
|
|
37
|
+
];
|
|
38
|
+
const LINUX_BROWSER_CONFIGS = [
|
|
39
|
+
{ id: "chromium", name: "Chromium", baseDir: ".config/chromium", secretToolApp: "chromium" },
|
|
40
|
+
{ id: "chrome", name: "Chrome", baseDir: ".config/google-chrome", secretToolApp: "chrome" }
|
|
41
|
+
];
|
|
42
|
+
const WINDOWS_BROWSER_CONFIGS = [
|
|
43
|
+
{ id: "chrome", name: "Chrome", baseDir: "Google/Chrome/User Data", usesLocalAppData: true },
|
|
44
|
+
{ id: "edge", name: "Edge", baseDir: "Microsoft/Edge/User Data", usesLocalAppData: true }
|
|
45
|
+
];
|
|
46
|
+
const browserPasswordCache = new Map;
|
|
47
|
+
let lastCookieDiagnostic = null;
|
|
48
|
+
let lastCookieDiagnosticDetails = null;
|
|
49
|
+
let sqliteModule = null;
|
|
50
|
+
let sqliteImportAttempted = false;
|
|
51
|
+
export function getLastGoogleCookieDiagnostic() {
|
|
52
|
+
return lastCookieDiagnostic;
|
|
53
|
+
}
|
|
54
|
+
export function getLastBrowserCookieDiagnostic() {
|
|
55
|
+
return lastCookieDiagnostic;
|
|
56
|
+
}
|
|
57
|
+
export function getLastGoogleCookieDiagnosticDetails() {
|
|
58
|
+
return lastCookieDiagnosticDetails;
|
|
59
|
+
}
|
|
60
|
+
export async function getGoogleCookies(options) {
|
|
61
|
+
return getBrowserCookiesForHosts({
|
|
62
|
+
hosts: GOOGLE_ORIGINS.map((origin) => new URL(origin).hostname),
|
|
63
|
+
browser: options?.browser,
|
|
64
|
+
profile: options?.profile,
|
|
65
|
+
requiredCookies: options?.requiredCookies,
|
|
66
|
+
cookieNames: ALL_COOKIE_NAMES,
|
|
67
|
+
requiredLabel: "Gemini"
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export async function getBrowserCookiesForHosts(options) {
|
|
71
|
+
lastCookieDiagnostic = null;
|
|
72
|
+
lastCookieDiagnosticDetails = null;
|
|
73
|
+
if (!isBrowserCookieAccessAllowed()) {
|
|
74
|
+
setCookieDiagnostic("Browser cookie access is disabled; enable allowBrowserCookies to use browser cookies.");
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const currentPlatform = process.platform;
|
|
78
|
+
const platformConfigs = currentPlatform === "darwin" ? MACOS_BROWSER_CONFIGS : currentPlatform === "linux" ? LINUX_BROWSER_CONFIGS : currentPlatform === "win32" ? WINDOWS_BROWSER_CONFIGS : [];
|
|
79
|
+
const configs = options.browser ? platformConfigs.filter((config) => config.id === options.browser) : platformConfigs;
|
|
80
|
+
if (options.browser && configs.length === 0) {
|
|
81
|
+
setCookieDiagnostic(`Browser preset '${options.browser}' is not supported on this platform.`);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
if (configs.length === 0) {
|
|
85
|
+
setCookieDiagnostic("Chromium cookie extraction is unsupported on this platform.");
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const warningSet = new Set;
|
|
89
|
+
const rawProfile = typeof options.profile === "string" ? options.profile.trim() : "";
|
|
90
|
+
const requestedProfile = normalizeProfileName(options.profile);
|
|
91
|
+
if (rawProfile && !requestedProfile) {
|
|
92
|
+
setCookieDiagnostic("Configured Chromium profile must be a profile directory name, not a path.");
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
const requiredCookies = normalizeCookieNames(options.requiredCookies);
|
|
96
|
+
const cookieNames = normalizeCookieNames(options.cookieNames ? [...options.cookieNames] : undefined);
|
|
97
|
+
const hosts = normalizeHosts(options.hosts);
|
|
98
|
+
if (hosts.length === 0) {
|
|
99
|
+
setCookieDiagnostic("No valid cookie hosts were requested.");
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const attempts = [];
|
|
103
|
+
const home = currentPlatform === "win32" ? process.env.USERPROFILE || homedir() : homedir();
|
|
104
|
+
let sawCookieDatabase = false;
|
|
105
|
+
let sawRequiredCookies = false;
|
|
106
|
+
let sawAnyHostCookie = false;
|
|
107
|
+
let sawBackendFailure;
|
|
108
|
+
let sawUnsafeProfilePath = false;
|
|
109
|
+
let sawWindowsAppBoundCookie = false;
|
|
110
|
+
let sawDecryptionFailure = false;
|
|
111
|
+
for (const config of configs) {
|
|
112
|
+
const profiles = requestedProfile ? [requestedProfile] : listBrowserProfiles(home, config);
|
|
113
|
+
for (const profile of profiles) {
|
|
114
|
+
const profilePath = resolveProfilePath(home, config, profile);
|
|
115
|
+
if (profilePath === "outside-root") {
|
|
116
|
+
sawUnsafeProfilePath = true;
|
|
117
|
+
recordCookieAttempt(attempts, config, profile, "unsafe-profile");
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (!profilePath) {
|
|
121
|
+
recordCookieAttempt(attempts, config, profile, "missing-database");
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const cookiesPath = cookieDatabasePath(profilePath, config);
|
|
125
|
+
if (!cookiesPath) {
|
|
126
|
+
recordCookieAttempt(attempts, config, profile, "missing-database");
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
sawCookieDatabase = true;
|
|
130
|
+
const tempDir = mkdtempSync(join(tmpdir(), "pi-chrome-cookies-"));
|
|
131
|
+
try {
|
|
132
|
+
const tempDb = join(tempDir, "Cookies");
|
|
133
|
+
copyFileSync(cookiesPath, tempDb);
|
|
134
|
+
copySidecar(cookiesPath, tempDb, "-wal");
|
|
135
|
+
copySidecar(cookiesPath, tempDb, "-shm");
|
|
136
|
+
if (requiredCookies?.length) {
|
|
137
|
+
const preflight = await hasCookieNames(tempDb, hosts, requiredCookies);
|
|
138
|
+
if (preflight.failure) {
|
|
139
|
+
sawBackendFailure = preflight.failure;
|
|
140
|
+
recordCookieAttempt(attempts, config, profile, preflight.failure === "unavailable" ? "sqlite-unavailable" : "sqlite-query-failed");
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (!preflight.present) {
|
|
144
|
+
recordCookieAttempt(attempts, config, profile, "missing-required-cookies");
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
sawRequiredCookies = true;
|
|
148
|
+
}
|
|
149
|
+
const key = currentPlatform === "win32" ? await readWindowsEncryptionKey(config, home) : await readBrowserPassword(config, currentPlatform).then((password) => password ? pbkdf2Sync(password, "saltysalt", currentPlatform === "darwin" ? 1003 : 1, 16, "sha1") : null);
|
|
150
|
+
if (!key) {
|
|
151
|
+
warningSet.add(currentPlatform === "win32" ? `Could not read ${config.name} Windows cookie encryption key` : `Could not read ${config.name} cookie encryption password`);
|
|
152
|
+
recordCookieAttempt(attempts, config, profile, "password-read-failed");
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const metaVersion = await readMetaVersion(tempDb);
|
|
156
|
+
if (metaVersion.failure) {
|
|
157
|
+
sawBackendFailure = metaVersion.failure;
|
|
158
|
+
recordCookieAttempt(attempts, config, profile, metaVersion.failure === "unavailable" ? "sqlite-unavailable" : "sqlite-query-failed");
|
|
159
|
+
}
|
|
160
|
+
if (metaVersion.value === null)
|
|
161
|
+
continue;
|
|
162
|
+
const rowsResult = await queryCookieRows(tempDb, hosts, cookieNames ?? null, Boolean(options.requestUrl));
|
|
163
|
+
if (rowsResult.status === "failure") {
|
|
164
|
+
sawBackendFailure = rowsResult.failure;
|
|
165
|
+
recordCookieAttempt(attempts, config, profile, rowsResult.failure === "unavailable" ? "sqlite-unavailable" : "sqlite-query-failed");
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const entries = [];
|
|
169
|
+
const cookies = {};
|
|
170
|
+
const requiredDecryptFailures = new Set;
|
|
171
|
+
for (const row of rowsResult.rows) {
|
|
172
|
+
const name = typeof row.name === "string" ? row.name : "";
|
|
173
|
+
if (!name)
|
|
174
|
+
continue;
|
|
175
|
+
let value = typeof row.value === "string" && row.value.length > 0 ? row.value : null;
|
|
176
|
+
if (!value && typeof row.encrypted_value_hex === "string" && /^[0-9a-f]*$/i.test(row.encrypted_value_hex)) {
|
|
177
|
+
const encrypted = Buffer.from(row.encrypted_value_hex, "hex");
|
|
178
|
+
if (currentPlatform === "win32" && encrypted.subarray(0, 3).toString("utf8") === "v20")
|
|
179
|
+
sawWindowsAppBoundCookie = true;
|
|
180
|
+
value = currentPlatform === "win32" ? decryptWindowsCookieValue(encrypted, key, metaVersion.value >= 24) : decryptCookieValue(encrypted, key, metaVersion.value >= 24);
|
|
181
|
+
if (!value && requiredCookies?.includes(name))
|
|
182
|
+
requiredDecryptFailures.add(name);
|
|
183
|
+
}
|
|
184
|
+
if (!value)
|
|
185
|
+
continue;
|
|
186
|
+
const path = typeof row.path === "string" && row.path.startsWith("/") ? row.path : "/";
|
|
187
|
+
if (options.requestUrl && !pathMatches(options.requestUrl.pathname || "/", path))
|
|
188
|
+
continue;
|
|
189
|
+
entries.push({ name, value, path });
|
|
190
|
+
if (!cookies[name])
|
|
191
|
+
cookies[name] = value;
|
|
192
|
+
}
|
|
193
|
+
if (entries.length > 0)
|
|
194
|
+
sawAnyHostCookie = true;
|
|
195
|
+
if (requiredCookies?.length && !requiredCookies.every((name) => Boolean(cookies[name]))) {
|
|
196
|
+
if (requiredCookies.some((name) => !cookies[name] && requiredDecryptFailures.has(name))) {
|
|
197
|
+
sawDecryptionFailure = true;
|
|
198
|
+
recordCookieAttempt(attempts, config, profile, "decryption-failed");
|
|
199
|
+
} else {
|
|
200
|
+
recordCookieAttempt(attempts, config, profile, "missing-required-cookies");
|
|
201
|
+
}
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (entries.length === 0) {
|
|
205
|
+
recordCookieAttempt(attempts, config, profile, requiredDecryptFailures.size > 0 ? "decryption-failed" : "no-host-cookies");
|
|
206
|
+
if (requiredDecryptFailures.size > 0)
|
|
207
|
+
sawDecryptionFailure = true;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
cookies,
|
|
212
|
+
warnings: [...warningSet],
|
|
213
|
+
...options.requestUrl ? { cookieHeader: buildCookieHeader(entries) } : {}
|
|
214
|
+
};
|
|
215
|
+
} finally {
|
|
216
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (sawBackendFailure === "unavailable") {
|
|
221
|
+
setCookieDiagnostic("SQLite backend unavailable: install sqlite3 or use a runtime with SQLite support.", attempts);
|
|
222
|
+
} else if (sawBackendFailure === "query") {
|
|
223
|
+
setCookieDiagnostic("SQLite query failed while reading the copied Chromium cookie database.", attempts);
|
|
224
|
+
} else if (sawUnsafeProfilePath) {
|
|
225
|
+
setCookieDiagnostic("Configured Chromium profile must resolve inside the browser profile root.", attempts);
|
|
226
|
+
} else if (!sawCookieDatabase) {
|
|
227
|
+
setCookieDiagnostic(requestedProfile ? `Chromium profile '${requestedProfile}' does not contain a cookie database.` : "No detected Chromium profile contains a cookie database.", attempts);
|
|
228
|
+
} else if (requiredCookies?.length && !sawRequiredCookies) {
|
|
229
|
+
setCookieDiagnostic(`No detected Chromium profile contains the required ${options.requiredLabel ?? "browser"} cookies.`, attempts);
|
|
230
|
+
} else if (sawWindowsAppBoundCookie) {
|
|
231
|
+
setCookieDiagnostic("Windows Chromium v20 app-bound cookies are not supported.", attempts);
|
|
232
|
+
} else if (warningSet.size > 0) {
|
|
233
|
+
setCookieDiagnostic([...warningSet][0], attempts);
|
|
234
|
+
} else if (sawDecryptionFailure) {
|
|
235
|
+
setCookieDiagnostic(`Required ${options.requiredLabel ?? "browser"} cookies could not be decrypted.`, attempts);
|
|
236
|
+
} else if (!sawAnyHostCookie) {
|
|
237
|
+
setCookieDiagnostic(options.requestUrl ? "No detected Chromium profile contains cookies for the requested URL." : "No detected Chromium profile contains cookies for the requested host.", attempts);
|
|
238
|
+
} else {
|
|
239
|
+
setCookieDiagnostic("Required Gemini cookies were not available or could not be decrypted.", attempts);
|
|
240
|
+
}
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
function setCookieDiagnostic(message, attempts = []) {
|
|
244
|
+
lastCookieDiagnostic = message;
|
|
245
|
+
lastCookieDiagnosticDetails = { message, attempts };
|
|
246
|
+
}
|
|
247
|
+
function recordCookieAttempt(attempts, config, profile, status) {
|
|
248
|
+
attempts.push({ browser: config.name, profile, status });
|
|
249
|
+
}
|
|
250
|
+
function normalizeProfileName(value) {
|
|
251
|
+
if (typeof value !== "string")
|
|
252
|
+
return;
|
|
253
|
+
const normalized = value.trim();
|
|
254
|
+
if (!normalized)
|
|
255
|
+
return;
|
|
256
|
+
if (isAbsolute(normalized) || normalized === "." || normalized === ".." || normalized.includes("/") || normalized.includes("\\")) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
return normalized;
|
|
260
|
+
}
|
|
261
|
+
function resolveProfilePath(home, config, profile) {
|
|
262
|
+
const basePath = browserBasePath(home, config);
|
|
263
|
+
const profilePath = join(basePath, profile);
|
|
264
|
+
if (!cookieDatabasePath(profilePath, config))
|
|
265
|
+
return null;
|
|
266
|
+
try {
|
|
267
|
+
const baseRealPath = realpathSync(basePath);
|
|
268
|
+
const profileRealPath = realpathSync(profilePath);
|
|
269
|
+
if (profileRealPath !== baseRealPath && !profileRealPath.startsWith(`${baseRealPath}${sep}`))
|
|
270
|
+
return "outside-root";
|
|
271
|
+
return profileRealPath;
|
|
272
|
+
} catch {
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function cookieDatabasePath(profilePath, config) {
|
|
277
|
+
const networkCookies = join(profilePath, "Network", "Cookies");
|
|
278
|
+
if (config.usesLocalAppData && existsSync(networkCookies))
|
|
279
|
+
return networkCookies;
|
|
280
|
+
const legacyCookies = join(profilePath, "Cookies");
|
|
281
|
+
return existsSync(legacyCookies) ? legacyCookies : null;
|
|
282
|
+
}
|
|
283
|
+
function browserBasePath(home, config) {
|
|
284
|
+
return config.usesLocalAppData ? join(process.env.LOCALAPPDATA || join(home, "AppData", "Local"), config.baseDir) : join(home, config.baseDir);
|
|
285
|
+
}
|
|
286
|
+
function normalizeCookieNames(names) {
|
|
287
|
+
if (!names?.length)
|
|
288
|
+
return;
|
|
289
|
+
const normalized = names.filter((name) => typeof name === "string").map((name) => name.trim()).filter(Boolean);
|
|
290
|
+
return normalized.length > 0 ? [...new Set(normalized)] : undefined;
|
|
291
|
+
}
|
|
292
|
+
function normalizeHosts(hosts) {
|
|
293
|
+
return [...new Set(hosts.map((host) => host.trim().toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "")).filter(Boolean))];
|
|
294
|
+
}
|
|
295
|
+
function listBrowserProfiles(home, config) {
|
|
296
|
+
const basePath = browserBasePath(home, config);
|
|
297
|
+
if (!existsSync(basePath))
|
|
298
|
+
return ["Default"];
|
|
299
|
+
const profiles = new Set;
|
|
300
|
+
try {
|
|
301
|
+
for (const entry of readdirSync(basePath, { withFileTypes: true })) {
|
|
302
|
+
if (entry.isDirectory() && cookieDatabasePath(join(basePath, entry.name), config))
|
|
303
|
+
profiles.add(entry.name);
|
|
304
|
+
}
|
|
305
|
+
} catch {}
|
|
306
|
+
if (profiles.size === 0)
|
|
307
|
+
return ["Default"];
|
|
308
|
+
return [...profiles].sort(compareProfileNames);
|
|
309
|
+
}
|
|
310
|
+
function compareProfileNames(a, b) {
|
|
311
|
+
const key = (name) => {
|
|
312
|
+
if (name === "Default")
|
|
313
|
+
return [0, 0];
|
|
314
|
+
const profile = /^Profile\s+(\d+)$/i.exec(name);
|
|
315
|
+
if (profile)
|
|
316
|
+
return [1, Number(profile[1])];
|
|
317
|
+
const person = /^Person\s+(\d+)$/i.exec(name);
|
|
318
|
+
if (person)
|
|
319
|
+
return [2, Number(person[1])];
|
|
320
|
+
return [3, Number.MAX_SAFE_INTEGER];
|
|
321
|
+
};
|
|
322
|
+
const [ap, ai] = key(a);
|
|
323
|
+
const [bp, bi] = key(b);
|
|
324
|
+
return ap - bp || ai - bi || a.localeCompare(b, undefined, { sensitivity: "base", numeric: true });
|
|
325
|
+
}
|
|
326
|
+
function decryptCookieValue(encrypted, key, stripHash) {
|
|
327
|
+
const buf = Buffer.from(encrypted);
|
|
328
|
+
if (buf.length < 3 || !/^v\d\d$/.test(buf.subarray(0, 3).toString("utf8")))
|
|
329
|
+
return null;
|
|
330
|
+
const ciphertext = buf.subarray(3);
|
|
331
|
+
if (!ciphertext.length)
|
|
332
|
+
return "";
|
|
333
|
+
try {
|
|
334
|
+
const decipher = createDecipheriv("aes-128-cbc", key, Buffer.alloc(16, 32));
|
|
335
|
+
decipher.setAutoPadding(false);
|
|
336
|
+
const unpadded = removePkcs7Padding(Buffer.concat([decipher.update(ciphertext), decipher.final()]));
|
|
337
|
+
const bytes = stripHash && unpadded.length >= 32 ? unpadded.subarray(32) : unpadded;
|
|
338
|
+
const decoded = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
339
|
+
let i = 0;
|
|
340
|
+
while (i < decoded.length && decoded.charCodeAt(i) < 32)
|
|
341
|
+
i++;
|
|
342
|
+
return decoded.slice(i);
|
|
343
|
+
} catch {
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
function decryptWindowsCookieValue(encrypted, key, stripHash) {
|
|
348
|
+
const buf = Buffer.from(encrypted);
|
|
349
|
+
if (buf.subarray(0, 3).toString("utf8") !== "v10" || buf.length < 3 + 12 + 16)
|
|
350
|
+
return null;
|
|
351
|
+
try {
|
|
352
|
+
const nonce = buf.subarray(3, 15);
|
|
353
|
+
const ciphertext = buf.subarray(15, -16);
|
|
354
|
+
const decipher = createDecipheriv("aes-256-gcm", key, nonce);
|
|
355
|
+
decipher.setAuthTag(buf.subarray(-16));
|
|
356
|
+
const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
357
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(stripHash && plaintext.length >= 32 ? plaintext.subarray(32) : plaintext);
|
|
358
|
+
} catch {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
function removePkcs7Padding(buf) {
|
|
363
|
+
if (!buf.length)
|
|
364
|
+
return buf;
|
|
365
|
+
const padding = buf[buf.length - 1];
|
|
366
|
+
return !padding || padding > 16 ? buf : buf.subarray(0, buf.length - padding);
|
|
367
|
+
}
|
|
368
|
+
function readBrowserPassword(config, currentPlatform) {
|
|
369
|
+
const cacheKey = `${currentPlatform}:${config.name}`;
|
|
370
|
+
const cached = browserPasswordCache.get(cacheKey);
|
|
371
|
+
if (cached)
|
|
372
|
+
return cached;
|
|
373
|
+
const passwordResult = currentPlatform === "darwin" ? config.keychainAccount && config.keychainService ? readKeychainPassword(config.keychainAccount, config.keychainService).then((password) => ({ password, cacheable: Boolean(password) })) : Promise.resolve({ password: null, cacheable: false }) : currentPlatform === "linux" ? readLinuxPassword(config.secretToolApp) : Promise.resolve({ password: null, cacheable: false });
|
|
374
|
+
const passwordPromise = passwordResult.then(({ password, cacheable }) => {
|
|
375
|
+
if (!cacheable)
|
|
376
|
+
browserPasswordCache.delete(cacheKey);
|
|
377
|
+
return password;
|
|
378
|
+
}, (error) => {
|
|
379
|
+
browserPasswordCache.delete(cacheKey);
|
|
380
|
+
throw error;
|
|
381
|
+
});
|
|
382
|
+
browserPasswordCache.set(cacheKey, passwordPromise);
|
|
383
|
+
return passwordPromise;
|
|
384
|
+
}
|
|
385
|
+
async function readWindowsEncryptionKey(config, home) {
|
|
386
|
+
try {
|
|
387
|
+
const localState = JSON.parse(readFileSync(join(browserBasePath(home, config), "Local State"), "utf8"));
|
|
388
|
+
const encodedKey = localState.os_crypt?.encrypted_key;
|
|
389
|
+
if (typeof encodedKey !== "string")
|
|
390
|
+
return null;
|
|
391
|
+
const protectedKey = Buffer.from(encodedKey, "base64");
|
|
392
|
+
if (protectedKey.subarray(0, 5).toString("utf8") !== "DPAPI")
|
|
393
|
+
return null;
|
|
394
|
+
const decrypted = await unprotectWindowsData(protectedKey.subarray(5));
|
|
395
|
+
return decrypted?.length === 32 ? decrypted : null;
|
|
396
|
+
} catch {
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function unprotectWindowsData(protectedData) {
|
|
401
|
+
return new Promise((resolve) => {
|
|
402
|
+
const script = "Add-Type -AssemblyName System.Security;$data=[Convert]::FromBase64String($env:PIWA_PROTECTED);$clear=[System.Security.Cryptography.ProtectedData]::Unprotect($data,$null,[System.Security.Cryptography.DataProtectionScope]::CurrentUser);[Console]::Write([Convert]::ToBase64String($clear))";
|
|
403
|
+
const encoded = Buffer.from(script, "utf16le").toString("base64");
|
|
404
|
+
execFile("powershell.exe", ["-NoProfile", "-NonInteractive", "-EncodedCommand", encoded], { timeout: 5000, maxBuffer: 1024 * 1024, env: { ...process.env, PIWA_PROTECTED: protectedData.toString("base64") } }, (err, stdout) => {
|
|
405
|
+
if (err) {
|
|
406
|
+
resolve(null);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
try {
|
|
410
|
+
resolve(Buffer.from(stdout.trim(), "base64"));
|
|
411
|
+
} catch {
|
|
412
|
+
resolve(null);
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
function readKeychainPassword(account, service) {
|
|
418
|
+
return new Promise((resolve) => {
|
|
419
|
+
execFile("security", ["find-generic-password", "-w", "-a", account, "-s", service], { timeout: 5000 }, (err, stdout) => {
|
|
420
|
+
if (err) {
|
|
421
|
+
resolve(null);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
resolve(stdout.trim() || null);
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
function readLinuxPassword(secretToolApp) {
|
|
429
|
+
if (!secretToolApp)
|
|
430
|
+
return Promise.resolve({ password: "peanuts", cacheable: true });
|
|
431
|
+
return new Promise((resolve) => {
|
|
432
|
+
execFile("secret-tool", ["lookup", "application", secretToolApp], { timeout: 5000 }, (err, stdout) => {
|
|
433
|
+
if (err) {
|
|
434
|
+
resolve({ password: "peanuts", cacheable: false });
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
const password = stdout.trim();
|
|
438
|
+
resolve(password ? { password, cacheable: true } : { password: "peanuts", cacheable: false });
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
async function importSqlite() {
|
|
443
|
+
if (process.env.DM_WEB_ACCESS_DISABLE_NODE_SQLITE === "1")
|
|
444
|
+
return null;
|
|
445
|
+
if (sqliteImportAttempted)
|
|
446
|
+
return sqliteModule;
|
|
447
|
+
sqliteImportAttempted = true;
|
|
448
|
+
const orig = process.emitWarning.bind(process);
|
|
449
|
+
process.emitWarning = (warning, ...args) => {
|
|
450
|
+
const msg = typeof warning === "string" ? warning : warning?.message ?? "";
|
|
451
|
+
if (msg.includes("SQLite is an experimental feature"))
|
|
452
|
+
return;
|
|
453
|
+
return orig(warning, ...args);
|
|
454
|
+
};
|
|
455
|
+
try {
|
|
456
|
+
sqliteModule = await import("node:sqlite");
|
|
457
|
+
} catch {
|
|
458
|
+
sqliteModule = null;
|
|
459
|
+
} finally {
|
|
460
|
+
process.emitWarning = orig;
|
|
461
|
+
}
|
|
462
|
+
return sqliteModule;
|
|
463
|
+
}
|
|
464
|
+
async function runSqliteQuery(dbPath, sql) {
|
|
465
|
+
const sqlite = await importSqlite();
|
|
466
|
+
let queryFailed = false;
|
|
467
|
+
if (sqlite) {
|
|
468
|
+
try {
|
|
469
|
+
const db = new sqlite.DatabaseSync(dbPath, { readOnly: true });
|
|
470
|
+
try {
|
|
471
|
+
return { status: "success", rows: db.prepare(sql).all() };
|
|
472
|
+
} finally {
|
|
473
|
+
db.close();
|
|
474
|
+
}
|
|
475
|
+
} catch {
|
|
476
|
+
queryFailed = true;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
const cli = await runSqliteCli(dbPath, sql);
|
|
480
|
+
if (cli.status === "success")
|
|
481
|
+
return cli;
|
|
482
|
+
if (cli.failure === "query")
|
|
483
|
+
queryFailed = true;
|
|
484
|
+
const python = await runPythonSqlite(dbPath, sql);
|
|
485
|
+
if (python.status === "success")
|
|
486
|
+
return python;
|
|
487
|
+
if (python.failure === "query")
|
|
488
|
+
queryFailed = true;
|
|
489
|
+
return { status: "failure", failure: queryFailed ? "query" : "unavailable" };
|
|
490
|
+
}
|
|
491
|
+
function runSqliteCli(dbPath, sql) {
|
|
492
|
+
return new Promise((resolve) => {
|
|
493
|
+
execFile("sqlite3", ["-readonly", "-json", dbPath, sql], { timeout: 5000, maxBuffer: 1048576 }, (err, stdout) => {
|
|
494
|
+
if (err) {
|
|
495
|
+
resolve({ status: "failure", failure: err.code === "ENOENT" ? "unavailable" : "query" });
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
try {
|
|
499
|
+
const parsed = JSON.parse(stdout || "[]");
|
|
500
|
+
resolve(Array.isArray(parsed) ? { status: "success", rows: parsed } : { status: "failure", failure: "query" });
|
|
501
|
+
} catch {
|
|
502
|
+
resolve({ status: "failure", failure: "query" });
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
function runPythonSqlite(dbPath, sql) {
|
|
508
|
+
const script = `import json,sqlite3,sys
|
|
509
|
+
try:
|
|
510
|
+
c=sqlite3.connect('file:'+sys.argv[1]+'?mode=ro',uri=True)
|
|
511
|
+
c.row_factory=sqlite3.Row
|
|
512
|
+
print(json.dumps([dict(r) for r in c.execute(sys.argv[2]).fetchall()]))
|
|
513
|
+
except Exception:
|
|
514
|
+
sys.exit(1)`;
|
|
515
|
+
return new Promise((resolve) => {
|
|
516
|
+
execFile("python3", ["-c", script, dbPath, sql], { timeout: 5000, maxBuffer: 1048576 }, (err, stdout) => {
|
|
517
|
+
if (err) {
|
|
518
|
+
resolve({ status: "failure", failure: err.code === "ENOENT" ? "unavailable" : "query" });
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
try {
|
|
522
|
+
const parsed = JSON.parse(stdout || "[]");
|
|
523
|
+
resolve(Array.isArray(parsed) ? { status: "success", rows: parsed } : { status: "failure", failure: "query" });
|
|
524
|
+
} catch {
|
|
525
|
+
resolve({ status: "failure", failure: "query" });
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
async function readMetaVersion(dbPath) {
|
|
531
|
+
const result = await runSqliteQuery(dbPath, "SELECT value FROM meta WHERE key = 'version'");
|
|
532
|
+
if (result.status === "failure") {
|
|
533
|
+
return result.failure === "unavailable" ? { value: null, failure: result.failure } : { value: 0 };
|
|
534
|
+
}
|
|
535
|
+
const value = result.rows[0]?.value;
|
|
536
|
+
if (typeof value === "number")
|
|
537
|
+
return { value: Math.floor(value) };
|
|
538
|
+
if (typeof value === "string")
|
|
539
|
+
return { value: parseInt(value, 10) || 0 };
|
|
540
|
+
return { value: 0 };
|
|
541
|
+
}
|
|
542
|
+
async function hasCookieNames(dbPath, hosts, names) {
|
|
543
|
+
const result = await runSqliteQuery(dbPath, `SELECT DISTINCT name FROM cookies WHERE ${buildCookieWhere(hosts, names)}`);
|
|
544
|
+
if (result.status === "failure")
|
|
545
|
+
return { present: false, failure: result.failure };
|
|
546
|
+
const present = new Set(result.rows.map((row) => typeof row.name === "string" ? row.name : ""));
|
|
547
|
+
return { present: names.every((name) => present.has(name)) };
|
|
548
|
+
}
|
|
549
|
+
async function queryCookieRows(dbPath, hosts, names, filterExpired) {
|
|
550
|
+
const columns = await readCookieColumns(dbPath);
|
|
551
|
+
if (columns.status === "failure")
|
|
552
|
+
return columns;
|
|
553
|
+
const pathExpr = columns.columns.has("path") ? "path" : "'/' AS path";
|
|
554
|
+
const expiresExpr = columns.columns.has("expires_utc") ? chromeExpiryMillisExpr() : "0";
|
|
555
|
+
const expiryFilter = filterExpired && columns.columns.has("expires_utc") ? ` AND (${expiresExpr} = 0 OR ${expiresExpr} > ${chromeExpiryNowMillis()})` : "";
|
|
556
|
+
const partitionFilter = filterExpired ? unpartitionedCookieFilter(columns.columns) : "";
|
|
557
|
+
return runSqliteQuery(dbPath, `SELECT name, value, host_key, ${pathExpr}, ${expiresExpr} AS expires_utc, hex(encrypted_value) AS encrypted_value_hex FROM cookies WHERE ${buildCookieWhere(hosts, names ?? undefined)}${expiryFilter}${partitionFilter} ORDER BY length(path) DESC, ${expiresExpr} ASC`);
|
|
558
|
+
}
|
|
559
|
+
async function readCookieColumns(dbPath) {
|
|
560
|
+
const result = await runSqliteQuery(dbPath, "PRAGMA table_info(cookies)");
|
|
561
|
+
if (result.status === "failure")
|
|
562
|
+
return result;
|
|
563
|
+
return { status: "success", columns: new Set(result.rows.map((row) => typeof row.name === "string" ? row.name : "")) };
|
|
564
|
+
}
|
|
565
|
+
function chromeExpiryMillisExpr() {
|
|
566
|
+
return "CASE WHEN expires_utc = 0 THEN 0 ELSE CAST(expires_utc / 1000 AS INTEGER) + CASE WHEN expires_utc % 1000 = 0 THEN 0 ELSE 1 END END";
|
|
567
|
+
}
|
|
568
|
+
function chromeExpiryNowMillis() {
|
|
569
|
+
return Date.now() + 11644473600000;
|
|
570
|
+
}
|
|
571
|
+
function unpartitionedCookieFilter(columns) {
|
|
572
|
+
const clauses = [];
|
|
573
|
+
if (columns.has("top_frame_site_key"))
|
|
574
|
+
clauses.push("(top_frame_site_key IS NULL OR top_frame_site_key = '')");
|
|
575
|
+
if (columns.has("partition_key"))
|
|
576
|
+
clauses.push("(partition_key IS NULL OR partition_key = '')");
|
|
577
|
+
if (columns.has("is_partitioned"))
|
|
578
|
+
clauses.push("(is_partitioned IS NULL OR is_partitioned = 0)");
|
|
579
|
+
return clauses.length > 0 ? ` AND ${clauses.join(" AND ")}` : "";
|
|
580
|
+
}
|
|
581
|
+
function buildCookieHeader(entries) {
|
|
582
|
+
return entries.sort((a, b) => b.path.length - a.path.length).map(({ name, value }) => `${name}=${value}`).join("; ");
|
|
583
|
+
}
|
|
584
|
+
function pathMatches(requestPath, cookiePath) {
|
|
585
|
+
if (requestPath === cookiePath)
|
|
586
|
+
return true;
|
|
587
|
+
if (!requestPath.startsWith(cookiePath))
|
|
588
|
+
return false;
|
|
589
|
+
if (cookiePath.endsWith("/"))
|
|
590
|
+
return true;
|
|
591
|
+
return requestPath[cookiePath.length] === "/";
|
|
592
|
+
}
|
|
593
|
+
function buildCookieWhere(hosts, cookieNames) {
|
|
594
|
+
const hostClauses = [];
|
|
595
|
+
for (const host of hosts) {
|
|
596
|
+
const escapedHost = escapeSqlString(host);
|
|
597
|
+
hostClauses.push(`host_key = '${escapedHost}'`);
|
|
598
|
+
for (const candidate of domainCookieHosts(host)) {
|
|
599
|
+
hostClauses.push(`host_key = '.${escapeSqlString(candidate)}'`);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
let where = `(${[...new Set(hostClauses)].join(" OR ")})`;
|
|
603
|
+
const names = cookieNames ? [...cookieNames].filter(Boolean) : [];
|
|
604
|
+
if (names.length)
|
|
605
|
+
where += ` AND name IN (${names.map((name) => `'${escapeSqlString(name)}'`).join(", ")})`;
|
|
606
|
+
return where;
|
|
607
|
+
}
|
|
608
|
+
function escapeSqlString(value) {
|
|
609
|
+
return value.replaceAll("'", "''");
|
|
610
|
+
}
|
|
611
|
+
function domainCookieHosts(host) {
|
|
612
|
+
const parts = host.split(".").filter(Boolean);
|
|
613
|
+
if (parts.length <= 1)
|
|
614
|
+
return [];
|
|
615
|
+
const candidates = new Set;
|
|
616
|
+
for (let i = 0;i <= parts.length - 2; i++)
|
|
617
|
+
candidates.add(parts.slice(i).join("."));
|
|
618
|
+
return [...candidates];
|
|
619
|
+
}
|
|
620
|
+
function copySidecar(srcDb, targetDb, suffix) {
|
|
621
|
+
const sidecar = `${srcDb}${suffix}`;
|
|
622
|
+
if (!existsSync(sidecar))
|
|
623
|
+
return;
|
|
624
|
+
try {
|
|
625
|
+
copyFileSync(sidecar, `${targetDb}${suffix}`);
|
|
626
|
+
} catch {}
|
|
627
|
+
}
|