Skip to content

_has_shell_execution_call: identifiers in parameter default values are recorded as uncertain bindings (later ordinary calls mark the file shell-executing) #1074

Closed

Description

@yunze7373

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

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:

  • left of assignment_pattern
  • identifiers in object_pattern / array_pattern
  • rest_pattern targets

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).

Activity

  1. Varshith-Kali commented on Nov 9, 2026

    @Varshith-Kali
    Contributor

    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.

  2. yunze7373 commented on Nov 9, 2026

    @yunze7373
    Author

    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): a is 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions