@blockrun/franklin 3.29.12 → 3.29.13

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,24 @@ 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, '');
142
150
  // 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)) {
151
+ // FILENAME is hopeless — it's trivially obfuscated. So match the DIRECTORY: any
152
+ // reference to ~/.blockrun forces a prompt. (The file Read/Write/Edit tools
153
+ // have a separate canonicalized guard; this is the best-effort net for the shell.)
154
+ if (/\.blockrun/i.test(norm)) {
150
155
  return false;
151
156
  }
152
157
  // Relative reads with no `.blockrun` in the text (e.g. the cwd is the wallet
153
158
  // 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)) {
159
+ if (/(?<![\w-])(?:\.solana-session(?:-key2)?|\.session|[\w-]*wallet[\w-]*\.(?:json|key))(?![\w-])/i.test(norm)) {
155
160
  return false;
156
161
  }
157
162
  // Command/process substitution runs an arbitrary INNER command the classifier
@@ -159,6 +164,14 @@ function isSegmentSafe(segment) {
159
164
  if (/\$\(|`|<\(|>\(/.test(segment)) {
160
165
  return false;
161
166
  }
167
+ // ANSI-C (`$'\x6e'`) and locale (`$"..."`) quoting decode/expand to text the
168
+ // classifier can't resolve — and which the dequote pass above can't statically
169
+ // evaluate (`~/.blockru$'\x6e'/.session` → `~/.blockrun/.session`). Match it as
170
+ // an OPENING quote (at a token boundary) or by its tell-tale escape (`$'\`), so
171
+ // a `grep 'foo$'` regex anchor — a `$` before a CLOSING quote — is left safe.
172
+ if (/(?:^|[\s=(:,])\$['"]|\$['"]\\/.test(segment)) {
173
+ return false;
174
+ }
162
175
  // Parameter expansion (`$VAR`, `${VAR}`) expands to text the classifier also
163
176
  // can't see, so a bare `$HOME` glob can reach the wallet store exactly like
164
177
  // `$(...)` — `cat $HOME/.bl*/.s*` evaded the rooted-glob guard below because it
@@ -171,7 +184,7 @@ function isSegmentSafe(segment) {
171
184
  // A glob/brace in an explicit PATH (a token rooted at ~, ., or /) expands AFTER
172
185
  // this guard and can reach the wallet store (`cat ~/.b*/.s*`) or a sensitive
173
186
  // file. Bare cwd globs (`*.md`, `src/*.ts`) have no such prefix and stay safe.
174
- if (/(?:^|\s)(?:~|\.|\/)\S*[*?[{]/.test(segment)) {
187
+ if (/(?:^|\s)(?:~|\.|\/)\S*[*?[{]/.test(norm)) {
175
188
  return false;
176
189
  }
177
190
  // Output redirection to a FILE target is a write — block it for EVERY segment,
@@ -186,13 +199,27 @@ function isSegmentSafe(segment) {
186
199
  // dangerous-path block so `cat ~/.ssh/id_rsa`, `cat ~/.aws/credentials`,
187
200
  // `cat ~/.gnupg/secring.gpg`, gcloud tokens, `.npmrc`/`.pgpass`/`.netrc`, and
188
201
  // docker registry creds don't auto-approve secrets into model context.
189
- if (/(?:^|[\s/~'"=])\.(?:ssh|aws|gnupg|kube)(?:\/|$|['"\s])/i.test(segment))
202
+ if (/(?:^|[\s/~=])\.(?:ssh|aws|gnupg|kube)(?:\/|$|\s)/i.test(norm))
203
+ return false;
204
+ if (/\bid_(?:rsa|dsa|ecdsa|ed25519)\b/i.test(norm))
205
+ return false;
206
+ if (/(?:^|[\s/~=])\.(?:npmrc|pgpass|netrc)(?:$|\s)/i.test(norm))
190
207
  return false;
191
- if (/\bid_(?:rsa|dsa|ecdsa|ed25519)\b/i.test(segment))
208
+ if (/gcloud\/(?:credentials|access_tokens|application_default)|\.docker\/config/i.test(norm))
192
209
  return false;
193
- if (/(?:^|[\s/~'"=])\.(?:npmrc|pgpass|netrc)(?:$|['"\s])/i.test(segment))
210
+ // Other plaintext credential / key stores a bare `cat` would dump into context.
211
+ // Denylists lag the real set of secret files, so be generous — over-prompting
212
+ // is safe. Includes the Solana CLI default keypair (`~/.config/solana/id.json`),
213
+ // a SPENDABLE wallet that lives outside Franklin's own ~/.blockrun store.
214
+ if (/(?:^|[\s/~=])\.git-credentials(?:$|\s)/i.test(norm))
194
215
  return false;
195
- if (/gcloud\/(?:credentials|access_tokens|application_default)|\.docker\/config/i.test(segment))
216
+ if (/(?:^|[\s/~=])\.(?:bash|zsh|sh|python|node_repl|mysql|psql|irb)_history(?:$|\s)/i.test(norm))
217
+ return false;
218
+ if (/(?:git|gh)\/(?:credentials|hosts\.ya?ml|hosts\.json)\b/i.test(norm))
219
+ return false;
220
+ if (/\.cargo\/credentials|rclone\/rclone\.conf|(?:^|[\s/~=])\.config\/solana(?:\/|\b)|solana\/id\.json/i.test(norm))
221
+ return false;
222
+ if (/(?:keychain(?:-db)?|\.keychain)\b|\bKeychains\/|\blogins\.json\b/i.test(norm))
196
223
  return false;
197
224
  // Parse into words. An env-assignment PREFIX (`FOO=bar cmd …`) is a real
198
225
  // assignment only in the LEADING run before the command word — a later `x=y`
@@ -247,6 +274,16 @@ function isSegmentSafe(segment) {
247
274
  if (subCmd === 'remote' && /(?:^|\s)(?:add|set-url|set-head|set-branches|remove|rm|rename|prune|update)\b/.test(segment)) {
248
275
  return false;
249
276
  }
277
+ // `branch`/`tag` read by default, but their delete/rename/copy/force flags
278
+ // silently mutate refs (lose local commits). `branch -D` is already a
279
+ // dangerous-pattern; gate the rest (incl. lowercase `-d`, `-m`, `-f`) here.
280
+ // Creating a branch/tag (a bare positional) stays safe — only ref destruction prompts.
281
+ if (subCmd === 'branch' && /(?:^|\s)-(?:d|D|m|M|c|C|f)\b|(?:^|\s)--(?:delete|move|copy|force|unset-upstream)\b/.test(segment)) {
282
+ return false;
283
+ }
284
+ if (subCmd === 'tag' && /(?:^|\s)-(?:d|f)\b|(?:^|\s)--(?:delete|force)\b/.test(segment)) {
285
+ return false;
286
+ }
250
287
  return true;
251
288
  }
252
289
  // npm / yarn / pnpm / bun / npx
@@ -260,9 +297,22 @@ function isSegmentSafe(segment) {
260
297
  if (baseName === 'cargo') {
261
298
  return SAFE_CARGO_SUBCOMMANDS.has(subCmd);
262
299
  }
263
- // rtk (RTK wrapper — safe, it's a proxy)
264
- if (baseName === 'rtk')
265
- return true;
300
+ // rtk is a command REWRITER/executor, not a leaf command: `rtk <cmd>` runs
301
+ // <cmd> (e.g. `rtk git status`), and `rtk proxy <cmd>` runs it unfiltered. So
302
+ // its safety equals the WRAPPED command's — a blanket allow turned it into a
303
+ // wildcard exec hole (`rtk node evil.js` auto-approved RCE). Strip the `rtk`
304
+ // token (and a `proxy` passthrough) and recurse, like the time/nice prefix.
305
+ // Read-only meta-subcommands (gain/discover/version) stay safe.
306
+ if (baseName === 'rtk') {
307
+ const next = words[argIdx] || '';
308
+ if (next === '' || next === 'gain' || next === 'discover' || /^-/.test(next))
309
+ return true;
310
+ const restWords = words.slice(next === 'proxy' ? argIdx + 1 : argIdx);
311
+ const rest = restWords.join(' ').trim();
312
+ if (!rest)
313
+ return true;
314
+ return isSegmentSafe(rest);
315
+ }
266
316
  // `find` is read-only EXCEPT its action predicates, which execute arbitrary
267
317
  // commands or delete files (`find / -name id_rsa -exec cat {} +`, `find . -delete`).
268
318
  // Same arbitrary-exec hazard that excludes xargs — force a prompt.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/franklin",
3
- "version": "3.29.12",
3
+ "version": "3.29.13",
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": {