315: MSSQL spike: candidate A guard using node-sql-parser #337
No reviewers
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills!337
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/issue-315/mssql-spike-candidate-a-guard-using-node-sql-parse"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
315: MSSQL spike: candidate A guard using node-sql-parser
Implements 315.
Generated in 1m 22s.
Review findings
Review Findings — 315
Summary
I fixed all six findings and the test suite passes.
node --test extensions/mssql/spike/*.test.mjsran 34 tests with 0 failures and 0 skipped. There is no build or lint script. The skip path for a missingnode-sql-parserwas not exercised, because the package is installed locally.candidate-a.test.mjsnow skips with a clear message whennode-sql-parseris missing. I pinned the version at 5.4.0 in the install comment and the skip message.dependency-check.mdnow records the version, licence and install step.dependency-check.mdand did not extend the blocklist. TheUNION ... SELECT ... INTOrejection now has a test.npm auditoutput were not checked in this pass.dependency-check.mdflags both as open.Critical
High
Medium
node-sql-parseris imported but not declared anywhere, because the spike deliberately usesnpm install --no-save. The rootnpm testglob (extensions/mssql/spike/*.test.mjs) now includes this test, so it fails with a module-not-found error on any clean checkout or CI run that has not run the extra install. Suggested fix: record the extra install step inextensions/mssql/spike/ci-coverage.mdordependency-check.mdand in the CI config, or have the test skip with a clear message when the module is missing. [BEST PRACTICE] Also record the package's version, licence and maintenance status in the dependency check, since it is a supply-chain addition. [SECURITY RISK] This matters more because the parser underpins a security guard.SELECT 1 FOR XML PATH,CROSS APPLY OPENJSON(...)and table hints such asWITH (NOLOCK)are allowed, and so isOPENJSON, which is harmless in most cases. Other constructs are not checked either, includingOPENXML,xp_/sp_function-style calls,NEXT VALUE FOR sequence, which advances a sequence, and user-defined scalar functions. Suggested fix: document these as known gaps in the spike's findings, or add them to the corpus. Run the check at the database level too, using a least-privilege read-only login as the primary control and this parser guard as defence in depth. [SECURITY RISK]hasIntoTargetrelies on the parser's AST shape (into.typeorinto.expr, with{ position: null }when absent). If a parser upgrade changes this shape,SELECT INTOwould be silently allowed. Suggested fix: pin thenode-sql-parserversion for the spike, and keep theselectIntoandselectIntoInCtetests as regression guards. Add aUNION ... SELECT ... INTOtest, which I confirmed manually is rejected.Low
reasonis truthy, so a case could be rejected for the wrong reason, for exampleexecfailing as a parse error. Suggested fix: assert on the specific reason, or a reason substring, per case.SELECT 1;), comments hiding a second statement, bracket-quoted or schema-qualified names ([OPENROWSET],master..OPENROWSET),OPENDATASOURCE, andWAITFOR/DECLARE/SETbatches. Suggested fix: add these cases, noting that the corpus files may already cover some.FORBIDDEN_NAMEis matched only against thevalueandtablestring properties. A forbidden function name stored under another key, such asnamein a function node, would be missed. Suggested fix: confirm against the AST forOPENQUERYused as a function call, and widen the keys checked if needed.