Skip to content

fix(auth)!: change timestamp to ms since Unix epoch for effective replay protection - #58

Open
VasilevNStas wants to merge 1 commit into
APN-Network:masterfrom
VasilevNStas:29-fix/timestamp-ms
Open

fix(auth)!: change timestamp to ms since Unix epoch for effective replay protection#58
VasilevNStas wants to merge 1 commit into
APN-Network:masterfrom
VasilevNStas:29-fix/timestamp-ms

Conversation

@VasilevNStas

Copy link
Copy Markdown
Contributor

Description

Changes Auth.timestamp from uint32 (minutes since project epoch) to uint64 timestamp_ms (milliseconds since Unix epoch) for effective per-message replay protection.

Problem

The previous uint32 timestamp used minute granularity. Every Auth sent within the same 60-second window carried the identical value. With the ±1 minute acceptance window, a captured frame could be replayed for up to 119 seconds. This is not a nonce — it's a coarse time window.

Fix

Before After
uint32 timestamp = 2 uint64 timestamp_ms = 2
Minutes since 2024-01-01 UTC Milliseconds since Unix epoch
±1 minute acceptance ~1–2 second skew window
HMAC input: 4 bytes LE/BE undefined HMAC input: 8 bytes big-endian

The big-endian serialization is now explicitly specified in the HMAC comment.

Migration

Breaking wire change — the Auth frame format changes. All Nodes and clients must update simultaneously:

  • Auth field 2 wire type changes (varint fits within 1–10 bytes)
  • HMAC input length changes from 4 to 8 bytes
  • Generated code symbol changes from timestamp to timestamp_ms

Closes #29

@VasilevNStas

Copy link
Copy Markdown
Contributor Author

@yegor256 @davvd plz review this PR

@VasilevNStas
VasilevNStas force-pushed the 29-fix/timestamp-ms branch from fee2ffe to 5c1ecf5 Compare July 4, 2026 18:09
@VasilevNStas

Copy link
Copy Markdown
Contributor Author

@davvd conflicts resolved.

Comment thread auth.proto Outdated
// message; unlike the previous minute-based timestamp, an attacker
// cannot replay a captured frame at any point within a multi-minute
// window.
uint64 timestamp_ms = 2;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VasilevNStas we are against compound names, only solid nouns

@VasilevNStas

VasilevNStas commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

@davvd Thank you for the review note about compound names — understood, I will keep field names as solid nouns going forward.

Updating the branch now:

  1. Renaming timestamp_ms back to timestamp (solid noun)
  2. Rebuilding the branch on top of current master to remove unrelated diff (the old branch had drifted and picked up reverts of upstream changes)
  3. Only change: uint32 timestamp = 2;uint64 timestamp = 2; with updated comments for ms-since-Unix-epoch semantics and big-endian HMAC serialization

@VasilevNStas

Copy link
Copy Markdown
Contributor Author

@davvd plz re-review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auth.timestamp minute granularity makes replay-prevention nonce ineffective

2 participants