fix: replace MD5 with SHA-256 for template signer fragment#7216
fix: replace MD5 with SHA-256 for template signer fragment#7216sandiyochristan wants to merge 2 commits intoprojectdiscovery:devfrom
Conversation
MD5 is cryptographically broken and unsuitable for identifying template signers. The fragment is used to verify code template signing authorization, so a collision-resistant hash is needed. SHA-256 is already used elsewhere in the signing process.
Neo - PR Security ReviewNo security issues found Highlights
Hardening Notes
Comment |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughReplaced MD5 with SHA-256 for generating the user fragment from the ECDSA public key X coordinate. Adjusted digest/fragment handling in Verify to strip the fragment by taking the substring before the last colon instead of trimming by fragment content. Comments and imports updated accordingly. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/templates/signer/tmpl_signer.go`:
- Around line 60-66: GetUserFragment changed the fragment to a SHA256 hex, but
Verify() still removes ":" + t.GetUserFragment(), which breaks verification of
older MD5-suffixed signatures; update Verify() to split the incoming signature
on the last ':' (e.g., find last index of ':'), treat the part before the colon
as the hex-encoded digest and the part after as the fragment, then
hex.DecodeString only the digest part and proceed with verification — make this
change in the Verify method so digest parsing is independent of the fragment
value while leaving TemplateSigner.GetUserFragment unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dd5fc55b-670a-40a9-905b-7506f2a6cd23
📒 Files selected for processing (1)
pkg/templates/signer/tmpl_signer.go
…tibility The Verify() method previously stripped the fragment by matching the exact current fragment value. This breaks verification of templates signed with a different fragment hash (e.g., old MD5 vs new SHA-256). Now splits on the last ':' delimiter instead, making verification work regardless of the fragment hash algorithm.
Proposed Changes
The
GetUserFragment()method inpkg/templates/signer/tmpl_signer.gouses MD5 to hash the ECDSA public key for generating signer identification fragments. MD5 is cryptographically broken and should not be used in any security-relevant context.The Problem
The signer fragment serves a security-critical purpose — it is used to verify authorization when re-signing code protocol templates (see
Sign()method, lines 80-94). When a code template already has a signature, the fragment is compared to determine if the current signer is the original signer:MD5 has been broken since 2004 (Wang et al.) and practical collision attacks exist. While a preimage attack on this specific usage is harder than a collision, using a broken hash in a security-critical code path is a well-known anti-pattern that weakens the overall trust chain.
The Fix
Replace
md5.Sum()withsha256.Sum256():This is a minimal change because:
crypto/sha256was already imported in the same file (used for signing on line 118)sha256.Sum256()has the same call signature asmd5.Sum()— takes[]byte, returns a fixed-size byte arraycrypto/md5import is removed entirely as it has no other uses in this fileFragment Length Change
The hex-encoded fragment changes from 32 chars (MD5, 128-bit) to 64 chars (SHA-256, 256-bit). This is a one-time change — any previously signed templates will need to be re-signed, which is the expected behavior when upgrading cryptographic primitives. Templates signed with the old MD5 fragment will still verify correctly since the fragment is only used for the re-signing authorization check, not for signature verification itself.
Files Changed
pkg/templates/signer/tmpl_signer.go— replacedmd5.Sumwithsha256.Sum256, removed unusedcrypto/md5import, updated commentsSecurity Impact
Proof
crypto/sha256was already imported and used in the same file forsha256.Sum256on line 118crypto/md5import eliminates the last usage of MD5 in this packageChecklist
devbranchSummary by CodeRabbit