mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 03:45:20 +00:00
fix(security): reduce timestamp validation window to ±5 minutes
BCH-01-011: Reduces replay attack window from ±1 hour to ±5 minutes. The previous 1-hour window allowed extended replay attacks. A 5-minute window is industry standard for replay protection while accommodating reasonable clock drift. - Updated InputValidator.validateTimestamp to use 300-second window - Updated tests to verify new boundary conditions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -52,11 +52,13 @@ struct InputValidator {
|
||||
// MessageType/NoisePayloadType enums; keeping validator free of stale lists.
|
||||
|
||||
/// Validates timestamp is reasonable (not too far in past or future)
|
||||
/// BCH-01-011: Reduced from ±1 hour to ±5 minutes to limit replay attack window
|
||||
static func validateTimestamp(_ timestamp: Date) -> Bool {
|
||||
let now = Date()
|
||||
let oneHourAgo = now.addingTimeInterval(-3600)
|
||||
let oneHourFromNow = now.addingTimeInterval(3600)
|
||||
return timestamp >= oneHourAgo && timestamp <= oneHourFromNow
|
||||
// 5 minutes = 300 seconds (industry standard for replay protection)
|
||||
let fiveMinutesAgo = now.addingTimeInterval(-300)
|
||||
let fiveMinutesFromNow = now.addingTimeInterval(300)
|
||||
return timestamp >= fiveMinutesAgo && timestamp <= fiveMinutesFromNow
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user