Skip to content

_has_shell_execution_call: RegExp .exec() and template arguments to imported helpers mark plain JavaScript as shell-executing (partial coverage, AE1 HIGH) #1071

Open

Description

@yunze7373

Summary

In javascript_tokens.py, _has_shell_execution_call() decides whether a JavaScript file has a shell-execution surface. When it returns True, javascript_template_spans() leaves every template literal in the file unresolved. The file is then reported as partially inspected, and a SKILL.md that references it gets AE1 "Incomplete referenced artifact analysis" (HIGH).

Two common, non-executing patterns make _has_shell_execution_call() return True:

  1. RegExp.prototype.exec: any member call named exec matches _SHELL_EXECUTION_CALLS, even when the receiver is a regular-expression literal.
  2. A template literal passed to an imported helper: any imported identifier that receives a template literal argument is treated as a possible executor, even when the helper is a sibling module inside the same bundle and has no execution surface.

In both cases a one-file change that keeps the program semantics identical takes a minimal skill from SAFE to CAUTION with a HIGH finding.

This looks related to, but distinct from, #884 (the printf-substitution path in static_patterns_tool_misuse). The repros below differ only in the exec call or the import, and the template literals are identical, so the deciding factor here is _has_shell_execution_call().

Environment

  • SkillSpector v2.13.4 (tag v2.13.4, commit 54824463)
  • Python 3.14.3, Windows 11
  • skillspector scan <dir> --no-llm --format json

Reproducer 1: regex literal .exec()

SKILL.md

---
name: date-format-demo
description: Formats an ISO calendar date (YYYY-MM-DD) as YYYY/MM/DD. Use when the user asks to reformat a date.
---

# Date format demo

Run `node scripts/format-date.mjs 2026-01-31` and show the printed result to the user.

scripts/format-date.mjs

export function formatDate(text) {
  const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text);
  return m ? `${m[1]}/${m[2]}/${m[3]}` : null;
}

console.log(formatDate(process.argv[2] ?? ''));

Control variant: change only the second line to const m = text.match(/^(\d{4})-(\d{2})-(\d{2})$/);.

Variant Score Recommendation Coverage Findings
/.../.exec(text) 25 MEDIUM CAUTION 50.0% (1 full, 1 partial) AE1 HIGH: scripts/format-date.mjs (partial)
text.match(/.../) 0 LOW SAFE 100.0% (2 full) none

Reproducer 2: template literal passed to an imported helper

SKILL.md

---
name: greeting-demo
description: Prints a short greeting for a given name. Use when the user asks for a greeting.
---

# Greeting demo

Run `node scripts/greet.mjs Ada` and show the printed result to the user.

scripts/format.mjs

export function formatMessage(text) {
  return text.trim();
}

scripts/greet.mjs

import { formatMessage } from './format.mjs';

console.log(formatMessage(`Hello, ${process.argv[2] ?? 'world'}`));

Control variant: define the same formatMessage function locally in greet.mjs instead of importing it.

Variant Score Recommendation Coverage Findings
imported formatMessage 25 MEDIUM CAUTION 66.7% (2 full, 1 partial) AE1 HIGH: scripts/greet.mjs (partial)
local formatMessage 0 LOW SAFE 100.0% (3 full) none

Unit-level probe

from skillspector.javascript_tokens import parse_javascript_source, _has_shell_execution_call

noop = lambda: None
def probe(src):
    return _has_shell_execution_call(parse_javascript_source(src, noop), noop)
Source (abridged) Result
const m = /^(\d{4})-(\d{2})$/.exec(t); return m ? `${m[1]}` : null; True
const m = t.match(/^(\d{4})-(\d{2})$/); return m ? `${m[1]}` : null; False
const DAY = /^(\d{4})$/; const m = DAY.exec(t); return m ? `${m[1]}` : null; True
return /^\d+$/.test(t) ? `n:${t}` : null; False
import { formatMessage } from './format.mjs'; formatMessage(`Hello, ${name}`) True
import { formatMessage } from './format.mjs'; formatMessage('Hello, ' + name) + `!` False
function formatMessage(s) { return s.trim(); } formatMessage(`Hello, ${name}`) False

