length-extension-attacks-anti-pattern

Detect hash length extension vulnerabilities and provide HMAC alternatives in Python, JavaScript, and Java.

8|1|Updated Jan 19, 2026
One-click install
npx skills add https://github.com/igbuend/grimbard --skill length-extension-attacks-anti-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: length-extension-attacks-anti-pattern
Source: https://github.com/igbuend/grimbard/tree/main/skills/length-extension-attacks-anti-pattern
Command: npx skills add https://github.com/igbuend/grimbard --skill length-extension-attacks-anti-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses critical security vulnerabilities in message authentication and integrity verification, specifically preventing attackers from extending valid hash-based signatures without knowing the secret key.

Core Features & Use Cases

  • Vulnerability Detection: Identifies the misuse of hash functions (MD5, SHA-1, SHA-256) in constructing message authentication codes (MACs).
  • Secure Implementation Guidance: Provides correct implementations using HMAC, which is resistant to length extension attacks.
  • Cross-Language Examples: Offers secure coding examples in Python, JavaScript, and Java.
  • Use Case: When reviewing code that uses hash(secret + message) for API signatures or data integrity, this skill helps identify the weakness and guides developers to use HMAC instead.

Quick Start

Review the current code for any instances of hash(secret + message) patterns and ensure HMAC is used for message authentication.

Frequently Asked Questions about length-extension-attacks-anti-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is a hash length extension attack and how does it compromise message authentication?

A hash length extension attack exploits vulnerable hash functions like MD5, SHA-1, or SHA-256 to append data to a valid hash(secret + message) signature without knowing the secret key, compromising message integrity. Using HMAC prevents this vulnerability.

How do I prevent hash length extension attacks in my API signature verification?

To prevent hash length extension attacks in API signatures, replace vulnerable hash(secret + message) patterns with HMAC implementations. This Skill identifies misuse of MD5, SHA-1, and SHA-256, guiding developers to secure HMAC alternatives.

Why does using hash(secret + message) for MACs create a security vulnerability?

Using hash(secret + message) for message authentication codes creates a vulnerability because attackers can exploit the hash construction to extend the message and forge valid signatures. HMAC securely wraps the hash function to prevent length extension attacks.

Can I find secure HMAC code examples for Python, JavaScript, and Java to fix vulnerable hash functions?

Yes, this Skill provides secure HMAC implementation examples for Python, JavaScript, and Java. These cross-language examples help developers replace vulnerable MD5, SHA-1, and SHA-256 hash constructions with secure message authentication alternatives.

How do I detect MD5 or SHA-256 misuse in my codebase for message authentication?

This Skill detects MD5, SHA-1, and SHA-256 misuse in message authentication contexts by identifying vulnerable hash(secret + message) patterns. It flags these anti-patterns as CWE-328 vulnerabilities and recommends secure HMAC implementations.

Are there limitations to using HMAC for preventing length extension attacks?

HMAC is resistant to length extension attacks when implemented correctly, but developers must ensure proper key management and use cryptographically sound hash functions. This Skill helps identify vulnerable patterns but secure implementation requires following provided HMAC examples carefully.