Skip to content

fix(net): prevent hello message replay - #6972

Open
xxo1shine wants to merge 1 commit into
tronprotocol:release_v4.8.3from
xxo1shine:fix/net-hello-message-replay
Open

xxo1shine wants to merge 1 commit into
tronprotocol:release_v4.8.3from
xxo1shine:fix/net-hello-message-replay

Conversation

@xxo1shine

Copy link
Copy Markdown
Collaborator

What does this PR do?

Hello messages were accepted without checking timestamp freshness, allowing a previously signed witness message to be replayed indefinitely.

Add a configurable freshness threshold and track the latest verified timestamp per witness so stale or repeated messages are rejected before trust is granted. Adapt the setting to the current NodeConfig-based configuration model while retaining signature-length validation.

Fixes #6675

Why are these changes required?

This PR has been tested by:

  • Unit Tests
  • Manual Testing

Follow up

Extra details

@github-actions
github-actions Bot requested a review from 317787106 September 16, 2026 06:24
@xxo1shine
xxo1shine force-pushed the fix/net-hello-message-replay branch 4 times, most recently from 9a6dbb8 to 56038ea Compare September 16, 2026 06:32
Hello messages were accepted without checking timestamp freshness, allowing a previously signed witness message to be replayed indefinitely.

Use a fixed five-minute freshness threshold and track the latest verified timestamp per witness so stale or repeated messages are rejected before trust is granted.
@xxo1shine
xxo1shine force-pushed the fix/net-hello-message-replay branch from 56038ea to afc874a Compare September 16, 2026 06:40
@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.8.3 milestone Sep 17, 2026

@lxcmyf lxcmyf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[MUST] This review found two blocking issues; see the inline comments.

}

long now = System.currentTimeMillis();
if (now - msg.getTimestamp() > HELLO_MESSAGE_TIMESTAMP_THRESHOLD) {

@lxcmyf lxcmyf Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[MUST] This check only rejects old timestamps. A timestamp beyond the future side of the window, or an extreme value that overflows the subtraction, is accepted and cached, causing subsequent normal Hello messages to be rejected for a long time. Use an overflow-safe two-sided comparison (timestamp < now - threshold || timestamp > now + threshold) and add future-timestamp coverage.

return false;
}

Long lastTimestamp = helloReplayCache.getIfPresent(msg.getAddress());

@lxcmyf lxcmyf Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[MUST] The getIfPresent → signature verification → put sequence is not atomic. Replays of the same address/timestamp on different channels can pass concurrently and both add trust. After signature verification, commit the timestamp with an address-scoped atomic compare-and-update or equivalent lock, and add a concurrency test.

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.

3 participants