fix(content-type): replace git-diff with jsdiff to clear Snyk issue - #324
Open
naman-contentstack wants to merge 1 commit into
Open
fix(content-type): replace git-diff with jsdiff to clear Snyk issue#324naman-contentstack wants to merge 1 commit into
naman-contentstack wants to merge 1 commit into
Conversation
git-diff@2.0.7 is unmaintained (last published 2018) and pulls in chalk@2, diff@3, loglevel, shelljs and shelljs.exec. Snyk flagged the only vulnerable path in the monorepo through that tree: Missing Release of Resource after Effective Lifetime [Medium] SNYK-JS-INFLIGHT-6095116 git-diff@2.0.7 > shelljs@0.8.5 > glob@7.2.3 > inflight@1.0.6 Snyk reports no direct upgrade or patch, since git-diff is abandoned. Replace it with diff@^9 (jsdiff): zero runtime dependencies, bundled TypeScript types, dual CJS/ESM. It also removes the dependency on a `git` binary and the temp-file/subprocess round trip git-diff used to shell out through shelljs. buildDiffString now calls createTwoFilesPatch, which emits the `---` and `+++` file headers itself, so the hand-rolled header concatenation is gone. Output was verified equivalent: both patch strings were run through Diff2html.parse and compared on file names, added/deleted line counts, hunk headers and every line type plus content - identical. Identical inputs are also handled better. git-diff returned undefined when both sides matched, which interpolated the literal string "undefined" into the patch; createTwoFilesPatch returns a well-formed patch with no hunks. Drop @types/git-diff, since diff ships its own types. Tests: the existing spec mocked diff2html, so the generated patch was never asserted. Add two cases covering the string handed to Diff2html.parse - one for headers, hunk and changed lines, one for the identical-input case. Both were mutation-checked against a corrupted buildDiffString. Suite: 78 passed, 16 suites, tsc clean, Snyk reports no vulnerable paths across the monorepo. Bump the pinned pnpm-lock.yaml checksum in .talismanrc, which the lockfile change invalidates. The finding is the usual sha512 integrity hashes, not a secret. Note: this commit also carries a pre-existing, uncommitted version bump to 1.5.4 that was already present in package.json. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
🔒 Security Scan Results
⏱️ SLA Breach Summary
✅ BUILD PASSED - All security checks passed |
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.
Why
git-diff@2.0.7is unmaintained (last published 2018) and pulls inchalk@2,diff@3,loglevel,shelljsandshelljs.exec. Snyk flagged the only vulnerable path in the entire monorepo through that tree:Snyk lists it under "Issues with no direct upgrade or patch" — because
git-diffis abandoned, there is nothing to bump to. The dependency has to go.What
Replaced it with
diff@^9(jsdiff): zero runtime dependencies, bundled TypeScript types, dual CJS/ESM. As a side effect it also drops the dependency on agitbinary and the temp-file + subprocess round tripgit-diffused to shell out throughshelljs.createTwoFilesPatchemits the---/+++file headers itself, so the hand-rolled header concatenation is gone.@types/git-diffdropped too, sincediffships its own types.Output equivalence
Not assumed — checked. Both the old and new patch strings were run through
Diff2html.parseand compared on file names, added/deleted line counts, hunk headers, and every line's type and content. Identical. The rendered compare view is unchanged.One behaviour actually improves:
git-diffreturnedundefinedwhen both sides matched, which interpolated the literal string"undefined"into the patch.createTwoFilesPatchreturns a well-formed patch with no hunks.Tests
The existing spec mocked
diff2html, so the generated patch was never asserted — the diff-building logic had no real coverage. Added two cases against the string handed toDiff2html.parse:@@hunk, and the actual changed-/+lines"undefined"Both were mutation-checked — corrupting
buildDiffStringmakes them fail, so they catch regressions rather than just passing.Reviewer notes
.talismanrc: the pinnedpnpm-lock.yamlchecksum is bumped. Talisman flags the lockfile'ssha512-...npm integrity hashes as "base64 encoded text" — a false positive, not a secret. The file is already ignored by checksum; the lockfile change invalidated the pin. Same thing 38bebe6 and db3fcc5 did. The pre-commit hook was not bypassed — Talisman and Snyk both ran and passed.1.5.3→1.5.4bump that was already in the working tree, in the samepackage.jsonas the dep change and not cleanly separable. Happy to pull it out if you'd rather it landed on its own.src/core/content-type/compare.ts:18:asyncand nothing awaits it, so a real tmp failure becomes an unhandled rejection and kills the CLI instead of surfacing a readable error. This is the one uncovered branch in the coverage report. Out of scope for a dependency swap — worth a follow-up ticket.🤖 Generated with Claude Code