webrtc: fix deprecated webrtcICEServers parser for IPv6 hosts; (#5932)

strings.Split produces wrong part count when the host contains colons
(IPv6). SplitN(s, ";", 4) keeps the hostport token intact.

---------

Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com>
This commit is contained in:
Kai P.
2026-08-25 06:55:05 +00:00
committed by GitHub
co-authored by aler9
parent 3f2b3cd3f5
commit cf5cd38cf9
2 changed files with 19 additions and 3 deletions
+4 -3
View File
@@ -986,10 +986,11 @@ func (conf *Conf) Validate(l logger.Writer) error {
"and has been replaced with 'webrtcICEServers2'")
for _, server := range *conf.WebRTCICEServers {
parts := strings.Split(server, ":")
if len(parts) == 5 {
// old format: scheme:username:password:hostport; SplitN avoids splitting IPv6 colons
parts := strings.SplitN(server, ":", 4)
if len(parts) == 4 {
conf.WebRTCICEServers2 = append(conf.WebRTCICEServers2, WebRTCICEServer{
URL: parts[0] + ":" + parts[3] + ":" + parts[4],
URL: parts[0] + ":" + parts[3],
Username: parts[1],
Password: parts[2],
})
+15
View File
@@ -343,6 +343,21 @@ func TestConfDeprecatedAuth(t *testing.T) {
}, conf.AuthInternalUsers)
}
func TestConfDeprecatedWebRTCICEServersIPv6(t *testing.T) {
tmpf := createTempFile(t, []byte(
"webrtcICEServers:\n"+
"- \"turn:myuser:mypass:[2001:db8::1]:3478?transport=tcp\"\n"))
conf, _, err := Load(tmpf, nil, nil)
require.NoError(t, err)
require.Equal(t, []WebRTCICEServer{{
URL: "turn:[2001:db8::1]:3478?transport=tcp",
Username: "myuser",
Password: "mypass",
}}, conf.WebRTCICEServers2)
}
func TestConfErrors(t *testing.T) {
for _, ca := range []struct {
name string