-
-
Notifications
You must be signed in to change notification settings - Fork 23
Adds to OWASP/mastg#2588 [MASWE-0024] Weak Message Authentication Codes (MAC) #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sydseter
wants to merge
21
commits into
OWASP:main
Choose a base branch
from
sydseter:MASWE-0024
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a2af71d
Fixes https://github.com/OWASP/mastg/issues/2588
sydseter d6381c7
change id
sydseter dedf092
Change status
sydseter 167b9c2
Add back description
sydseter ba0fef2
Reconstruct topics and description
sydseter 4b1d324
Remove description and topics
sydseter 8eff3e3
Remove new line
sydseter c9122d1
Add back draft state for now
sydseter b9ab458
Enhance clarity on MAC usage and associated risks
sydseter a7c258d
Clarify MAC usage issues and mitigation strategies
sydseter 8b2bebb
Merge branch 'main' into MASWE-0024
sydseter 9df0ed1
correct spelling
sydseter 13c9257
Apply suggestions from code review
cpholguera f36ad8e
Update weaknesses/MASVS-CRYPTO/MASWE-0024.md
sydseter 4832e51
Update MASWE-0024.md
sydseter e4f1109
Update MASWE-0024 with new HMAC mitigation
sydseter 7802a72
Merge branch 'main' into MASWE-0024
sydseter 85f9e01
Update MASWE-0024.md
sydseter 84eb087
Refine HMAC usage explanation in MASWE-0024
sydseter 5af97b0
Merge branch 'main' into MASWE-0024
sydseter e53cd60
renamed MASWE-0024 -> MASWE-0120
sydseter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| --- | ||
| title: Improper Use of Message Authentication Code (MAC) | ||
| id: MASWE-0120 | ||
| alias: improper-mac | ||
| platform: [android, ios] | ||
| profiles: [L1, L2] | ||
| mappings: | ||
| masvs-v1: [MSTG-CRYPTO-4] | ||
| masvs-v2: [MASVS-CRYPTO-1] | ||
| cwe: [327, 807, 915] | ||
|
|
||
| refs: | ||
| - https://developer.android.com/privacy-and-security/cryptography#deprecated-functionality | ||
| - https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar2.pdf | ||
| - https://csrc.nist.gov/pubs/sp/800/224/ipd | ||
| - https://datatracker.ietf.org/doc/html/rfc6151 | ||
| - https://web.archive.org/web/20170810051504/http://www.tcs.hut.fi/old/papers/aura/aura-csfws97.pdf | ||
| - https://en.wikipedia.org/wiki/Replay_attack | ||
| draft: | ||
| description: Improper use of MACs in security sensitive contexts affecting data integrity. | ||
| topics: | ||
| - Using HMAC with keys with insufficient entropy | ||
| - Using HMAC with missing timestamp (or nonce) | ||
| - Using MAC‑then‑encrypt or encrypt‑then‑MAC incorrectly, leaking information via timing or error messages | ||
| - Allowing predictors (users or attackers) to control data inputs, creating scenarios where forged or replayed tags bypass integrity checks. | ||
| - Hash functions lacking collision resistance (e.g., MD5 or SHA‑1 used in HMAC) | ||
| - Use of non‑cryptographic checksums (e.g., CRC‑32 instead of HMAC) | ||
| - MAC constructions that fail outside narrow assumptions (e.g., raw CBC‑MAC on variable‑length messages) | ||
| - Tags that are too short significantly lower the effort required for forgery | ||
| status: placeholder | ||
|
|
||
| --- | ||
|
|
||
| ## Overview | ||
|
|
||
| Improper use of a MAC, e.g., not using proper nonces or timestamps, may allow MAC forgeries, making it possible to compromise the authenticity and integrity of the data. | ||
| Another common issue is using an HMAC with a general-purpose hashing algorithm on low-entropy input, such as user-supplied passwords, PINs, or other user-controlled inputs. HMACs are not designed for use with low-entropy inputs or low-entropy keys. Using HMACs in this way results in "weak" message digests that can be easily exploited. | ||
| Deprecated or risky HMAC implementations like HMAC-MD5 or HMAC-SHA1 are vulnerable to collision attacks that would compromise the authenticity and integrity of the data. Collision attacks can also be made possible through truncating the HMAC digest. If truncating is necessary for interoperability, never truncate the digest below 128 bits and use the full HMAC whenever possible. Finally, never create checksums using non-cryptographically secure algorithms like CRC‑32, which are not meant for cryptographic purposes. | ||
|
|
||
| ## Impact | ||
|
|
||
| - **Loss of authenticity**: Improper use of MAC may allow an attacker to compromise the authenticity of the data, making the data appear authentic. | ||
| - **Loss of Integrity**: Improper use of MAC may allow an attacker to alter the data, thereby compromising its integrity. | ||
| - **Loss of Confidentiality**: Using MAC for other purposes than authentication may lead to a complete loss of confidentiality. | ||
|
|
||
| ## Modes of Introduction | ||
|
|
||
| - **Not including a timestamp**: Creating a MAC for message authentication without using a proper timestamp that can be validated to protect against MAC forgery. | ||
| - **Using a MAC with low-entropy keys**: Using low-entropy inputs or low-entropy keys as input to a HMAC. | ||
| - **Using a MAC with a predictor**: Using data controlled by the user to create a HMAC signature. | ||
| - **Using a deprecated or risky MAC implementation**: Using e.g, HMAC-MD5 or HMAC-SHA1, which are known to be vulnerable to collision attacks. | ||
| - **Using a non-cryptographically secure algorithm**: Using CRC‑32, which is not meant to be used for cryptographic purposes. | ||
| - **Truncating the HMAC digest too much**: Truncating the final HMAC digest makes it shorter than 128 bits. | ||
| - **Not applying the MAC in the correct order**: When using CBC mode during encryption, e.g., incorrectly creating the MAC before encrypting the data instead of after, to ensure the authenticity and integrity of the encrypted data. | ||
| - **Using raw hash constructs where a MAC is required**: For example, computing SHA-256(secret || data) or SHA-256(data || secret) instead of using HMAC, making the scheme vulnerable to length extension and structural attacks. | ||
|
|
||
| ## Mitigations | ||
|
|
||
| - **Use MAC with a timestamp**: Generate the MAC over a message with the timestamp included. This should protect the application against replay attacks within a reasonable amount of time. Reasonable, meaning a time frame that is short enough to prevent an attacker from sending an identical message and long enough to allow the message to be sent and digested. | ||
| - **Do not use HMAC together with a low-entropy key**: Ensure the keys used are generated using cryptographically secure PRNGs (CSPRNG) generate random numbers that pass statistical randomness tests, and are resilient against prediction attacks. | ||
| - **Do not use a MAC together with a predictor**: Ensure that all inputs to the MAC are unpredictable and not controlled by the user or attacker. Never use user-controllable or predictable data as input to a MAC, as this can allow attackers to forge valid MACs. | ||
| - **Do not use deprecated HMAC implementations**: Deprecated HMAC implementations could contain errors that allow for collision attacks. Therefore, only use recommended libraries and functions. | ||
| - **Do not use non-cryptographically secure algorithms**: Algorithms like e.g. CRC‑32 are not meant to be used for cryptographic purposes. | ||
| - **Use the complete HMAC digest and avoid truncation**: When possible, always use the complete HMAC digest. When truncating is necessary, never make it shorter than 128 bits. | ||
| - **Use HMAC instead of raw hash constructs to detect tampering**: Don't roll your own hash constructs; instead, follow recommended approaches for how to implement HMAC. | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.