_has_shell_execution_call: identifiers in parameter default values are recorded as uncertain bindings (later ordinary calls mark the file shell-executing)
Summary
_has_shell_execution_call() in javascript_tokens.py treats every identifier inside formal_parameters as an uncertain binding. That includes identifiers that appear only in a parameter's default-value expression. Those identifiers are references, not bindings.
As a result, a later ordinary call to the same name, such as Number(value) or a local helper, is treated as a call through an unknown callable. The file is marked as having a shell-execution surface, its template literals stay unresolved, and the file is reported as partially inspected (static_parse_limit, leading to AE1 HIGH when referenced from SKILL.md).
Environment
- SkillSpector v2.13.4 (tag
v2.13.4). Also reproduces onmainate48d771aand on the branch of #1072 (550b782c). --no-llm
End-to-end reproducer (on main at e48d771a)
SKILL.md
---
name: limit-check-demo
description: Checks whether a number is within a limit. Use when the user asks to validate a count.
---
# Limit check demo
Run `node scripts/check.mjs 42` and show the printed result to the user.
scripts/check.mjs
export function check(value, max = Number.MAX_SAFE_INTEGER) {
const n = Number(value);
return n <= (max ?? Number.MAX_SAFE_INTEGER) ? `ok: ${n}` : `too large: ${n}`;
}
console.log(check(process.argv[2] ?? '0'));
Control variant: change only the signature to check(value, max).
| Variant | Score | Recommendation | Coverage | Findings |
|---|---|---|---|---|
max = Number.MAX_SAFE_INTEGER |
25 MEDIUM | CAUTION | 50.0% | AE1 HIGH: scripts/check.mjs (partial) |
max (no default) |
0 LOW | SAFE | 100.0% | none |
Unit-level reproducer
| Source | _has_shell_execution_call |
|---|---|
export function f(v, max = Number.MAX_SAFE_INTEGER) { const n = Number(v); return n > max ? null : `n=${n}`; } |
True |
export function f(v, max) { const n = Number(v); return n > max ? null : `n=${n}`; } |
False |
function defaultPath() { return 'a.json'; } export function load(p = defaultPath()) { return `${p}:${defaultPath()}`; } |
True |
function defaultPath() { return 'a.json'; } export function load(p) { return `${p ?? defaultPath()}`; } |
False |
from skillspector.javascript_tokens import parse_javascript_source, _has_shell_execution_call
noop = lambda: None
probe = lambda src: _has_shell_execution_call(parse_javascript_source(src, noop), noop)
Cause
In the first loop of _has_shell_execution_call(), a formal_parameters node sets target = node. The fallback walk then adds every identifier and shorthand_property_identifier_pattern under it to uncertain_bindings. For max = Number.MAX_SAFE_INTEGER (an assignment_pattern), the walk also visits the right side, so Number becomes an uncertain binding. In the second loop, Number(v) then hits the origin.id in callable_ids and name in uncertain_bindings branch.
Suggested fix
When walking parameter patterns, collect only binding positions:
leftofassignment_pattern- identifiers in
object_pattern/array_pattern rest_patterntargets
Do not descend into default-value expressions (the right of assignment_pattern). The default-value expression can still be analysed as ordinary code by the second loop.
Related: #1071 (same function, different trigger).
Hi, I would like to take this one on. I can reproduce the false AE1 HIGH on parameter default values and fix _has_shell_execution_call to collect only binding positions in parameter patterns, with regression tests for both reproducers. Please let me know if you would prefer a different approach.
Sounds good, go for it. Your approach is what I had in mind.
A few cases I'd throw into the tests while you're there:
- defaults inside destructuring:
function f({ limit = Number.MAX_SAFE_INTEGER } = {}),function f([first = defaultValue()] = []) - arrow functions and class methods with defaults
function f(a, b = a):ais still a real parameter- the default expression itself should still be checked, so something like
function f(p = cp.exec(`ls ${dir}`))should keep failing closed
I can re-run my original repros against your branch once it's up.