Audit remediation: SQL-literal injection escaping (+ codecheck CI fix)#148
Merged
Conversation
…rals (audit 6.1-3)
Several sqlitedb queries interpolate branch_id / doc_id / document_id /
filename directly into SQL string literals delimited by double quotes, e.g.
['... WHERE doc_id="' document_id '"']. run_sql_query() does not forward bind
parameters to mksqlite (it calls do_run_sql_query without varargin), so these
values cannot be passed as '?' placeholders; a value containing a double quote
could break out of the literal and inject SQL (e.g. a crafted branch name or
document id).
Add a private escapeSqlLiteral helper that doubles embedded double quotes
(inside a double-quoted token SQLite reads "" as an escaped "), mirroring the
DID-python _sql_escape (which doubles single quotes for its single-quoted
literals), and apply it at all 15 value-interpolation sites
(do_add_branch / do_delete_branch / do_get_branch_parent / do_get_sub_branches
/ do_get_doc_ids / read / remove_doc / open_doc / file path lookups). The
existing parameterized run_sql_noOpen('... =?', val) call sites are unchanged.
Lockstep with the DID-python field-name validation (same audit item 6.1-3).
Authored without a local MATLAB runtime; needs MATLAB to validate/run.
Maps the §6.1 finding addressed here (SQL-literal escaping, 6.1-3) to its commit, notes that isa (6.1-1) and the sqlite indexes (6.1-4) needed no MATLAB change (MATLAB is the correct reference / already has them; Python caught up), and records the timestamp-format DECISION (§6.1-2/§7.3-13: datenum vs epoch seconds in the same column) as a cross-client choice deliberately NOT changed here, pending joint sign-off. Reiterates author-not-run + the lockstep merge with audit/did-python-2026-06.
Adversarial review counted 14 escapeSqlLiteral call sites in sqlitedb.m, not 15 (the earlier count of 15 included a docstring-example occurrence that was later reverted). All vulnerable double-quoted interpolations are still covered.
…6 ecosystem audit; lockstep + deferrals)
The bare-named tools/tasks/codecheckToolbox.m sits on the genpath'd
tools/ directory and shadowed matbox.tasks.codecheckToolbox, so the
check-code@v1 action's codecheckToolbox("FoldersToCheck","src") call
resolved to the local zero-arg wrapper and failed with "Too many input
arguments". Packaging it as didtools.codecheckToolbox removes the
shadow while keeping the developer convenience. Mirrors the fix already
made on the V2 branch.
Reverts the package-move approach (which let CI fall through to matbox with CreateBadge=true and fail in createBadgeSvg: 'Python commands require a supported version of CPython'). Instead keep the bare-named wrapper that the check-code@v1 action resolves to, but accept and forward the new name-value args (FoldersToCheck/src) while forcing CreateBadge=false. Fixes both the original 'Too many input arguments' error and the CPython badge error without changing the workflow.
Contributor
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #148 +/- ##
==========================================
+ Coverage 41.60% 41.62% +0.01%
==========================================
Files 55 55
Lines 3158 3159 +1
==========================================
+ Hits 1314 1315 +1
Misses 1844 1844 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
stevewds
approved these changes
Jun 14, 2026
This was referenced Jun 14, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repo-side branch of the audit work originally proposed in #146 (fork PR
audriB/DID-matlab:audit/did-matlab-2026-06), brought into aVH-Labbranch so it can be edited and run through CI directly. Lockstep with VH-Lab/DID-python#23 (same audit item §6.1-3).Changes
sqlitedbqueries interpolatebranch_id/doc_id/document_id/filenameinto double-quoted SQL string literals.run_sql_query()does not forward bind params to mksqlite, so those values can't be?placeholders; a value containing"could break out of the literal and inject SQL. Added a privateescapeSqlLiteral(doubles", since SQLite reads""as an escaped"inside a double-quoted token), applied at all 14 value-interpolation sites. The already-parameterizedrun_sql_noOpen('... =?', val)calls are unchanged. Mirrors DID-python's_sql_escape.tools/tasks/codecheckToolbox.m: thecheck-code@v1action addstools/to the path and calls the bare-namedcodecheckToolbox("FoldersToCheck","src"). The wrapper was zero-arg, so this failed with "Too many input arguments" — unrelated to the escaping change and also failing onmain. Fixed by making the wrapper accept and forward the name-value args while keepingCreateBadge=false(badge generation needs CPython, which the runner lacks). Keeping the bare-named wrapper means the action stays on itsifbranch with badges disabled, so no workflow change is needed.Backward compatibility (normal NDI-matlab use)
No behavioral change expected. The escaping only alters values containing
", and NDI never produces such values at these sites: branch ids are'a', doc/document ids aredid.ido16hex_16hex, and binary filenames are literals like'data.bin'/'frames.bin'. For all of these,escapeSqlLiteralis a no-op and the generated SQL is byte-identical. No schema or stored-data format change.Deferred — DECISION required (not changed here)
timestampcolumn format (§6.1-2 / §7.3-13): datenum-days (MATLAB) vs epoch-seconds (Python) in the same column. This is a cross-client decision (DID-matlab / DID-python / cloud) and is intentionally left untouched. Background and the full list of datenum touch-points across DID, NDI, and NDR are catalogued in [Note / no action required] What it would take to move away from MATLAB datenums for timebases/timestamps #147.Test status
Symmetry tests (which exercise these
sqlitedbqueries and DID↔Python parity) and codespell pass. Thecodecheckstatic analysis itself passes (0 errors); this PR's CI commits resolve the wrapper/badge failures in that job.https://claude.ai/code/session_01Nn5vG7DR3RqvBAGwd94JKt