Skip to content

fix(ice): use a random transaction ID for STUN Binding requests - #954

Merged
rainliu merged 1 commit into
webrtc-rs:masterfrom
hsdfat:fix/stun-random-transaction-id
Nov 7, 2026
Merged

rainliu merged 1 commit into
webrtc-rs:masterfrom
hsdfat:fix/stun-random-transaction-id

Conversation

@hsdfat

@hsdfat hsdfat commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Fixes webrtc-rs/rtc#283 (filed in rtc, but the code lives here).

RTCStunGatherer::gather_from_stun_server built the Binding request with TransactionId::default(), which is the all-zero ID, so every server-reflexive request went out with the same transaction ID. RFC 8489 §5 requires the transaction ID to be uniformly random, and some servers/NATs drop or mis-match requests that reuse it.

This switches to TransactionId::new(), which already exists in rtc-stun and fills the ID from rand::rng().

Test

Added binding_requests_use_random_transaction_ids: it builds two STUN clients against the mock runtime, takes the queued Binding request bytes, and checks the 96-bit transaction ID (bytes 8..20) is non-zero and differs between requests. It fails on master and passes with this change.

cargo test --lib --no-default-features --features runtime-mock,crypto-ring stun_gatherer
cargo fmt --check
cargo clippy --lib --tests --no-default-features --features runtime-mock,crypto-ring

CHANGELOG [Unreleased] → Fixed updated.

The STUN gatherer built its Binding request with TransactionId::default(),
an all-zero ID, so every srflx request carried the same transaction ID.
RFC 8489 section 5 requires it to be uniformly random; use
TransactionId::new().

Fixes webrtc-rs/rtc#283
@codecov

codecov Bot commented Nov 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.57%. Comparing base (8ea6e2a) to head (3deae7a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #954   +/-   ##
=======================================
  Coverage   86.57%   86.57%           
=======================================
  Files          66       66           
  Lines       14423    14423           
=======================================
  Hits        12486    12486           
  Misses       1937     1937           
Flag Coverage Δ
smol 86.50% <100.00%> (-0.02%) ⬇️
tokio 86.39% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rainliu
rainliu merged commit 3c4584a into webrtc-rs:master Nov 7, 2026
17 checks passed
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.

stun_gatherer sends STUN Binding requests with an all-zero transaction id

2 participants