Repository navigation
chore: bump sha.js from 2.4.11 to 2.4.12 (fix security issue: CVE-2025-9288) - #11639
Conversation
- Verify SHA1 output for known inputs - Test truncation with options.length - Handle empty string input - Confirm deterministic behavior for identical inputs
- Updated hash() to only truncate when options.length > 0 - Prevents accidental truncation when options.length is negative - Maintains expected behavior for full-length hash
WalkthroughBump sha.js dependency; add/export a SHA-1 Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant StringUtils
participant SHA1Lib as sha.js
Caller->>StringUtils: hash(input, options?)
StringUtils->>SHA1Lib: compute SHA-1 hex digest of input
SHA1Lib-->>StringUtils: fullDigest (40 hex chars)
alt options.length is defined and > 0
StringUtils->>StringUtils: len = Math.trunc(options.length)
StringUtils->>StringUtils: sliceDigest = fullDigest.slice(0, Math.min(len, fullDigest.length))
StringUtils-->>Caller: return sliceDigest
else
StringUtils-->>Caller: return fullDigest
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks (3 passed)✅ Passed checks (3 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Flag potential breaking changes that are not documented:
1. Identify changes to public APIs/exports, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints (including removed/renamed items and changes to types, required params, return values, defaults, or behavior).
2. Ignore purely internal/private changes (e.g., code not exported from package entry points or marked internal).
3. Verify documentation exists: a "Breaking Change" section in the PR description and updates to CHANGELOG.md.Please share your feedback with us on this Discord post. Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/util/StringUtils.ts (1)
119-127: Minor hardening: coerce to an integer and clamp explicitly; clarify non-crypto intent.Avoid surprises with floats/Infinity and document that SHA-1 here is non-security-critical.
Apply:
export function hash(input: string, options: IHashOptions = {}): string { const hashFunction = shajs("sha1") hashFunction.update(input, "utf8") const hashedInput = hashFunction.digest("hex") - if (options.length && options.length > 0) { - return hashedInput.slice(0, options.length) - } + const len = Number.isFinite(options.length as number) + ? Math.trunc(options.length as number) + : 0 + if (len > 0) { + // slice already caps to hashedInput.length; the Math.min keeps intent explicit + return hashedInput.slice(0, Math.min(len, hashedInput.length)) + } return hashedInput }Optional JSDoc tweak:
/** * Returns a SHA-1 hex digest for internal IDs/aliases (not for cryptographic security). */test/unit/util/string-utils.ts (1)
123-190: Good coverage; consider deduping the two “length > digest size” cases.Both tests at Lines 177–182 and 184–189 assert the same behavior. Keep one to reduce redundancy.
Apply:
@@ - it("should clamp length larger than hash length to full length", () => { - const full = "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d" - const result = hash("hello", { length: 999 }) - expect(result).to.be.equal(full) - expect(result).to.have.lengthOf(40) - }) - it("should return full length when options.length exceeds digest size", () => { const full = hash("hello") - const over = hash("hello", { length: 100 }) + const over = hash("hello", { length: 999 }) expect(over).to.equal(full) expect(over).to.have.lengthOf(40) })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled
- Linear integration is disabled
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (3)
package.json(1 hunks)src/util/StringUtils.ts(1 hunks)test/unit/util/string-utils.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/unit/util/string-utils.ts (1)
src/util/StringUtils.ts (1)
hash(119-127)
🔇 Additional comments (3)
package.json (1)
107-107: No lockfile updates needed; package-lock.json already pins [email protected]
Lockfile verification confirms version 2.4.12 is in use.src/util/StringUtils.ts (1)
123-126: Correct fix: avoid truncating on length = 0 or negative.The extra
options.length > 0guard addresses the empty/negative edge cases cleanly.test/unit/util/string-utils.ts (1)
2-2: Import looks correct for added hash() tests.
gioboa
left a comment
There was a problem hiding this comment.
Thanks for your help @prateek-hegde 💪
commit: |
|
Hey @alumni @sgarner 🚨 Can I count on you both to give it the final ✅ so we can merge and keep things secure? 🙏 |
sgarner
left a comment
There was a problem hiding this comment.
Thanks for the PR @prateek-hegde !
I have a concern about the added input validation. Otherwise this looks good. I'll let @alumni weigh in before we decide.
…tringUtils.ts->hash()
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/util/StringUtils.ts (2)
113-118: Doc: clarify truncation semantics.Consider noting explicitly that when
options.lengthis<= 0or not provided, the function returns the full 40-char digest. This avoids ambiguity for callers reading the JSDoc./** - * Returns a SHA-1 hex digest for internal IDs/aliases (not for cryptographic security) + * Returns a SHA-1 hex digest for internal IDs/aliases (not for cryptographic security). + * Note: if `options.length` is not provided or <= 0, the full 40-character digest is returned. * * @param input String to be hashed. * @param options.length Optionally, shorten the output to desired length. */
109-111: Export the options type for cleaner public typings.
hashis exported; consumers will see its signature in.d.ts. ExportingIHashOptionsimproves DX and avoids anonymous inlined types in declarations.-interface IHashOptions { +export interface IHashOptions { length?: number }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/util/StringUtils.ts(2 hunks)
🔇 Additional comments (2)
src/util/StringUtils.ts (2)
123-126: Length > 0 truncation guard — LGTM.This matches the PR intent and avoids negative-length truncation edge cases. No further validation needed given internal-only usage.
1-1: No changes needed: default import interop enabled. The root tsconfig.json has"allowSyntheticDefaultImports": trueand the playground tsconfig.json has"esModuleInterop": true, soimport shajs from "sha.js"is safe at runtime.
sgarner
left a comment
There was a problem hiding this comment.
LGTM
Thanks for your contribution @prateek-hegde 💜
|
@michaelbromley Do you have an expected timeline for when a new release including this vulnerability fix will be published? Thanks! |
|
@michaelbromley getting some critical error to update sha.js to version 2.4.12 or later, and for this pr is already merged (2 days ago) but latest version released 3 week ago (0.3.26). so can we get any patch update to include sha.js PR or any timeline. |
|
Sorry for the slow reply, I'm having some days off :) TypeORM does not force you to use a version with a vulnerability, so no immediate release is necessary (neither was the update in this repository, i.e. this PR, it's just nice to have). BTW, shajs will be removed in the next major version. |
|
Indeed, TypeORM depends on the range npm update sha.js@latestConsidering the limited way TypeORM uses sha.js, there is not really any feasible vector to exploit CVE-2025-9288 through it anyway. But this fix has been merged and will be coming in a release soon. |
…5-9288) (typeorm#11639) * chore: bump sha.js from 2.4.11 to 2.4.12 (fix security issue: CVE-2025-9288) * test: add unit tests for hash() to ensure sha.js upgrade compatibility - Verify SHA1 output for known inputs - Test truncation with options.length - Handle empty string input - Confirm deterministic behavior for identical inputs * removed .only from test/unit/util/string-utils.ts to run all the unit tests * fix(hash): ensure negative or zero options.length returns full hash - Updated hash() to only truncate when options.length > 0 - Prevents accidental truncation when options.length is negative - Maintains expected behavior for full-length hash * added strict +ve number input validation for hash() * simplified the logic to check number len before applying slice() in StringUtils.ts->hash() --------- Co-authored-by: Prateek Hegde <[email protected]> Co-authored-by: Prateek Hegde <[email protected]>
Summary
Bumps
sha.jsfrom 2.4.11 to 2.4.12 to address security advisory CVE: 2025-9288.Details
[email protected]contains a known vulnerability (CVE: 2025-9288).[email protected].Testing
Notes
This is a safe, non-breaking patch dependency update.
Pull-Request Checklist
masterbranchFixes #00000- N/ASummary by CodeRabbit
Bug Fixes
Tests
Chores