@askalf/dario 3.31.15 → 3.31.16
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/accounts.js +15 -10
- package/dist/oauth.js +14 -8
- package/dist/open-browser.d.ts +52 -0
- package/dist/open-browser.js +68 -0
- package/dist/proxy.js +5 -6
- package/dist/redact.d.ts +28 -0
- package/dist/redact.js +38 -0
- package/package.json +2 -1
package/dist/accounts.js
CHANGED
|
@@ -23,6 +23,8 @@ import { randomUUID, randomBytes, createHash } from 'node:crypto';
|
|
|
23
23
|
import { createServer } from 'node:http';
|
|
24
24
|
import { detectCCOAuthConfig } from './cc-oauth-detect.js';
|
|
25
25
|
import { loadCredentials } from './oauth.js';
|
|
26
|
+
import { openBrowser } from './open-browser.js';
|
|
27
|
+
import { redactSecrets } from './redact.js';
|
|
26
28
|
const DARIO_DIR = join(homedir(), '.dario');
|
|
27
29
|
const ACCOUNTS_DIR = join(DARIO_DIR, 'accounts');
|
|
28
30
|
/**
|
|
@@ -161,7 +163,10 @@ async function doRefreshAccountToken(creds) {
|
|
|
161
163
|
});
|
|
162
164
|
if (!res.ok) {
|
|
163
165
|
const errBody = await res.text().catch(() => '');
|
|
164
|
-
|
|
166
|
+
// Redact tokens / JWTs / Bearer values before they hit the Error
|
|
167
|
+
// message — defense-in-depth against an upstream that ever echoes a
|
|
168
|
+
// credential into a 4xx body. See src/redact.ts.
|
|
169
|
+
throw new Error(`Refresh failed for ${creds.alias} (${res.status}): ${redactSecrets(errBody.slice(0, 200))}`);
|
|
165
170
|
}
|
|
166
171
|
const data = await res.json();
|
|
167
172
|
const updated = {
|
|
@@ -186,13 +191,10 @@ function generatePKCE() {
|
|
|
186
191
|
const codeChallenge = base64url(createHash('sha256').update(codeVerifier).digest());
|
|
187
192
|
return { codeVerifier, codeChallenge };
|
|
188
193
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
: `xdg-open "${url}"`;
|
|
194
|
-
exec(cmd, () => { });
|
|
195
|
-
}
|
|
194
|
+
// `openBrowser` lives in src/open-browser.ts — uses execFile + argv array
|
|
195
|
+
// + URL-protocol allowlist instead of shell interpolation. The previous
|
|
196
|
+
// inline `exec(\`start "" "${url}"\`)` pattern would have shelled out
|
|
197
|
+
// any `&` / `|` / `^` / backtick / `$()` in a URL.
|
|
196
198
|
/**
|
|
197
199
|
* Interactive OAuth flow that adds a new account to the pool. Uses dario's
|
|
198
200
|
* auto-detected CC OAuth config (same scanner the single-account path uses).
|
|
@@ -256,7 +258,7 @@ export async function addAccountViaOAuth(alias) {
|
|
|
256
258
|
});
|
|
257
259
|
if (!tokenRes.ok) {
|
|
258
260
|
const body = await tokenRes.text().catch(() => '');
|
|
259
|
-
throw new Error(`Token exchange failed (${tokenRes.status}): ${body.slice(0, 200)}`);
|
|
261
|
+
throw new Error(`Token exchange failed (${tokenRes.status}): ${redactSecrets(body.slice(0, 200))}`);
|
|
260
262
|
}
|
|
261
263
|
const tokens = await tokenRes.json();
|
|
262
264
|
// Prefer CC identity if installed; otherwise generate fresh IDs.
|
|
@@ -299,7 +301,10 @@ export async function addAccountViaOAuth(alias) {
|
|
|
299
301
|
console.log(` If the browser didn't open, visit:`);
|
|
300
302
|
console.log(` ${authUrl}`);
|
|
301
303
|
console.log();
|
|
302
|
-
|
|
304
|
+
try {
|
|
305
|
+
openBrowser(authUrl);
|
|
306
|
+
}
|
|
307
|
+
catch { /* non-fatal: user has the URL printed above */ }
|
|
303
308
|
});
|
|
304
309
|
server.on('error', (err) => {
|
|
305
310
|
reject(new Error(`Failed to start OAuth callback server: ${err.message}`));
|
package/dist/oauth.js
CHANGED
|
@@ -11,6 +11,7 @@ import { execFile } from 'node:child_process';
|
|
|
11
11
|
import { dirname, join } from 'node:path';
|
|
12
12
|
import { homedir, platform } from 'node:os';
|
|
13
13
|
import { detectCCOAuthConfig } from './cc-oauth-detect.js';
|
|
14
|
+
import { redactSecrets } from './redact.js';
|
|
14
15
|
// Manual-flow redirect URI. Anthropic's authorize endpoint special-cases
|
|
15
16
|
// this value (also baked into CC as MANUAL_REDIRECT_URL) to render the
|
|
16
17
|
// authorization code + state on a copy-paste success page instead of
|
|
@@ -255,12 +256,15 @@ export async function startAutoOAuthFlow() {
|
|
|
255
256
|
console.log(' Opening browser to sign in...');
|
|
256
257
|
console.log(` If the browser didn't open, visit: ${authUrl}`);
|
|
257
258
|
console.log('');
|
|
258
|
-
//
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
259
|
+
// Hardened: openBrowser uses execFile + argv array + URL protocol
|
|
260
|
+
// allowlist. Previous inline `exec(\`start "" "${authUrl}"\`)`
|
|
261
|
+
// would have shelled out any `&` / `|` / `^` / backtick / `$()` in
|
|
262
|
+
// a URL — see src/open-browser.ts.
|
|
263
|
+
const { openBrowser } = await import('./open-browser.js');
|
|
264
|
+
try {
|
|
265
|
+
openBrowser(authUrl);
|
|
266
|
+
}
|
|
267
|
+
catch { /* non-fatal: user has the URL printed above */ }
|
|
264
268
|
});
|
|
265
269
|
server.on('error', (err) => {
|
|
266
270
|
reject(new Error(`Failed to start OAuth callback server: ${err.message}`));
|
|
@@ -429,7 +433,9 @@ async function exchangeCodeManual(code, codeVerifier, state) {
|
|
|
429
433
|
});
|
|
430
434
|
if (!res.ok) {
|
|
431
435
|
const body = await res.text().catch(() => '');
|
|
432
|
-
|
|
436
|
+
// See src/redact.ts — strip tokens / JWTs / Bearer values from upstream
|
|
437
|
+
// body before they surface in the Error message.
|
|
438
|
+
throw new Error(`Token exchange failed (HTTP ${res.status}): ${redactSecrets(body.slice(0, 200))}`);
|
|
433
439
|
}
|
|
434
440
|
const data = await res.json();
|
|
435
441
|
const tokens = {
|
|
@@ -490,7 +496,7 @@ async function doRefreshTokens() {
|
|
|
490
496
|
});
|
|
491
497
|
if (!res.ok) {
|
|
492
498
|
const errBody = await res.text().catch(() => '');
|
|
493
|
-
console.error(`[dario] Refresh attempt ${attempt + 1}/3 failed: HTTP ${res.status} — ${errBody.slice(0, 200)}`);
|
|
499
|
+
console.error(`[dario] Refresh attempt ${attempt + 1}/3 failed: HTTP ${res.status} — ${redactSecrets(errBody.slice(0, 200))}`);
|
|
494
500
|
if (res.status === 401 || res.status === 403) {
|
|
495
501
|
throw new Error(`Refresh token rejected (${res.status}). Run \`dario login\` to re-authenticate.`);
|
|
496
502
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe URL → default-browser dispatch.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the inline `child_process.exec` template-string patterns that
|
|
5
|
+
* previously lived in `src/oauth.ts` and `src/accounts.ts`. Those used
|
|
6
|
+
* shell interpolation of an external URL (`exec(\`start "" "${url}"\`)`,
|
|
7
|
+
* `exec(\`xdg-open "${url}"\`)`) — defense-in-depth concern: a malicious
|
|
8
|
+
* `DARIO_OAUTH_AUTHORIZE_URL` override, a backdoored `claude` binary
|
|
9
|
+
* smuggling a different `CLAUDE_AI_AUTHORIZE_URL` literal through the
|
|
10
|
+
* cc-oauth-detect scanner, or any future code path that lets a less-
|
|
11
|
+
* trusted source reach this function would inject shell metacharacters
|
|
12
|
+
* (`&`, `|`, `>`, `^`, ``$()``, backtick) and execute arbitrary commands.
|
|
13
|
+
*
|
|
14
|
+
* Hardened path:
|
|
15
|
+
* 1. Parse the URL with WHATWG `URL` — throws on malformed input.
|
|
16
|
+
* 2. Allow only `http:` and `https:` (rejects `file:`, `javascript:`,
|
|
17
|
+
* `vbscript:`, `data:`, custom schemes that route through
|
|
18
|
+
* registered URL handlers).
|
|
19
|
+
* 3. Re-serialize via `parsed.toString()` so any pre-parse oddities
|
|
20
|
+
* get normalized through the URL spec.
|
|
21
|
+
* 4. Spawn the platform's URL-handler binary directly with the URL as
|
|
22
|
+
* a single argv element — no shell, no template interpolation.
|
|
23
|
+
* Windows uses `explorer.exe` (System32 binary, accepts URLs as
|
|
24
|
+
* argv, no cmd hop) instead of `cmd /c start`, which would parse
|
|
25
|
+
* `&`/`|` as command separators after Node's argv → cmd quoting.
|
|
26
|
+
* 5. Errors from the spawned process are swallowed: a failed browser
|
|
27
|
+
* open is non-fatal because every caller also prints the URL to
|
|
28
|
+
* stdout for manual paste.
|
|
29
|
+
*
|
|
30
|
+
* Tests use the `exec` option to inject a stub.
|
|
31
|
+
*/
|
|
32
|
+
import { type ExecFileException } from 'node:child_process';
|
|
33
|
+
export interface OpenBrowserOptions {
|
|
34
|
+
/** Test hook — defaults to node:child_process execFile. */
|
|
35
|
+
exec?: (file: string, args: readonly string[], callback: (error: ExecFileException | null, stdout: string, stderr: string) => void) => void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build the (binary, argv) pair the current platform uses to dispatch a
|
|
39
|
+
* URL to its default browser. Exported for tests.
|
|
40
|
+
*/
|
|
41
|
+
export declare function browserDispatchCommand(url: string, platform?: NodeJS.Platform): {
|
|
42
|
+
bin: string;
|
|
43
|
+
args: string[];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Open `url` in the user's default browser. See module docstring.
|
|
47
|
+
*
|
|
48
|
+
* @throws if the URL is malformed or has a protocol other than http/https.
|
|
49
|
+
* Browser-launch failures (handler missing, etc.) are swallowed —
|
|
50
|
+
* every caller already prints the URL for manual paste.
|
|
51
|
+
*/
|
|
52
|
+
export declare function openBrowser(url: string, opts?: OpenBrowserOptions): void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe URL → default-browser dispatch.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the inline `child_process.exec` template-string patterns that
|
|
5
|
+
* previously lived in `src/oauth.ts` and `src/accounts.ts`. Those used
|
|
6
|
+
* shell interpolation of an external URL (`exec(\`start "" "${url}"\`)`,
|
|
7
|
+
* `exec(\`xdg-open "${url}"\`)`) — defense-in-depth concern: a malicious
|
|
8
|
+
* `DARIO_OAUTH_AUTHORIZE_URL` override, a backdoored `claude` binary
|
|
9
|
+
* smuggling a different `CLAUDE_AI_AUTHORIZE_URL` literal through the
|
|
10
|
+
* cc-oauth-detect scanner, or any future code path that lets a less-
|
|
11
|
+
* trusted source reach this function would inject shell metacharacters
|
|
12
|
+
* (`&`, `|`, `>`, `^`, ``$()``, backtick) and execute arbitrary commands.
|
|
13
|
+
*
|
|
14
|
+
* Hardened path:
|
|
15
|
+
* 1. Parse the URL with WHATWG `URL` — throws on malformed input.
|
|
16
|
+
* 2. Allow only `http:` and `https:` (rejects `file:`, `javascript:`,
|
|
17
|
+
* `vbscript:`, `data:`, custom schemes that route through
|
|
18
|
+
* registered URL handlers).
|
|
19
|
+
* 3. Re-serialize via `parsed.toString()` so any pre-parse oddities
|
|
20
|
+
* get normalized through the URL spec.
|
|
21
|
+
* 4. Spawn the platform's URL-handler binary directly with the URL as
|
|
22
|
+
* a single argv element — no shell, no template interpolation.
|
|
23
|
+
* Windows uses `explorer.exe` (System32 binary, accepts URLs as
|
|
24
|
+
* argv, no cmd hop) instead of `cmd /c start`, which would parse
|
|
25
|
+
* `&`/`|` as command separators after Node's argv → cmd quoting.
|
|
26
|
+
* 5. Errors from the spawned process are swallowed: a failed browser
|
|
27
|
+
* open is non-fatal because every caller also prints the URL to
|
|
28
|
+
* stdout for manual paste.
|
|
29
|
+
*
|
|
30
|
+
* Tests use the `exec` option to inject a stub.
|
|
31
|
+
*/
|
|
32
|
+
import { execFile } from 'node:child_process';
|
|
33
|
+
const ALLOWED_PROTOCOLS = new Set(['http:', 'https:']);
|
|
34
|
+
/**
|
|
35
|
+
* Build the (binary, argv) pair the current platform uses to dispatch a
|
|
36
|
+
* URL to its default browser. Exported for tests.
|
|
37
|
+
*/
|
|
38
|
+
export function browserDispatchCommand(url, platform = process.platform) {
|
|
39
|
+
const parsed = new URL(url);
|
|
40
|
+
if (!ALLOWED_PROTOCOLS.has(parsed.protocol)) {
|
|
41
|
+
throw new Error(`openBrowser: refusing to open URL with protocol "${parsed.protocol}" (only http/https allowed)`);
|
|
42
|
+
}
|
|
43
|
+
const safe = parsed.toString();
|
|
44
|
+
if (platform === 'win32') {
|
|
45
|
+
// explorer.exe accepts a URL as a single argv element and routes it
|
|
46
|
+
// through the registered URL handler. Avoids `cmd /c start "" "URL"`,
|
|
47
|
+
// which re-parses cmd metacharacters even when called via execFile
|
|
48
|
+
// because the cmd builtin runs *inside* cmd's parser, not Node's.
|
|
49
|
+
return { bin: 'explorer.exe', args: [safe] };
|
|
50
|
+
}
|
|
51
|
+
if (platform === 'darwin') {
|
|
52
|
+
return { bin: 'open', args: [safe] };
|
|
53
|
+
}
|
|
54
|
+
// Linux / BSD / other Unix.
|
|
55
|
+
return { bin: 'xdg-open', args: [safe] };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Open `url` in the user's default browser. See module docstring.
|
|
59
|
+
*
|
|
60
|
+
* @throws if the URL is malformed or has a protocol other than http/https.
|
|
61
|
+
* Browser-launch failures (handler missing, etc.) are swallowed —
|
|
62
|
+
* every caller already prints the URL for manual paste.
|
|
63
|
+
*/
|
|
64
|
+
export function openBrowser(url, opts = {}) {
|
|
65
|
+
const { bin, args } = browserDispatchCommand(url);
|
|
66
|
+
const exec = opts.exec ?? execFile;
|
|
67
|
+
exec(bin, args, () => { });
|
|
68
|
+
}
|
package/dist/proxy.js
CHANGED
|
@@ -13,6 +13,7 @@ import { Analytics, billingBucketFromClaim } from './analytics.js';
|
|
|
13
13
|
import { loadAllAccounts, loadAccount, refreshAccountToken } from './accounts.js';
|
|
14
14
|
import { getOpenAIBackend, isOpenAIModel, forwardToOpenAI } from './openai-backend.js';
|
|
15
15
|
import { RequestQueue, QueueFullError, QueueTimeoutError, DEFAULT_MAX_CONCURRENT, DEFAULT_MAX_QUEUED, DEFAULT_QUEUE_TIMEOUT_MS } from './request-queue.js';
|
|
16
|
+
import { redactSecrets } from './redact.js';
|
|
16
17
|
const ANTHROPIC_API = 'https://api.anthropic.com';
|
|
17
18
|
const DEFAULT_PORT = 3456;
|
|
18
19
|
const MAX_BODY_BYTES = 10 * 1024 * 1024; // 10 MB — generous for large prompts, prevents abuse
|
|
@@ -345,12 +346,10 @@ function translateStreamChunk(line) {
|
|
|
345
346
|
}
|
|
346
347
|
const OPENAI_MODELS_LIST = { object: 'list', data: ['claude-opus-4-6', 'claude-sonnet-4-6', 'claude-haiku-4-5'].map(id => ({ id, object: 'model', created: 1700000000, owned_by: 'anthropic' })) };
|
|
347
348
|
export function sanitizeError(err) {
|
|
348
|
-
|
|
349
|
-
//
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
.replace(/eyJ[a-zA-Z0-9_-]+\.eyJ[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+/g, '[REDACTED_JWT]')
|
|
353
|
-
.replace(/Bearer\s+[^\s,;]+/gi, 'Bearer [REDACTED]');
|
|
349
|
+
// Pattern set lives in src/redact.ts so OAuth call sites can run the
|
|
350
|
+
// same redaction directly on response-body strings without importing
|
|
351
|
+
// proxy (which imports oauth — would circle).
|
|
352
|
+
return redactSecrets(err instanceof Error ? err.message : String(err));
|
|
354
353
|
}
|
|
355
354
|
/**
|
|
356
355
|
* API-key auth via DARIO_API_KEY (x-api-key or Authorization: Bearer).
|
package/dist/redact.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret redaction for free-form strings emitted by dario.
|
|
3
|
+
*
|
|
4
|
+
* Used wherever an externally-sourced string (an upstream HTTP response
|
|
5
|
+
* body, an exception message, a verbose log line) might transit through
|
|
6
|
+
* to a place a user can see (stderr, an Error message, a JSON response).
|
|
7
|
+
* Even though Anthropic's documented API is not known to echo tokens in
|
|
8
|
+
* error responses, defense-in-depth: a future API change, a CDN error
|
|
9
|
+
* page that captures the request headers, or an intermediary's debug
|
|
10
|
+
* dump could surface a token, and we'd rather redact in transit than
|
|
11
|
+
* audit every call site for novel leak shapes.
|
|
12
|
+
*
|
|
13
|
+
* Patterns match formats actually seen in the Anthropic ecosystem:
|
|
14
|
+
* - `sk-ant-…` — long-lived API keys
|
|
15
|
+
* - JWT triple — OAuth access tokens (`eyJhdr.eyJpyld.sig`)
|
|
16
|
+
* - `Bearer <…>` — auth headers, raw or quoted
|
|
17
|
+
*
|
|
18
|
+
* Re-exported by `proxy.ts:sanitizeError` so the proxy's existing leak-
|
|
19
|
+
* shield benefits from any new patterns added here, and consumed
|
|
20
|
+
* directly by the OAuth code paths in `oauth.ts` / `accounts.ts` for
|
|
21
|
+
* sanitizing upstream error bodies before they hit `throw new Error`.
|
|
22
|
+
*/
|
|
23
|
+
export declare const SECRET_PATTERNS: ReadonlyArray<readonly [RegExp, string]>;
|
|
24
|
+
/**
|
|
25
|
+
* Apply every redaction pattern to a string. Idempotent — running a
|
|
26
|
+
* pre-redacted string through this is a no-op.
|
|
27
|
+
*/
|
|
28
|
+
export declare function redactSecrets(s: string): string;
|
package/dist/redact.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret redaction for free-form strings emitted by dario.
|
|
3
|
+
*
|
|
4
|
+
* Used wherever an externally-sourced string (an upstream HTTP response
|
|
5
|
+
* body, an exception message, a verbose log line) might transit through
|
|
6
|
+
* to a place a user can see (stderr, an Error message, a JSON response).
|
|
7
|
+
* Even though Anthropic's documented API is not known to echo tokens in
|
|
8
|
+
* error responses, defense-in-depth: a future API change, a CDN error
|
|
9
|
+
* page that captures the request headers, or an intermediary's debug
|
|
10
|
+
* dump could surface a token, and we'd rather redact in transit than
|
|
11
|
+
* audit every call site for novel leak shapes.
|
|
12
|
+
*
|
|
13
|
+
* Patterns match formats actually seen in the Anthropic ecosystem:
|
|
14
|
+
* - `sk-ant-…` — long-lived API keys
|
|
15
|
+
* - JWT triple — OAuth access tokens (`eyJhdr.eyJpyld.sig`)
|
|
16
|
+
* - `Bearer <…>` — auth headers, raw or quoted
|
|
17
|
+
*
|
|
18
|
+
* Re-exported by `proxy.ts:sanitizeError` so the proxy's existing leak-
|
|
19
|
+
* shield benefits from any new patterns added here, and consumed
|
|
20
|
+
* directly by the OAuth code paths in `oauth.ts` / `accounts.ts` for
|
|
21
|
+
* sanitizing upstream error bodies before they hit `throw new Error`.
|
|
22
|
+
*/
|
|
23
|
+
export const SECRET_PATTERNS = [
|
|
24
|
+
[/sk-ant-[a-zA-Z0-9_-]+/g, '[REDACTED]'],
|
|
25
|
+
[/eyJ[a-zA-Z0-9_-]+\.eyJ[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+/g, '[REDACTED_JWT]'],
|
|
26
|
+
[/Bearer\s+[^\s,;]+/gi, 'Bearer [REDACTED]'],
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Apply every redaction pattern to a string. Idempotent — running a
|
|
30
|
+
* pre-redacted string through this is a no-op.
|
|
31
|
+
*/
|
|
32
|
+
export function redactSecrets(s) {
|
|
33
|
+
let out = s;
|
|
34
|
+
for (const [pat, repl] of SECRET_PATTERNS) {
|
|
35
|
+
out = out.replace(pat, repl);
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@askalf/dario",
|
|
3
|
-
"version": "3.31.
|
|
3
|
+
"version": "3.31.16",
|
|
4
4
|
"description": "A local LLM router. One endpoint, every provider — Claude subscriptions, OpenAI, OpenRouter, Groq, local LiteLLM, any OpenAI-compat endpoint — your tools don't need to change.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"start": "node dist/cli.js",
|
|
29
29
|
"dev": "tsx src/cli.ts",
|
|
30
30
|
"e2e": "node test/e2e.mjs",
|
|
31
|
+
"stress": "node test/stress.mjs",
|
|
31
32
|
"compat": "node test/compat.mjs",
|
|
32
33
|
"lint:pkg": "node scripts/check-package-json.mjs",
|
|
33
34
|
"drift:sdk": "node scripts/check-sdk-drift.mjs",
|