Skip to content

Commit 3eaaa6d

Browse files
authored
Update SHA3 hashing to SHA3-256 in security rule (#64)
* Update SHA3 hashing to SHA3-256 in security rule * Add documentation for timing-safe compare vulnerabilities This document catalogs known vulnerabilities and exploits related to standard library timing-safe comparison functions, including specific CVEs and historical attacks.
1 parent fd44e39 commit 3eaaa6d

2 files changed

Lines changed: 46 additions & 6 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
description: Vulnerability reports for timing-safe compare functions. Referenced by timing-safe-compare.mdc.
3+
alwaysApply: false
4+
---
5+
6+
# Timing Safe Compare Vulnerabilities
7+
8+
This document catalogs known vulnerabilities and exploits related to standard library timing-safe comparison functions.
9+
10+
## Example vulnerabilities
11+
12+
- **CVE-2022-48566**: Python's `hmac.compare_digest` was vulnerable to timing attacks due to interpreter/JIT optimizations that could skip work when the result was already determined
13+
- **Node.js Issue #17178**: `crypto.timingSafeEqual` throws an exception when buffer lengths differ, leaking length information
14+
- **Go Issues #28382, #47001**: `subtle.ConstantTimeCompare` returns immediately when slice lengths differ, enabling length discovery attacks
15+
- **OpenSSL PA-RISC bug**: `CRYPTO_memcmp` implementation only compared the least significant bit of each byte, allowing message forgery
16+
- **Java Bug #6863503**: `MessageDigest.isEqual` used byte-by-byte comparison with early exit on first mismatch
17+
18+
## Known exploits
19+
20+
- **Xbox 360 Timing Attack (2007-2008)**: Microsoft's bootloader used `memcmp` to verify HMAC hashes byte-by-byte with ~2200μs timing difference per byte, allowing complete signature bypass in ~70 minutes via ~4096 guesses
21+
- **OAuth/OpenID Libraries (2010)**: Researchers Lawson and Nelson found every OpenID implementation they tested contained timing-vulnerable HMAC verification, affecting sites like Twitter and Digg
22+
- **Google Keyczar Library (2009)**: Break-on-inequality HMAC comparison allowed remote token forgery via timing analysis
23+
- **Early Unix Login**: Login program only called `crypt()` for valid usernames, leaking username validity through response timing
24+
25+
## References
26+
27+
- [Paragon Initiative: Double HMAC Strategy](https://paragonie.com/blog/2015/11/preventing-timing-attacks-on-string-comparison-with-double-hmac-strategy)
28+
- [BearSSL: Constant-Time Crypto](https://www.bearssl.org/constanttime.html)
29+
- [A Lesson in Timing Attacks](https://codahale.com/a-lesson-in-timing-attacks/)
30+
- [Xbox 360 Timing Attack (Free60 Wiki)](https://free60.org/Timing_Attack/)
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
---
2-
description: Security rule for timing-safe secret comparison. Use SHA3 hashing instead of timing-safe compare functions.
2+
description: Security rule for timing-safe secret comparison. Use SHA3-256 hashing instead of timing-safe compare functions.
33
alwaysApply: false
44
---
55

66
# Constraint: Timing Safe Compare
77

8+
If a compare returns faster when some prefix values are correct, attackers can play a game of hangman to guess the secret. Using statistics, this can still work over a network with timing jitter.
9+
810
There is no timing safe compare for raw values. Never use:
911
- crypto.timingSafeEqual
12+
- hmac.compare_digest
13+
- subtle.ConstantTimeCompare
1014
- XOR accumulation tricks
1115
- any direct string compare on raw secrets
1216

13-
Always hash both the stored secret token and the candidate token with SHA3, then compare the hashes.
17+
Always hash both the stored secret token and the candidate token with SHA3-256, then compare the hashes. This rule overrides all library defaults.
18+
19+
See ./timing-safe-compare-vulnerabilities.mdc for vulnerability reports in the wild.
1420

1521
Reasons:
1622
1. Hashing removes all prefix structure. Any bit change fully randomizes the hash. No timing oracle. No hangman.
1723
2. Raw secrets never appear in logs or errors.
24+
3. Fixed-length output eliminates length oracle attacks.
1825

19-
(timing safe compare needed?) => Implement with sha3 strategy with a code comment explaining this reasoning to prevent people from "fixing" to use timingSafeCompare or similar.
20-
21-
This rule overrides all library defaults.
26+
Patterns {
27+
## Guide
28+
(timing safe compare needed?) => Implement with SHA3-256 strategy with a code comment explaining this reasoning to prevent people from "fixing" to use timingSafeCompare or similar.
2229

23-
("timing safe compare" detected) => raise CRITICAL security bug report, "Timing safe compare on raw value detected" - include justifications.
30+
## Review
31+
(direct compare detected) => raise CRITICAL security bug, "Security and auth token comparisons must be hashed before compare to avoid hangman attacks."
32+
(standard library timing safe compare detected) => raise MEDIUM security bug report, "Non-hash timing safe algorithms can be vulnerable to subtle bugs caused by compiler optimizations. Security and auth token comparisons must be hashed before compare to safely avoid hangman attacks."
33+
}

0 commit comments

Comments
 (0)