CQ-05 / CD-02 exclude files by DEP_DIRS substring — over-matches (e.g. depsolver.js) and is author-evadable

Open
#145 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python

Research direction

Read cq05_safe_execution.py and cd02_permission_scope.py at the listed exclusion checks, then compare their path handling with CQ-03’s _is_test_path and PurePosixPath component matching. Update the dependency and test exclusions in both controls to match path components and test stems; done means paths such as depsolver.js, latest.js, and inspector.js remain scanned while actual dependency and test paths stay excluded.

Written by the indexing model from the issue text.

Description

The gap

CQ-05 (safe-execution) and CD-02 (permission-scope) decide whether a file is bundle code or a dependency/test — and therefore whether to scan it at all — with substring matches, not path-component matches. Substring matching over-matches, so a legitimate server file is silently dropped from the scan. A dropped file is scanned for nothing, which is a fail-open: the control certifies coverage it never had.

This is the same "attribute by origin, not by substring" shape as #136 / #143, but pointed the other way. #136 / #143 are about the "/deps/" in path form that fails to match and charges dependency findings to the bundle (over-block). CQ-05 / CD-02 use the bare dep in path form that over-matches and skips real server code (under-scan). Different direction, different controls, not covered by either issue.

Where

Dependency exclusion (over-matches deps/vendor/venv/... as a substring):

  • apps/scanner/src/mpak_scanner/controls/code_quality/cq05_safe_execution.py:113 — if any(dep in relative for dep in DEP_DIRS): continue
  • apps/scanner/src/mpak_scanner/controls/code_quality/cq05_safe_execution.py:142 — in_deps = any(dep in relative_path for dep in DEP_DIRS)
  • apps/scanner/src/mpak_scanner/controls/capability_declaration/cd02_permission_scope.py:500 — if any(dep_dir in relative for dep_dir in DEP_DIRS): return ...

Test exclusion in the same two spots has the identical substring flaw ("test" matches latest.js, "spec" matches inspector.js):

  • cq05_safe_execution.py:117 — if "test" in relative.lower() or "spec" in relative.lower(): continue
  • cd02_permission_scope.py:503 — same expression

Why it is a real fail-open

DEP_DIRS = ["deps", "node_modules", "vendor", "site-packages", ".venv", "venv"].

  • A server file src/depsolver.js — "deps" in "src/depsolver.js" is True → skipped. eval() / child_process / a broad permission grant in that file is never inspected. Same for any path containing deps/vendor/venv/venv as a substring.
  • The exclusion is on the bundle-relative path the author controls, so this is also an evasion vector, the same threat model #136 raises for CQ-02: name a file or directory ...deps... (with no actual dependency there) and its contents skip CQ-05 / CD-02 entirely. No node_modules required.
  • The test-path check compounds it: latest.js, contest.py, manifest_spec_helpers.js all match "test"/"spec" as substrings and are dropped from scanning.

CQ-02, CQ-03 and AI-05 already moved off this shape — they match on PurePosixPath(path).parts / stems (see cq03_static_analysis.py:35,47 and its comment naming latest.js / depsolver.js explicitly). CQ-05 and CD-02 were not converted.

Shape of a fix

Unlike #136 (which needs SBOM-based origin attribution to distinguish a real published package from an author-made vendor/ dir), this one is the small, independent fix the doc in apps/scanner/CLAUDE.md now prescribes: match path components, not substrings.

  • Dependency: any(part in DEP_DIRS for part in relative.parts)
  • Test: reuse CQ-03's _is_test_path (component + stem), not "test" in path

There are now four+ copies of DEP_DIRS + a _is_dependency_path helper across cq02 / cq03 / ai05 (and the missing conversions in cq05 / cd02 / cq01). Worth extracting one shared is_dependency_path / is_test_path helper so the next control can't reintroduce the substring form. Converting CQ-05 / CD-02 does not need the SBOM work and can land ahead of #136.

Not this

Real dependency/test directories must still be excluded — the goal is to stop over-matching innocent server files (and to close the author-named-path evasion), not to start scanning node_modules/.

Related

  • #136 — CQ-02 dependency exemption is author-controlled (over-block direction; SBOM fix)
  • #143 — CQ-01 "/deps/" in file_path charges dependency secrets to the bundle
  • #139 — CQ-02 false positives on inlined/minified bundler output
Dominant language
TypeScript
Stars
14
Forks
13
Avg merge
16m
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NimbleBrainInc/mpak

All issues in NimbleBrainInc/mpak

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.