CryptoJS SHA-1 to SHA-256 Migration Codemod
🔒 Critical Security Upgrade: Automatically migrates CryptoJS SHA-1 usage to SHA-256 to address cryptographic vulnerabilities.
Overview
SHA-1 is cryptographically broken and vulnerable to collision attacks. This codemod helps you upgrade from the deprecated SHA-1 algorithm to the more secure SHA-256, ensuring your application maintains cryptographic integrity.
Security Impact
- Vulnerability: SHA-1 collision attacks (CVE-2020-0601)
- CWE: CWE-327 (Use of a Broken or Risky Cryptographic Algorithm)
- OWASP: A02 - Cryptographic Failures
- Severity: Critical
Installation & Usage
bash
Transformations
ES6/ESM Imports
Before:
javascript
After:
javascript
Default Imports
Before:
javascript
After:
javascript
CommonJS Destructuring
Before:
javascript
After:
javascript
Method Chaining
Before:
javascript
After:
javascript
Variable References
Before:
javascript
After:
javascript
Aliased Imports
Before:
javascript
After:
javascript
What Won't Be Transformed
- String literals containing "SHA1" (preserved intentionally)
- Comments mentioning SHA1
- Custom functions named SHA1 (not from crypto-js)
- Already upgraded SHA256 usage
- Test files (configurable exclusion)
Important Notes
⚠️ Hash Length Change: SHA-256 produces 64-character hex strings vs SHA-1's 40-character strings. Review any code that depends on specific hash lengths.
✅ API Compatibility: The CryptoJS API remains the same - only the algorithm changes.
🔍 Manual Review Recommended: While this codemod handles most cases automatically, review the changes to ensure correctness in your specific context.
File Types Supported
.js- JavaScript.ts- TypeScript.jsx- React JSX.tsx- React TypeScript JSX
Excluded Patterns
The codemod automatically excludes:
node_modules/- Test files (
*.test.*,*.spec.*) - Test directories (
test/,tests/,__tests__/)
Development
bash
Security References
- CWE-327: Use of a Broken or Risky Cryptographic Algorithm
- CWE-328: Use of Weak Hash
- CVE-2020-0601: Windows CryptoAPI Spoofing Vulnerability
- RFC 6194: Security Considerations for the SHA-0 and SHA-1 Message-Digest Algorithms
- NIST Policy on Hash Functions
License
MIT