Where it comes from (v2.13.4)

  • _SHELL_EXECUTION_CALLS (javascript_tokens.py:1477) includes exec. The identifier and property scan in _has_shell_execution_call() (around lines 1709-1726) returns True for any property_identifier spelled exec under a member_expression, without looking at the receiver. The member_expression callee branch (around lines 1761-1764) has the same effect.
  • The imported-callable branch (around lines 1775-1787) returns True whenever an imported identifier receives a template_string argument, or an identifier bound to one. The inline comment explains this is a deliberate fail-closed choice ("does not claim interprocedural argument-flow analysis"), and I understand the rationale.

Suggested directions

  1. Receiver-aware exec: do not treat .exec(...) as shell execution when the receiver is a regex literal node, or an identifier whose only binding is a regex literal or new RegExp(...). This keeps child_process.exec, cp.exec and unknown receivers fail-closed while removing the most common JavaScript idiom from the trigger set.
  2. Bundle-local imports: for relative imports that resolve to a file inside the scanned skill, reuse the callee module's own _has_shell_execution_call() result, or an exported-function summary, instead of assuming the worst. Imports from shell modules, packages, unresolved paths or dynamic specifiers would stay fail-closed.
  3. Report the reason: if the conservative behaviour is kept, surfacing the decisive trigger in the ledger entry would let skill authors see why a file is partial. For example, shell_surface: member "exec" at 2:41 or shell_surface: imported callable "formatMessage" received template literal.

Related: calling a function parameter (for example a Promise resolve callback) also marks the file as shell-executing through the uncertain-binding path. That is consistent with the documented intent for injected parameters, so I mention it only because it compounds with the cases above in real modules.

Workaround concern

Today the practical workarounds are to rewrite re.exec(s) as s.match(re) (fine and idiomatic), or to restructure helpers so no template literal reaches an imported function. The second pushes authors toward code shaped around the analyzer rather than toward clearer code, which seems contrary to the goal of making skills easier to analyze correctly.

Happy to test a patch or provide more cases.

Activity

  1. Varshith-Kali commented on Nov 9, 2026

    @Varshith-Kali
    Contributor

    I can take this one. _has_shell_execution_call() treats any member call named exec as shell execution without checking the receiver, so /.../.exec(text) on a regex literal scores AE1 HIGH. I will make exec receiver-aware (ignore regex-literal and regex-bound receivers, keep child_process.exec, cp.exec and unknown receivers fail-closed) with regression tests.

  2. yunze7373 commented on Nov 9, 2026

    @yunze7373
    Author

    Thanks for picking this up. I tested #1072 (550b782c) against the cases from this issue. The bound forms (const re = /.../; re.exec(...) and new RegExp(...).exec(...)) are now owned. cp.exec(...) and unknown receivers stay fail-closed. The literal form already passes on main.

    Some data for direction 2, which #1072 intentionally leaves open. I traced which return True branch fires for every .mjs file in a real ~25-module skill on the #1072 branch:

    • 14 of 19 partial files are decided by the imported-callable branch: an imported identifier receiving a template literal.
    • Several of those imports are Node core modules that cannot start processes:
    Source Result
    import fs from 'node:fs'; fs.writeFileSync('out.txt', `${x}\n`) True
    import fs from 'node:fs'; fs.writeFileSync('out.txt', String(x) + '\n') False
    import path from 'node:path'; path.join(`${d}`, 'x') True

    A narrow first step for direction 2 could be to treat default/namespace imports from non-executing Node built-ins (node:fs, node:fs/promises, node:path, node:os, node:url, node:crypto, node:util, ...) as owned receivers. child_process, vm, worker_threads and module loaders would stay fail-closed. Bundle-local relative imports could follow later.

    The remaining 5 files come from the uncertain-binding branch:

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