Skip to content

static_parse_limit: a backtick template literal whose first word holds a non-trivial ${...} is read as a possible printf substitution #884

Open

Description

@KazunoriNakajima

Corrected below. The "Narrowing" and "Where it comes from" sections
of this report are wrong: it is not a span bound, and the trigger is not
the call expression. See the follow-up comments for the traced chain and
the real condition. The Impact section's "0 findings" was also my own
misreading. The reproducer still reproduces.

Summary

A single ordinary TypeScript template literal makes static_patterns_tool_misuse report static_parse_limit, so the file counts as partially inspected. The trigger is narrow and fully deterministic: a backtick-delimited template literal whose ${...} interpolation contains a call expression.

This is the same analyzer and reason code as #694 and #628, but a different and much narrower trigger: the backticks here are balanced, the file is valid TypeScript, and the deciding factor is the ( inside the interpolation rather than a stray backtick running to EOF. Filing separately so the JS/TS case doesn't get lost; close as a duplicate if you'd rather fold it into #694.

Versions: reproduces on v2.11.2 and v2.13.0. Linux, Python 3.12, --no-llm.

Reproducer

Two files:

skill/SKILL.md

---
name: template-literal-repro
description: Minimal reproducer for a TypeScript template literal tripping the bounded shell parser.
---

This skill does nothing. It exists only to carry the TypeScript file next to it.

skill/hook.ts — one line, no shell, no commands:

export const label = (n: number): string => `${format(n)}`
skillspector scan skill --no-llm --format json --output r.json

Actual

{
  "total_components": 2,
  "scanned_components": 1,
  "coverage_percent": 50.0,
  "is_complete": false,
  "status": "partial",
  "partially_inspected_files": 1,
  "ledger_exceptions": [
    {
      "outcome": "partial",
      "phase": "static",
      "reason_code": "static_parse_limit",
      "message": "A security-relevant expression exceeded a bounded static parser's span limit.",
      "path": "hook.ts",
      "analyzers": ["static_patterns_tool_misuse"]
    }
  ]
}

Narrowing

Calling static_patterns_tool_misuse.has_bounded_parse_exhaustion(text, lambda: None) directly:

Input Result
`${a}:${b}` ok
`${f(1)}` exhausted
`${a.b()}` exhausted
`${a}(${b})` ok
`plain (parens) no interpolation` ok
'${f(1)}' ok
"${f(1)}" ok

