From ff6cd5330367e067f0435ba462077c52f313c67d Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Mon, 3 Apr 2023 12:48:05 +0200 Subject: [PATCH] Reject stun urls with query parameters for consistency with Chromium behavior, in particular stun:host?transport=udp gets rejected. BUG=chromium:1385735 Change-Id: I85a141ecf72480bfa09d8354d6dcaef8ca0cdcff Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299943 Reviewed-by: Harald Alvestrand Reviewed-by: Guido Urdaneta Commit-Queue: Philipp Hancke Cr-Commit-Position: refs/heads/main@{#39916} --- pc/ice_server_parsing.cc | 9 +++++++++ pc/ice_server_parsing_unittest.cc | 2 ++ 2 files changed, 11 insertions(+) diff --git a/pc/ice_server_parsing.cc b/pc/ice_server_parsing.cc index 9322fd12d4..896305c54b 100644 --- a/pc/ice_server_parsing.cc +++ b/pc/ice_server_parsing.cc @@ -220,6 +220,15 @@ RTCError ParseIceServerUrl( // GetServiceTypeAndHostnameFromUri should never give an empty hoststring RTC_DCHECK(!hoststring.empty()); + // stun with ?transport (or any ?) is not valid. + if ((service_type == ServiceType::STUN || + service_type == ServiceType::STUNS) && + tokens.size() > 1) { + LOG_AND_RETURN_ERROR( + RTCErrorType::SYNTAX_ERROR, + "ICE server parsing failed: Invalid stun url with query parameters"); + } + int default_port = kDefaultStunPort; if (service_type == ServiceType::TURNS) { default_port = kDefaultStunTlsPort; diff --git a/pc/ice_server_parsing_unittest.cc b/pc/ice_server_parsing_unittest.cc index 4cb7c47b0b..4356b1efb0 100644 --- a/pc/ice_server_parsing_unittest.cc +++ b/pc/ice_server_parsing_unittest.cc @@ -188,6 +188,8 @@ TEST_F(IceServerParsingTest, ParseHostnameAndPort) { EXPECT_FALSE(ParseUrl("stun:/hostname")); // / is not allowed EXPECT_FALSE(ParseUrl("stun:?hostname")); // ? is not allowed EXPECT_FALSE(ParseUrl("stun:#hostname")); // # is not allowed + // STUN explicitly forbids query parameters. + EXPECT_FALSE(ParseUrl("stun:hostname?transport=udp")); } // Test parsing the "?transport=xxx" part of the URL.