codebase-memory-mcp icon indicating copy to clipboard operation
codebase-memory-mcp copied to clipboard

Default 'assets' directory exclusion silently swallows API route files (pages/api/assets)

Open jscyrus opened this issue 4 months ago • 3 comments

Summary

Directories named assets are excluded from indexing by default — reasonable for static files, but under Next.js API trees, pages/api/assets/ contains live route handlers (asset proxy endpoints, typically with dynamic [param].ts files taking attacker-controlled input). Those files are silently absent from file_hashes and produce no nodes.

To your credit, the index response DOES announce it ("excluded":{"dirs":["pages/api/assets"]}) — consumers who read that field can compensate (we are wiring that in on our side). The ask is about the default's blast radius, not silence.

Verified repro (2 minutes, CBM 0.9.0)

mkdir -p /tmp/repro/pages/api/assets /tmp/repro/pages/api/things
# a live proxy route where Next.js conventions put it:
echo 'const handler=(req:any,res:any)=>res.end("x"); export default handler;' \
  > "/tmp/repro/pages/api/assets/[assetId].ts"
# controls:
echo 'const handler=(req:any,res:any)=>res.end("x"); export default handler;' > /tmp/repro/pages/api/plain.ts
echo 'const handler=(req:any,res:any)=>res.end("x"); export default handler;' > "/tmp/repro/pages/api/things/[thingId].ts"

codebase-memory-mcp cli index_repository --repo-path /tmp/repro --mode moderate --name repro
# response: "excluded":{"dirs":["pages/api/assets"],"count":1}
sqlite3 ~/.cache/codebase-memory-mcp/repro.db "SELECT rel_path FROM file_hashes WHERE project='repro';"
# observed: pages/api/plain.ts, pages/api/[direct].ts, pages/api/things/[thingId].ts
#           — bracket names walk FINE; the assets/ subtree is the omission

We hit this on a large private TypeScript monorepo, where several live API route files under assets/ directories were silently absent from the graph. Route handlers under assets/ paths are a common Next.js pattern for asset proxying, so the excluded files tend to be exactly the parameterized, input-handling endpoints a code-graph consumer most needs.

Asks

  1. Is the assets exclusion configurable per project? If yes, a pointer to the setting is all we need; if not, please consider one (or an exception when the dir sits under a route tree like pages/api/ / app/api/).
  2. Consider not excluding directories that contain .ts/.js source files — static-asset dirs rarely do.

jscyrus avatar Jul 23 '26 03:07 jscyrus

Confirmed against current main: assets is in FAST_SKIP_DIRS, and both fast and moderate discovery use that directory-name filter. On current main, a project .cbmignore negation such as !pages/api/assets/ can unskip this ordinary built-in directory, so that is the immediate workaround. The RED case should index a moderate-mode Next.js route under that path and require its source and Route node to survive discovery. The durable fix must stop generic build-output names from silently hiding source-bearing framework paths. High priority for 0.9.1-rc under #592.

DeusData avatar Jul 24 '26 14:07 DeusData

Thank you again for the pages/api/assets example. The earlier response documented the scoped .cbmignore override, while the default discovery behavior remains the underlying concern. I have no new verified fix to report for source-bearing framework directories.

DeusData avatar Oct 19 '26 22:10 DeusData

Thank you for the source-bearing assets route example. The scoped override does not settle the default exclusion behavior, which remains for maintainer follow-through. Sorry for the delay; this is waiting on maintainer follow-up, and I’ll follow up soon.

DeusData avatar Oct 25 '26 17:10 DeusData