@blockrun/franklin 3.29.12 → 3.29.14

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.
@@ -139,19 +139,30 @@ export function classifyBashRisk(command) {
139
139
  return { level: 'normal' };
140
140
  }
141
141
  function isSegmentSafe(segment) {
142
+ // The shell strips quotes and backslash-escapes BEFORE opening a path, so a
143
+ // sensitive filename can be spliced to dodge a literal regex: `.block''run`,
144
+ // `.block"run"`, `'.blockrun'`, `.\blockrun` all resolve to `.blockrun` at the
145
+ // OS but read as non-contiguous text to a regex. Match the DENY patterns below
146
+ // against a normalized copy that mimics the shell's quote/escape removal, so no
147
+ // quoting arrangement of a wallet/secret path can reach 'safe'. (Over-matching
148
+ // here only ever prompts — it never blocks.)
149
+ const norm = segment.replace(/\\(.)/g, '$1').replace(/['"]/g, '');
150
+ // Brace expansion (`.bloc{k,}run`, `{~,}/...`, `.bloc{j..l}run`) is a 4th
151
+ // obfuscation primitive — the shell rewrites it to other words before opening
152
+ // the path, so `.blockrun`/basename literals read as non-contiguous text. Drop
153
+ // the brace metachars so the deny regexes below see the collapsed first word.
154
+ const debraced = norm.replace(/[{},]/g, '');
142
155
  // Never auto-approve a command that touches the wallet key store. Matching the
143
- // FILENAME is hopeless — it's trivially obfuscated (`.solana""-session`,
144
- // `.\solana-session`, a glob, or an unlisted key file like
145
- // solana-wallet-key2.json). So match the DIRECTORY: any reference to
146
- // ~/.blockrun forces a prompt. (The file Read/Write/Edit tools have a separate
147
- // canonicalized guard; this is the best-effort net for the shell. Over-
148
- // prompting on a stray `.blockrun` path is fine — it prompts, never blocks.)
149
- if (/\.blockrun/i.test(segment)) {
156
+ // FILENAME is hopeless — it's trivially obfuscated. So match the DIRECTORY: any
157
+ // reference to ~/.blockrun forces a prompt. (The file Read/Write/Edit tools
158
+ // have a separate canonicalized guard; this is the best-effort net for the shell.)
159
+ if (/\.blockrun/i.test(norm) || /\.blockrun/i.test(debraced)) {
150
160
  return false;
151
161
  }
152
162
  // Relative reads with no `.blockrun` in the text (e.g. the cwd is the wallet
153
163
  // dir): match the known key/secret basenames broadly (any *wallet*.json/.key).
154
- if (/(?<![\w-])(?:\.solana-session(?:-key2)?|\.session|[\w-]*wallet[\w-]*\.(?:json|key))(?![\w-])/i.test(segment)) {
164
+ const keyBasename = /(?<![\w-])(?:\.solana-session(?:-key2)?|\.session|[\w-]*wallet[\w-]*\.(?:json|key))(?![\w-])/i;
165
+ if (keyBasename.test(norm) || keyBasename.test(debraced)) {
155
166
  return false;
156
167
  }
157
168
  // Command/process substitution runs an arbitrary INNER command the classifier
@@ -159,6 +170,14 @@ function isSegmentSafe(segment) {
159
170
  if (/\$\(|`|<\(|>\(/.test(segment)) {
160
171
  return false;
161
172
  }
173
+ // ANSI-C (`$'\x6e'`) and locale (`$"..."`) quoting decode/expand to text the
174
+ // classifier can't resolve — and which the dequote pass above can't statically
175
+ // evaluate (`~/.blockru$'\x6e'/.session` → `~/.blockrun/.session`). Match it as
176
+ // an OPENING quote (at a token boundary) or by its tell-tale escape (`$'\`), so
177
+ // a `grep 'foo$'` regex anchor — a `$` before a CLOSING quote — is left safe.
178
+ if (/(?:^|[\s=(:,])\$['"]|\$['"]\\/.test(segment)) {
179
+ return false;
180
+ }
162
181
  // Parameter expansion (`$VAR`, `${VAR}`) expands to text the classifier also
163
182
  // can't see, so a bare `$HOME` glob can reach the wallet store exactly like
164
183
  // `$(...)` — `cat $HOME/.bl*/.s*` evaded the rooted-glob guard below because it
@@ -168,10 +187,18 @@ function isSegmentSafe(segment) {
168
187
  if (/\$\{?[A-Za-z_]/.test(segment)) {
169
188
  return false;
170
189
  }
190
+ // Brace expansion with a comma list (`{a,b}`) or `..` range (`{0..9}`) fabricates
191
+ // words/paths the classifier can't statically follow — `cat {~,}/.bloc{k,}run/...`
192
+ // reaches the wallet store while every char-literal guard misses. Treat any such
193
+ // group as opaque, like `$VAR`/`$(...)`. (A brace with NO comma/`..` — `{x}`, or
194
+ // an fd-dup `2>&1` — does not expand, so it stays safe.)
195
+ if (/\{[^{}]*(?:,|\.\.)[^{}]*\}/.test(segment)) {
196
+ return false;
197
+ }
171
198
  // A glob/brace in an explicit PATH (a token rooted at ~, ., or /) expands AFTER
172
199
  // this guard and can reach the wallet store (`cat ~/.b*/.s*`) or a sensitive
173
200
  // file. Bare cwd globs (`*.md`, `src/*.ts`) have no such prefix and stay safe.
174
- if (/(?:^|\s)(?:~|\.|\/)\S*[*?[{]/.test(segment)) {
201
+ if (/(?:^|\s)(?:~|\.|\/)\S*[*?[{]/.test(norm)) {
175
202
  return false;
176
203
  }
177
204
  // Output redirection to a FILE target is a write — block it for EVERY segment,
@@ -186,13 +213,27 @@ function isSegmentSafe(segment) {
186
213
  // dangerous-path block so `cat ~/.ssh/id_rsa`, `cat ~/.aws/credentials`,
187
214
  // `cat ~/.gnupg/secring.gpg`, gcloud tokens, `.npmrc`/`.pgpass`/`.netrc`, and
188
215
  // docker registry creds don't auto-approve secrets into model context.
189
- if (/(?:^|[\s/~'"=])\.(?:ssh|aws|gnupg|kube)(?:\/|$|['"\s])/i.test(segment))
216
+ if (/(?:^|[\s/~=])\.(?:ssh|aws|gnupg|kube)(?:\/|$|\s)/i.test(norm))
217
+ return false;
218
+ if (/\bid_(?:rsa|dsa|ecdsa|ed25519)\b/i.test(norm))
219
+ return false;
220
+ if (/(?:^|[\s/~=])\.(?:npmrc|pgpass|netrc)(?:$|\s)/i.test(norm))
221
+ return false;
222
+ if (/gcloud\/(?:credentials|access_tokens|application_default)|\.docker\/config/i.test(norm))
223
+ return false;
224
+ // Other plaintext credential / key stores a bare `cat` would dump into context.
225
+ // Denylists lag the real set of secret files, so be generous — over-prompting
226
+ // is safe. Includes the Solana CLI default keypair (`~/.config/solana/id.json`),
227
+ // a SPENDABLE wallet that lives outside Franklin's own ~/.blockrun store.
228
+ if (/(?:^|[\s/~=])\.git-credentials(?:$|\s)/i.test(norm))
229
+ return false;
230
+ if (/(?:^|[\s/~=])\.(?:bash|zsh|sh|python|node_repl|mysql|psql|irb)_history(?:$|\s)/i.test(norm))
190
231
  return false;
191
- if (/\bid_(?:rsa|dsa|ecdsa|ed25519)\b/i.test(segment))
232
+ if (/(?:git|gh)\/(?:credentials|hosts\.ya?ml|hosts\.json)\b/i.test(norm))
192
233
  return false;
193
- if (/(?:^|[\s/~'"=])\.(?:npmrc|pgpass|netrc)(?:$|['"\s])/i.test(segment))
234
+ if (/\.cargo\/credentials|rclone\/rclone\.conf|(?:^|[\s/~=])\.config\/solana(?:\/|\b)|solana\/id\.json/i.test(norm))
194
235
  return false;
195
- if (/gcloud\/(?:credentials|access_tokens|application_default)|\.docker\/config/i.test(segment))
236
+ if (/(?:keychain(?:-db)?|\.keychain)\b|\bKeychains\/|\blogins\.json\b/i.test(norm))
196
237
  return false;
197
238
  // Parse into words. An env-assignment PREFIX (`FOO=bar cmd …`) is a real
198
239
  // assignment only in the LEADING run before the command word — a later `x=y`
@@ -247,6 +288,16 @@ function isSegmentSafe(segment) {
247
288
  if (subCmd === 'remote' && /(?:^|\s)(?:add|set-url|set-head|set-branches|remove|rm|rename|prune|update)\b/.test(segment)) {
248
289
  return false;
249
290
  }
291
+ // `branch`/`tag` read by default, but their delete/rename/copy/force flags
292
+ // silently mutate refs (lose local commits). `branch -D` is already a
293
+ // dangerous-pattern; gate the rest (incl. lowercase `-d`, `-m`, `-f`) here.
294
+ // Creating a branch/tag (a bare positional) stays safe — only ref destruction prompts.
295
+ if (subCmd === 'branch' && /(?:^|\s)-(?:d|D|m|M|c|C|f)\b|(?:^|\s)--(?:delete|move|copy|force|unset-upstream)\b/.test(segment)) {
296
+ return false;
297
+ }
298
+ if (subCmd === 'tag' && /(?:^|\s)-(?:d|f)\b|(?:^|\s)--(?:delete|force)\b/.test(segment)) {
299
+ return false;
300
+ }
250
301
  return true;
251
302
  }
252
303
  // npm / yarn / pnpm / bun / npx
@@ -260,9 +311,22 @@ function isSegmentSafe(segment) {
260
311
  if (baseName === 'cargo') {
261
312
  return SAFE_CARGO_SUBCOMMANDS.has(subCmd);
262
313
  }
263
- // rtk (RTK wrapper — safe, it's a proxy)
264
- if (baseName === 'rtk')
265
- return true;
314
+ // rtk is a command REWRITER/executor, not a leaf command: `rtk <cmd>` runs
315
+ // <cmd> (e.g. `rtk git status`), and `rtk proxy <cmd>` runs it unfiltered. So
316
+ // its safety equals the WRAPPED command's — a blanket allow turned it into a
317
+ // wildcard exec hole (`rtk node evil.js` auto-approved RCE). Strip the `rtk`
318
+ // token (and a `proxy` passthrough) and recurse, like the time/nice prefix.
319
+ // Read-only meta-subcommands (gain/discover/version) stay safe.
320
+ if (baseName === 'rtk') {
321
+ const next = words[argIdx] || '';
322
+ if (next === '' || next === 'gain' || next === 'discover' || /^-/.test(next))
323
+ return true;
324
+ const restWords = words.slice(next === 'proxy' ? argIdx + 1 : argIdx);
325
+ const rest = restWords.join(' ').trim();
326
+ if (!rest)
327
+ return true;
328
+ return isSegmentSafe(rest);
329
+ }
266
330
  // `find` is read-only EXCEPT its action predicates, which execute arbitrary
267
331
  // commands or delete files (`find / -name id_rsa -exec cat {} +`, `find . -delete`).
268
332
  // Same arbitrary-exec hazard that excludes xargs — force a prompt.
@@ -35,6 +35,14 @@ export function isBlockedSsrfHost(hostname) {
35
35
  return true; // loopback / unspecified
36
36
  if (h.startsWith('fe80:') || h.startsWith('fc') || h.startsWith('fd'))
37
37
  return true; // link-local / ULA
38
+ // 6to4 (`2002:WWXX:YYZZ::/16`) embeds an IPv4 (W.X.Y.Z) in the first two
39
+ // hextets; a 6to4 relay routes to it (e.g. 2002:7f00:1:: → 127.0.0.1,
40
+ // 2002:a9fe:a9fe:: → 169.254.169.254). Decode and recheck the embedded v4.
41
+ const sixToFour = h.match(/^2002:([0-9a-f]{1,4}):([0-9a-f]{1,4}):/);
42
+ if (sixToFour) {
43
+ const hi = parseInt(sixToFour[1], 16), lo = parseInt(sixToFour[2], 16);
44
+ return isBlockedSsrfHost(`${(hi >>> 8) & 255}.${hi & 255}.${(lo >>> 8) & 255}.${lo & 255}`);
45
+ }
38
46
  // NAT64 (`64:ff9b::a.b.c.d` / `64:ff9b::hhhh:hhhh`) embeds an IPv4 that a NAT64
39
47
  // gateway routes to — decode and recheck it like the IPv4-mapped form below.
40
48
  const nat64 = h.match(/^64:ff9b::(.+)$/);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/franklin",
3
- "version": "3.29.12",
3
+ "version": "3.29.14",
4
4
  "description": "Franklin Agent — The AI agent with a wallet. Spends USDC autonomously to get real work done. Pay per action, no subscriptions.",
5
5
  "type": "module",
6
6
  "exports": {