forked from username/flaskpaste
security: implement CRYPTO-001 and TIMING-001 remediations
CRYPTO-001: Certificate serial collision detection - Add _generate_unique_serial() helper for database-backed PKI - Add _generate_unique_serial() method for in-memory PKI class - Check database for existing serial before certificate issuance - Retry with new random serial if collision detected (max 5 attempts) TIMING-001: Constant-time database lookups for sensitive queries - Add dummy PBKDF2 verification when paste not found - Prevents timing-based enumeration (attackers can't distinguish 'not found' from 'wrong password' by measuring response time)
This commit is contained in:
@@ -485,6 +485,16 @@ def fetch_paste(paste_id: str, check_password: bool = True) -> Response | None:
|
||||
).fetchone()
|
||||
|
||||
if row is None:
|
||||
# TIMING-001: Perform dummy password verification to prevent timing-based
|
||||
# enumeration (attacker can't distinguish "not found" from "wrong password"
|
||||
# by measuring response time)
|
||||
if check_password:
|
||||
dummy_hash = (
|
||||
"$pbkdf2-sha256$600000$"
|
||||
"0000000000000000000000000000000000000000000000000000000000000000$"
|
||||
"0000000000000000000000000000000000000000000000000000000000000000"
|
||||
)
|
||||
verify_password("dummy", dummy_hash)
|
||||
db.commit()
|
||||
return error_response("Paste not found", 404)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user