Skip to content

fix: update csv-parse to 7.0.3 to clear its security alert - #5115

Open
NoopDog wants to merge 3 commits into
mainfrom
noopdog/5113-csv-parse-7
Open

NoopDog wants to merge 3 commits into
mainfrom
noopdog/5113-csv-parse-7

Conversation

@NoopDog

@NoopDog NoopDog commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Part of #5113. Closing #4949 happens after the merge.

What changed

  • package.json requires csv-parse ^7.0.2 (it was ^5.0.4). The lockfile resolves 7.0.3, the latest 7.x release.
  • app/utils/tsvParser.ts:
    • removes the unused if (!FIELD) branch and its docstring clause;
    • passes the row type to the parser (parseCsv<T>);
    • takes the header row with columns: true instead of an identity columns function;
    • corrects the @returns line.
  • New __tests__/utils/tsvParser.test.ts pins parseContentRows' output on a small inline TSV: header keys, number/boolean/string casts, a stray quote under the tab delimiter with relax_quotes, and an empty number cell.

Why

Dependabot alert #434 (GHSA-8cw4-87c7-c6xx) affects csv-parse 5.6.0 and is fixed in 7.0.2. Dependabot's own bump (#4949) failed type-checking. In 6.0, parse gained typed overloads that reject the no-FIELD call. In 7.0.3, the new columns typing rejects an untyped identity function inside the generic parseContentRows<T>. columns: true is csv-parse's built-in way to read the header row, so it replaces the function rather than casting around it.

Assumptions I made

  • data-browser isn't exposed to the advisory. That needs group_columns_by_name: true together with a duplicated __proto__ header. parseContentRows never sets that option, and it only parses two TSV files committed to the repo.
  • columns: true produces the same keys as the removed identity function. Both TSVs parse to byte-identical output on 5.6.0 and 7.0.3, and build-anvil-db regenerates identical catalog JSON.
  • The empty-number-to-0 case in the test records today's behaviour; it isn't a decision that 0 is right.

How to verify

  1. Run npm ls csv-parse. It shows 7.0.3.
  2. Run npm run lint, npx tsc --noEmit in the root and in files/, npx jest, npm run build-anvil-db in files/ and npm run build-dev:anvil-catalog. Each passes. build-anvil-db leaves git status clean.
  3. Parse both TSVs with parseContentRows on main and on this branch, and compare the sha256 of JSON.stringify of each result. They match: dashboard-source-anvil.tsv (303 rows) 08d3d573… and disease_abbrev_mapping.tsv (388 rows) 3d784ead….
  4. Run npx jest __tests__/utils/tsvParser.test.ts on this branch, then again after npm install --no-save csv-parse@5.6.0. All five tests pass both times.
  5. After the merge, open Security, then Dependabot. Alert Create Proposal to allow metadata access from the browser. #434 shows as fixed, and chore(deps): bump csv-parse from 5.6.0 to 7.0.2 #4949 is closed.

Definition of done (from #5113):

🤖 Generated with Claude Code

NoopDog and others added 3 commits November 26, 2026 00:05
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: cc-claude-tools <cc-claude-tools@clevercanary.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: cc-claude-tools <cc-claude-tools@clevercanary.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: cc-claude-tools <cc-claude-tools@clevercanary.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the csv-parse upgrade and shared TSV parser changes.

No open issues 🎉

What changed in this PR

Updates csv-parse to address the security alert tracked in #5113 and adapts the shared TSV parser used by catalog and consent-data builds.

Changes:

  • Raises csv-parse to ^7.0.2, with 7.0.3 resolved in the lockfile.
  • Removes the unused no-FIELD branch and uses typed parsing with columns: true.
  • Adds regression tests for header keys, scalar casts, stray quotes, and empty numeric cells.
File Description
package.json Requires the patched csv-parse release range.
package-lock.json Locks csv-parse to 7.0.3.
app/​utils/​tsvParser.ts Updates parser typing, simplifies header handling, and corrects documentation.
__tests__/​utils/​tsvParser.test.ts Pins TSV parsing behavior with five focused tests.

Review effort: Balanced

@frano-m frano-m left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. The upgrade, the dead-branch removal and the columns: true switch all check out: both TSVs parse to identical output on 5.6.0 and 7.0.3, and the new test passes on both. A few optional points:

  • Optional: CI never runs Jest. run-checks.yml runs only format, lint and tsc, so this new test (and the other 24 suites) won't run on pull requests, and a future csv-parse major still wouldn't be caught by it in CI. Consider a follow-up issue to add npx jest --maxWorkers=2 to the build job.
  • Optional, at squash time: "build-anvil-db leaves git status clean" doesn't show anything, because /files/**/out/ is gitignored. The sha256 comparison is the real evidence, so consider dropping that phrase from the commit body.
  • Since the PR says "Part of #5113" rather than closing it, #5113 and #4949 will need closing by hand once alert #434 shows as fixed.

Comment thread app/utils/tsvParser.ts

/**
* Returns the file contents parsed into a model shaped by FIELD, or as row arrays if FIELD is omitted.
* Returns the file contents parsed into a model shaped by FIELD.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: consider rewording. The keys come from the header row, and FIELD only picks which columns get cast (columns not in FIELD come through uncast). Something like "Returns the rows of a delimited file as objects keyed by header, with values cast by FIELD_TYPE."

SIZE: "Size",
};

const FIELD_TYPE = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: consider adding an "array" column (e.g. Tags with "a, b,,c" → ["a","b","c"]). The catalog relies on it for DATA_TYPES, DISEASES and STUDY_DESIGNS.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants