Repository navigation
fix(analyzer): ignore regex .exec() when detecting shell execution - #1072
Varshith-Kali wants to merge 5 commits into
Conversation
rng1995
left a comment
There was a problem hiding this comment.
[SkillSpector Review]
Request changes at 550b782cd0dcd0543008bc3f0bc3e9cf0a009a29.
Value and readiness: Receiver-aware ownership usefully removes the bound-regex false positives in #1071, and keeping imported-helper analysis separate is appropriate. The new global-constructor proof has a security-coverage hole, so this head is not ready.
Material findings:
- [P1, required]
src/skillspector/javascript_tokens.py:1743-1746exempts every constructor-positionRegExpidentifier while checking override spellings only on identifier/property_identifier/string nodes. A local shorthand binding is a different node type: in the pinned tree-sitter-javascript 0.25.0 grammar,catch ({RegExp})binds shorthand_property_identifier_pattern. Those nodes are collected in references but never checked against override_names;_has_shell_execution_callalso does not collect catch_clause parameters as uncertain bindings. Consequentlytry { step(); } catch ({RegExp}) { const re = new RegExp(); re.exec(${command}); }lets a caught, arbitrary constructor borrow the global RegExp proof and adds its.execmember to native ownership. By static control-flow inspection, the dynamic template can then acquire complete host ownership even though this is an unknown execution surface; the old path left this.execunowned. Include shorthand binding nodes in override detection, or establish that every RegExp binding form is absent before exempting a constructor. Add negative regression controls for destructured catch (and for-of) shadowing, retaining the real global-constructor positive cases.
PIC tradeoffs: Removing false partial-analysis findings must retain fail-closed behavior for shadowed native constructors; this finding crosses that boundary.
Verification and gaps: Reviewed the complete diff and surrounding exact-head ownership, alias and template-span paths, #1071 and its discussion, cutoff PR history (no reviews/comments/threads), and the pinned upstream grammar's catch_clause/object_pattern node definitions. Hosted CI run 42563976948 is attributed to this exact head and reports 20,992 passed, 24 skipped, 258 deselected and 4 xfailed; all six reported checks succeeded. Existing new shadowing coverage uses a function declaration, whose identifier is caught, and does not cover shorthand catch bindings. This finding is based on static source and grammar evidence, not a locally executed probe. No contributor code, tests, imports, builds or setup were executed.
…ership (NVIDIA#1072) A catch or for-of destructured RegExp binding is a shorthand_property_identifier_pattern node, which the override check never examined, so a caught arbitrary constructor could borrow the global RegExp proof and own its .exec member. Include shorthand binding nodes in override detection and collect catch_clause parameters as uncertain bindings. Add negative regression controls for destructured catch, for-of, and parameter shadowing, retaining the real global-constructor positive cases. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
|
Fixed. The hole was real:
Added negative regression controls for destructured catch, for-of, and parameter shadowing, retaining the real global-constructor positive cases. Evidence: the reviewer example and the for-of form now stay partial (were owned before the fix); the direct |
a33dc35 to
ea296ac
Compare
…ership (NVIDIA#1072) A catch or for-of destructured RegExp binding is a shorthand_property_identifier_pattern node, which the override check never examined, so a caught arbitrary constructor could borrow the global RegExp proof and own its .exec member. Include shorthand binding nodes in override detection and collect catch_clause parameters as uncertain bindings. Add negative regression controls for destructured catch, for-of, and parameter shadowing, retaining the real global-constructor positive cases. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
|
Follow-up: rebased onto current upstream main (ea5aeef) to clear the conflict. The rebase replayed the #1071 commit first, which conflicted in tests/nodes/analyzers/test_javascript_template_ownership.py because main added parameter-default-value tests in the same region; resolved by keeping both test sets (upstream parameter-default tests plus the regex-exec tests). The shorthand-RegExp fix itself applied cleanly. No code in the fix changed: the reviewer example and for-of form still stay partial, global-constructor positives still owned. Evidence on the rebased head: tests/nodes/analyzers/test_javascript_template_ownership.py 442 passed; analyzer suite 12,630 passed, 5 skipped, 4 xfailed. The PR now reports mergeable. New head ea296ac. |
yashrajp22
left a comment
There was a problem hiding this comment.
Two source-confirmed ownership gaps can cause unknown .exec() calls to lose the incomplete-analysis signal. Reviewed HEAD ea296ac56a6ea2e5e8ed97e9c9ee5a5ed790dc83 against base ea5aeef6b05c593959ad2125c09a528ffa5c55c9. Greptile completed this exact comparison with no comments; I retained these findings after checking the source paths and pinned JavaScript grammar.
This is a source review: no candidate code, tests, builds, source/wheel scans or provider checks were run. The imported-helper template case from #1071 remains outside this PR’s correction.
| if _callable_member(program, member) == "exec": | ||
| regex_calls.append(member) |
There was a problem hiding this comment.
The lookup is file-wide, so a local regex can accidentally prove an unrelated receiver:
function local() { const re = /x/; re.test(text); }
re.exec(`${command}`);The final re is outside that const binding’s scope, but this loop accepts its .exec and adds it to native ownership. _has_shell_execution_call then treats the dynamic template as ordinary host text, losing the partial-inspection signal for an unknown executor. Please constrain the proof to references that resolve to this binding, or refuse out-of-scope references, and cover an outer or sibling receiver.
There was a problem hiding this comment.
Fixed, thanks for catching this. The const-regex proof in _ordinary_native_calls now only accepts references that resolve to the binding: inside the binding scope (the enclosing program or statement_block) and after the declarator, matching the scalar proof declaration-end rule. An outer or sibling receiver with the same name is skipped and stays unowned, so the template keeps its partial-inspection signal. Verified with the exact example first: it returned owned before the fix and partial after. Regression tests added (out-of-scope-regex-receiver-exec, sibling-function-receiver-exec). Commit 8487ede. Module suite: 447 passed. Analyzer suite: 12,635 passed, 0 failed.
| spelling = program.text(node).strip("\"'") | ||
| if spelling in override_names: | ||
| if spelling in override_names and not _is_regexp_constructor(program, node): | ||
| intrinsic_override = True |
There was a problem hiding this comment.
The shorthand check still compares raw source spelling. This parameter binds a caller-supplied RegExp in JavaScript:
function f({\u0052egExp}) {
const re = new RegExp();
re.exec(`${command}`);
}program.text retains the escape, so it misses override_names and the plain constructor name does not match the recorded uncertain binding. The later backslash guard also omits shorthand_property_identifier_pattern. As a result, the arbitrary constructor’s .exec gains native ownership and the dynamic-execution completeness warning disappears. Please fail closed on escaped shorthand binding names before granting the constructor exemption, and cover escaped parameter, catch and loop bindings.
There was a problem hiding this comment.
Fixed. Added _decoded_identifier_text, which resolves JS escape sequences before any override-name comparison or uncertain-binding recording, so an escaped shorthand binding now binds the plain name and poisons the proof like the plain spelling. The backslash fail-closed guard in _has_shell_execution_call now also covers shorthand_property_identifier_pattern, so escaped parameter, catch, and loop bindings all fail closed before the constructor exemption. Verified first: all three escaped forms returned owned before the fix and partial after, while the plain global-constructor case stays owned. Regression tests added for escaped parameter, catch, and for-of bindings. Commit 8487ede. Module suite: 447 passed. Analyzer suite: 12,635 passed, 0 failed.
…bindings (NVIDIA#1072) Constrain the const-regex proof to references inside the binding scope and after its declaration, so an outer or sibling receiver with the same name cannot borrow it. Decode JS escape sequences in shorthand binding names before comparing against override names and recording uncertain bindings, and include shorthand_property_identifier_pattern in the backslash fail-closed guard, so an escaped RegExp binding cannot grant the constructor exemption. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
yashrajp22
left a comment
There was a problem hiding this comment.
The previously reported out-of-scope receiver and escaped-shorthand examples are fixed. One source-confirmed regression remains: the new scope filter skips references that can mutate or expose the regex, allowing a later unknown .exec() to lose its incomplete-analysis signal.
Reviewed HEAD 8487ede74b57234c1a5b751c0346295c9c48b0d0 against base ea5aeef6b05c593959ad2125c09a528ffa5c55c9. Greptile completed this exact comparison and independently identified the earlier-closure mutation case; I confirmed it against the source and consolidated it below.
No candidate code, tests, builds, source/wheel scans or provider checks were run. Runtime verification remains incomplete, and the imported-helper template case from #1071 remains outside this PR's correction.
| scope.start_byte <= reference.start_byte < scope.end_byte | ||
| and reference.start_byte > declarator.end_byte | ||
| ) | ||
| ): | ||
| continue |
There was a problem hiding this comment.
Skipping a reference before the declaration loses mutation checks even when that reference runs after initialization:
function run(handler) {
function patch() { re['exec'] = handler; }
const re = /x/;
patch();
re.exec(`${command}`);
}The closure's re is skipped here, so its assignment never invalidates the regex proof. The later .exec gains native ownership even though it calls the supplied handler; the dynamic template therefore loses its incomplete-analysis signal. The old loop rejected this reference. Please refuse the proof for these earlier in-scope references instead of skipping their mutation/escape checks, and add a closure regression case.
The same skip also drops escape checks for an earlier binding when regex_bindings[name] is overwritten by a later same-named regex:
{ const re = /x/; mutate(re, handler); }
{ const re = /y/; re.exec(`${command}`); }Only the second binding is checked, so the first can expose the shared regex prototype while the second .exec is still trusted. Please retain validation for every binding or fail closed on duplicate names, with a regression case for this shape too.
There was a problem hiding this comment.
Thanks, both fixed in 14451b7.
-
Pre-declaration references are now validated like any other in-scope use instead of skipped, restoring the old loop's rule. A closure defined before the declaration can run after initialization, so
re['exec'] = handlerinsidepatch()now refuses the proof and the later.execno longer gains native ownership. Addedclosure-mutated-regex-before-declaration-execas a regression case. -
regex_bindingsnow keeps every binding per name instead of letting a later same-named binding overwrite the earlier one, and each binding is validated against its own scope. The escape in the first block now refuses the proof, so the second block's.execis no longer trusted on its own. Addedduplicate-regex-binding-escape-execas a regression case.
Both new cases fail before the fix and pass after it. Test evidence: tests/nodes/analyzers/test_javascript_template_ownership.py, 449 passed; full tests/nodes/analyzers/ suite, 12637 passed, 5 skipped, 4 xfailed. Ruff check and format clean.
One note on case (1): I renamed the outer function from run to check in the test. The name run is itself in _SHELL_EXECUTION_CALLS, so any file using it stays partial for an unrelated reason and the case would pass before the fix without exercising the regex proof.
…me-named binding (NVIDIA#1072) In-scope references before a const regex declaration were skipped, so a closure that overwrites re.exec before the declaration never invalidated the regex proof and the later .exec kept native ownership. Validate those references like any other in-scope use, matching the old loop: a mutation or escape refuses the proof. A later same-named regex binding also overwrote the earlier one in regex_bindings, so an escape of the first binding went unchecked while the second .exec stayed trusted. Keep every binding and validate each against its own scope. Add a closure regression case and a duplicate-binding regression case; both fail before the fix and pass after it. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
rng1995
left a comment
There was a problem hiding this comment.
[SkillSpector Review]
Decision: Approved.
Value and readiness
Receiver-aware regex exec ownership removes the #1071 bound-regex false positives while preserving conservative treatment of unknown execution surfaces. The prior own marked finding and the later human findings are resolved in the pinned implementation and regression controls. Ready from code review; remaining human review/thread gates still govern merging.
Material findings
No remaining required code finding. Verified each reported issue:
- The own destructured-catch RegExp hole is closed: override checks include shorthand nodes, catch parameters become uncertain bindings, and catch/for-of/parameter controls retain partial inspection.
- Escaped shorthand bindings are decoded for override/binding comparisons and also covered by the backslash fail-closed check; escaped parameter, catch and loop controls are present.
- A function-local regex no longer owns an outer or sibling receiver: each binding's enclosing program/block bounds its eligible references, leaving other receivers unowned.
- Earlier in-scope references are validated instead of skipped, so a closure that mutates or exposes the regex before its textual declaration poisons ownership.
- Every same-named regex binding is retained and validated, preventing a later binding from hiding an earlier escape of the shared prototype.
The original literal, const-bound and global-constructor positives remain; child_process/unknown/let/reassigned/shadowed/tagged forms retain conservative checks. The helper-to-template-span caller still records unresolved executable templates when the proof fails. The imported-helper direction of #1071 remains deliberately outside this correction.
PIC tradeoffs
None requiring a new product decision. The proof stays conservative for reflection, overrides and escaping references, while widening ownership only for the supported regex forms.
Verification and gaps
Read the complete two-file diff, surrounding exact-head constructor/binding/reference/alias and template-span paths, every changed test, #1071, all six prior review records, author replies and all three thread histories. The human threads are outdated but remain unresolved; this review verifies their code corrections without treating their resolution state as approval. Pre/post heads match the inventory. Hosted CI run 42854561581 has this exact head_sha; its unit log includes the JavaScript ownership module and reports 22,589 passed, 25 skipped, 258 deselected and 12 xfailed. All six checks succeeded. No contributor code, tests, imports, builds, setup, hooks, scanner/model calls or regex probes were executed locally; author timing/probe claims were not independently reproduced.
Reviewed head: 14451b72d0845bc66a04c3f50cdd09211896af4a.
|
Hi @yashrajp22, following up on your three review threads from Nov 10 (file-wide receiver lookup, escaped RegExp shorthand, pre-declaration references). All three are addressed at head 14451b7: the ownership proof is scoped to references resolving to the binding, escaped shorthand spellings fail closed, and pre-declaration in-scope references refuse the proof, each with regression tests. rng1995 approved Nov 13. Could you take another look when you have a moment? Happy to fix anything still open. |
…VIDIA#1071) The shell-execution check treated every member call named exec as a shell surface, so a const regex binding or a new RegExp value calling .exec() left template literals unowned and scored the file AE1 HIGH. _ordinary_native_calls already owned the literal /.../.exec() form; extend the same proof to const-bound regex identifiers and new RegExp(...) receivers, keeping child_process, unknown receivers, let/var bindings, reassignment, shadowing, and template arguments fail-closed. Direction 2 of NVIDIA#1071 (bundle-local imports) is deliberately untouched. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
…ership (NVIDIA#1072) A catch or for-of destructured RegExp binding is a shorthand_property_identifier_pattern node, which the override check never examined, so a caught arbitrary constructor could borrow the global RegExp proof and own its .exec member. Include shorthand binding nodes in override detection and collect catch_clause parameters as uncertain bindings. Add negative regression controls for destructured catch, for-of, and parameter shadowing, retaining the real global-constructor positive cases. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
…bindings (NVIDIA#1072) Constrain the const-regex proof to references inside the binding scope and after its declaration, so an outer or sibling receiver with the same name cannot borrow it. Decode JS escape sequences in shorthand binding names before comparing against override names and recording uncertain bindings, and include shorthand_property_identifier_pattern in the backslash fail-closed guard, so an escaped RegExp binding cannot grant the constructor exemption. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
…me-named binding (NVIDIA#1072) In-scope references before a const regex declaration were skipped, so a closure that overwrites re.exec before the declaration never invalidated the regex proof and the later .exec kept native ownership. Validate those references like any other in-scope use, matching the old loop: a mutation or escape refuses the proof. A later same-named regex binding also overwrote the earlier one in regex_bindings, so an escape of the first binding went unchecked while the second .exec stayed trusted. Keep every binding and validate each against its own scope. Add a closure regression case and a duplicate-binding regression case; both fail before the fix and pass after it. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
14451b7 to
9f64876
Compare
|
Rebased onto current main (4bd0518). Upstream moved _ordinary_native_calls into javascript_native_calls.py, so the fix now lives there with the same semantics: const regex bindings and direct new RegExp(...) receivers calling .exec()/.test() with no template argument stay owned, and child_process, unknown receivers, let/var bindings, reassignment, shadowing, and template arguments stay fail-closed. New head: 9f64876. The #1071 reproducers still verify: all four positive cases score 0 SAFE and all fail-closed cases stay partial. Analyzer suite green (16488 passed, 5 skipped, 4 xfailed), ruff clean, mypy shows no new errors. |
rng1995
left a comment
There was a problem hiding this comment.
[SkillSpector Review]
Decision — Request changes.
Value and readiness — Receiver-aware regex detection fixes the reported false incomplete-analysis verdicts. On the rebased head I verified that the prior escaped binding, catch binding, out-of-scope receiver, earlier mutation and duplicate escape controls are retained. The duplicate-binding validation still has a scalability regression.
Material findings
javascript_native_calls.py:749–778visits every reference to a name for every same-named binding, then discards references outside the binding's byte range. Thousands of independent blocks that each define and use a localconst retherefore require millions of scope checks, even though each binding has only one relevant use. This work runs inside the shared static-analysis deadline and can leave a normal generated JavaScript file partially inspected. Index references by source position and visit only the current scope's range, or group them by resolved lexical binding. Preserve validation of pre-declaration closures and every same-named binding. Add a deterministic work-count regression with many sibling scopes. Regex binding proof
PIC tradeoffs — The conservative isolation and escape checks remain useful. Restricting where the proof looks for references prevents a coverage-budget regression without trusting extra JavaScript constructs.
Verification and gaps — Reviewed the full diff, native receiver and completeness call paths, regression matrix, and previous own and human reviews and author replies. All six recorded checks succeeded for this head. The duplicate-binding regression exercises escape behavior with two bindings and does not measure larger scope sets. Static review only.
Reviewed head: 9f64876dd9449ce0c63275d21e5ac58bb58c5972
…VIDIA#1072) The binding proof visited every reference to a name for every same-named binding, then discarded the ones outside the binding scope. Thousands of sibling blocks each defining `const re` therefore cost bindings times references inside the shared static-analysis deadline. references[name] is in document order (program.nodes is a pre-order walk), so each binding now slices only its own scope range with bisect. The slice visits exactly the references the old range check kept, so pre-declaration closures and every same-named binding are still validated the same way. Add a deterministic work-count regression with 200 sibling scopes: the quadratic scan needed about 102,000 check_runtime calls, the scope slice about 22,000, and the file still stays partial because the trailing `re` is outside every binding scope. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
|
Fixed, thanks for catching this. The binding proof in Work-count regression added ( Evidence on new head bc07e74: tests/nodes/analyzers/test_javascript_template_ownership.py 608 passed; full tests/nodes/analyzers/ suite 16,488 passed, 5 skipped, 4 xfailed. One failure appeared in the full run (test_runtime_command_process_wrappers_stay_partial[nohup]) but it passes in isolation and in its own file with and without this change, so it looks like a flaky full-run artifact, not this change. Ruff check and format clean. |
_has_shell_execution_call() treated any member call named exec as shell execution without checking the receiver. The literal /.../.exec() form is already owned on current main; the remaining bug is the bound form: a const regex binding (or new RegExp(...)) calling .exec() poisoned the whole file through intrinsic_override, leaving every template literal unresolved and the skill at AE1 HIGH.
Make exec receiver-aware in _ordinary_native_calls: a .exec() call is owned when its receiver is a regex literal, a const binding proved to hold only a regex literal or new RegExp(...), or a direct new RegExp(...) receiver, using the same const-only proof discipline as the existing .test() handling. child_process.exec, cp.exec, unknown receivers, bare exec, let/var or reassigned bindings, escaping references, shadowed RegExp, and template arguments to .exec() stay fail-closed. Direction 2 from the issue (template literals passed to imported helpers) is deliberately untouched; it is a separate design question.
Fixes #1071.
Proof of fix: 15-case probe, 3 fail on clean main (bound const regex .exec, bound new RegExp .exec, direct (new RegExp).exec) and 15/15 pass with the fix; 11 new tests in tests/nodes/analyzers/test_javascript_template_ownership.py; analyzer suite 11979 passed, 4 skipped, 4 xfailed; ruff clean; mypy shows no new errors (54 pre-existing vs 55 on clean HEAD).