So all three of these must coincide: backtick delimiters, ${...} interpolation, and a ( inside the interpolation. Single- and double-quoted strings with identical contents are fine, which is what points at the backtick being read as a shell command substitution.

Where it comes from

has_bounded_parse_exhaustion is reached through _SHELL_COMMAND_WORD_START_RE, which lists the backtick as a command-word start character. The bounded word parser then treats the template literal as a shell backtick substitution, reads ${...} as a shell parameter expansion, and the ( inside leaves the bounded parameter-expansion scan without an end, which surfaces as static_parse_limit.

A template literal is not shell syntax, so for .ts/.tsx/.js/.jsx the backtick probably shouldn't seed a shell command word at all. (The same reasoning appears in #694's "Expected" section for Rust and Python.)

Impact

`${f(x)}` is everyday TypeScript — string formatting, logging, path building. In practice this means a TS/JS codebase cannot reach complete analysis.

Measured on a real plugin, a Claude Code hooks package of 80 files:

  • 25 of 80 files flagged, all of them this pattern, e.g.
    • `${trimZero((n / 1000).toFixed(1))}k`
    • `${one.slice(0, max - 1)}…`
    • `${row}:${index}:${backdrop ?? 'none'}:${whole ? 'whole' : 'part'}`
  • Reported coverage 67.5%, is_complete: false
  • 0 findings — nothing was actually detected; the package simply can't be certified

Dropping the test directory makes the ratio worse (19 of 57), because the flagged files are the library sources. File size and line length are not the discriminator: a 49 KB file and a 1139-column file both pass, while an 11 KB file fails.

The 13 other static analyzers complete 79 of 80 files on the same package, so a single analyzer's parse bound decides the completeness number for the whole scan.

Our marketplace gates distribution on completeness, so this currently blocks an entire language ecosystem rather than one package. Happy to test a fix.

Activity

  1. KazunoriNakajima commented on Oct 20, 2026

    @KazunoriNakajima
    Author

    Two follow-ups on the Impact section.

    Correction. I wrote "0 findings — nothing was actually detected". That was wrong, and the mistake was mine, not the scanner's. A run that stops on insufficient coverage returns before classification, so its summary has empty counts; I read that emptiness as "nothing found". Classifying the saved result gives 24 findings on that package (9 HIGH). The rest of the report is unaffected — the 25 files are still flagged by the parse bound alone, and the package still cannot reach complete analysis.

    Extra evidence, per file. Rather than eyeballing the pattern, I ran static_patterns_tool_misuse.has_bounded_parse_exhaustion over all 80 files of that package under v2.11.2:

    • it reports exhaustion on exactly the 25 files the ledger flags — no more, no fewer
    • feeding the same contents back with every backtick replaced by a single quote clears all 25

    So for this package the backtick is the whole cause, with nothing else contributing. All 25 are .ts/.tsx; none is a shell script.

    Happy to test a patch.

  2. KazunoriNakajima commented on Oct 20, 2026

    @KazunoriNakajima
    Author

    I traced this through v2.11.2 and my "Where it comes from" section is wrong on both points. Posting the correction since it changes what a fix would have to address.

    It is not a span bound

    _skip_backtick_substitution finds the closing backtick without trouble, and the input is nine characters, so nothing is running out of budget. The chain is:

    1 _SHELL_COMMAND_WORD_START_RE (L44) the backtick is a command-word start character, so the template literal is read as a backtick substitution
    2 _parse_shell_command_word (L1337) the closing backtick is found — fine so far
    3 same, L1357 _is_printf_substitution: could this substitution invoke printf? (printf output is evaluated statically so a destructive command cannot hide behind it)
    4 _invocation_expansion_marker (L802) the command word is ${...}. Anything _SIMPLE_BRACED_PARAMETER_RE (L57) does not match — i.e. anything other than ${NAME}, ${1}, ${@} — is treated as a complex expansion that may nest a command substitution, and gets _DYNAMIC_SHELL_WORD_SENTINEL
    5 _consume_printf_invocation (L706) sees that sentinel and returns (recognized=True, exact=False) — "could be printf, basename not determinable"
    6 back at L1357 limited = True → static_parse_limit

    So it is a deliberate fail-closed answer — I cannot rule out that this is printf — reached on input that was never shell. The parse bound itself behaves correctly.

    The trigger is wider than a call expression

    I said the deciding factor was the ( inside the interpolation. It is not. Two conditions:

    1. the first whitespace-delimited word of the literal contains a ${...}, and
    2. that ${} is not a bare identifier
    `${a}`          ok        `${a.b}`        exhausted   <- no call at all
    `${a}:${b}`     ok        `${ a }`        exhausted   <- just a space
    `${a}${b}`      ok        `${a ?? b}`     exhausted
    `plain text`    ok        `${arr[0]}`     exhausted
    '${f(1)}'       ok        `${f(1)}`       exhausted
    
    `text ${a.b}`                  ok          <- word ends at the space
    `done in ${ms.toFixed(1)}ms`   ok
    `x${a.b}` / `/path/${a.b}` / `${a}-${b.c}`     exhausted
    // a comment containing `${x.y}`               exhausted   <- no language syntax is parsed
    

    In practice what trips it is a template literal that builds a path, an id or a formatted scalar with no leading space: `${row}:${index}`, `${n}k`, `/api/${id}`. All 25 files in the package I measured are of that shape.

    This also means a fix that only skips call expressions would still leave `${a.b}` and `/api/${id}` flagged. Not seeding a shell command word from a backtick in .ts/.tsx/.js/.jsx would cover all of them.

  3. changed the title [-]static_parse_limit: a TypeScript template literal with a call in its interpolation marks the file partially inspected[/-] [+]static_parse_limit: a backtick template literal whose first word holds a non-trivial ${...} is read as a possible printf substitution[/+] on Oct 20, 2026
  4. esarav commented on Nov 6, 2026

    @esarav

    Also reproduces on v2.13.3 for JavaScript inside an HTML file's inline <script>, not only .ts. Minimal case:

    <script>
    const t = label('Rows',`${rows.length} rows`);
    </script>

    has_bounded_parse_exhaustion returns True. ${count} in place of ${rows.length}, or rows.length+' rows', returns False. In a full scan (--no-llm), static_patterns_tool_misuse reports degraded with static_parse_limit on the .html file; the other two variants scan complete.

    #990 scopes the fix to .ts/.tsx, so .js, .jsx and inline <script> blocks in .html stay affected. We hit this on a real skill bundle (a generated HTML dashboard), and the only workaround was rewriting every nested template string as + joins.

  5. lucas-saldanha-werneck commented on Nov 13, 2026

    @lucas-saldanha-werneck

    More real-world cases of this trigger, all ordinary TypeScript in Claude Code plugin hook modules (--no-llm, static_patterns_tool_misuse, static_parse_limit, parser_diagnostic.check = printf_invocation, cause = runtime_dependent). The reported span is exactly the template literal's first word:

    File (permalink) Reported span
    assumptions-pane hooks/register.tsx#L58 mcp__${$.plugin.name}__${name}
    idea-shelf hooks/register.tsx#L140 ${SHELF}${Number.MAX_SAFE_INTEGER}:${cwd}
    side-notes hooks/register.tsx#L202 ${key}:${await $.session.cwd()}
    side-stack hooks/register.tsx#L393 ${++i} · ${n}${shown(n) ? '' : ' (not shown)'}
    plan-checklist hooks/register.tsx#L129 s${Date.now().toString(36)}${(idCounter++).toString(36)}

    So the trigger also covers member access ($.plugin.name, Number.MAX_SAFE_INTEGER), await, prefix ++ and a ternary in the first word, not only call expressions.

    Checked on main at 17c4d38 and on #990's head at a2c6aae (scanning each plugin root): #990 clears the printf_invocation case in plan-checklist's hooks/plan.ts, but all five spans above still report static_parse_limit there. Each plugin's tests/*.test.tsx has the same pattern (for example mcp__assumptions-pane__${e.name}). Happy to retest a later head.

  6. agam-am-duggal commented on Nov 17, 2026

    @agam-am-duggal

    Another real-world case, with two details that may help.

    1. The trigger also fires inside a fenced typescript block in a Markdown reference file, not only in a .ts source file.

    Minimal reproducer on v2.12.0 (macOS, Python 3.12, --no-llm):

    SKILL.md

    ---
    name: ts-template-repro
    description: Shows how to call an upstream API from a TypeScript server. Use when writing a TypeScript API client.
    ---
    
    # TypeScript API client
    
    Follow the pattern in the [TypeScript guide](./reference/guide.md).

    reference/guide.md

    # Guide
    
    Fetch a user like this:
    
    ```typescript
    async function getUser(user_id: string) {
      const raw = await apiRequest<unknown>(`users/${encodeURIComponent(user_id)}`, {});
      return raw;
    }
    ```

    Result: reference/guide.md is partial with static_parse_limit, parser_diagnostic.check = printf_invocation, start_line = 7; coverage 50%; one AE1 HIGH on the link in SKILL.md.

    2. On a public skill it adds four HIGH findings from one line.

    anthropics/skills mcp-builder/reference/node_mcp_server_v2.md#L461 holds the same pattern in a documentation sample. The reported span is users/${encodeURIComponent(user_id)}. SKILL.md links to that file four times and each link gets its own AE1 HIGH. Two other reference files in the skill are also partial (expansion_boundary, command_word_boundary), and together the scan reports 10 analysis-evasion findings and ends at score 100, DO_NOT_INSTALL. Without the coverage findings the skill has 1 HIGH, 12 MEDIUM and 4 LOW.

    Found while wrapping SkillSpector as the static tier of a skill evaluator. We now read analysis_completeness separately from the security findings, which works around it on our side.

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