Skip to content

Commit 0872ef4

Browse files
authored
Validate URI scheme and HTTP headers in ConnectProvider (#137)
* Validate URI scheme in Connect, allow only ws/wss * Validate HTTP header names and strip CRLF from values in ConnectProvider
1 parent e28b146 commit 0872ef4

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • src/main/kotlin/org/jitsi/xmpp/extensions/colibri2

src/main/kotlin/org/jitsi/xmpp/extensions/colibri2/Connect.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ class ConnectProvider : DefaultPacketExtensionProvider<Connect>(Connect::class.j
121121
} catch (e: Exception) {
122122
throw SmackParsingException("Invalid 'url': ${e.message}")
123123
}
124+
if (uri.scheme !in listOf("ws", "wss")) {
125+
throw SmackParsingException("Invalid 'url' scheme: ${uri.scheme}. Only 'ws' and 'wss' are allowed.")
126+
}
124127
val audio = parser.getAttributeValue("", Connect.AUDIO_ATTR_NAME)?.toBoolean() ?: false
125128
val video = parser.getAttributeValue("", Connect.VIDEO_ATTR_NAME)?.toBoolean() ?: false
126129
val protocolStr = parser.getAttributeValue("", Connect.PROTOCOL_ATTR_NAME)
@@ -152,11 +155,15 @@ class ConnectProvider : DefaultPacketExtensionProvider<Connect>(Connect::class.j
152155
?: throw SmackParsingException.RequiredAttributeMissingException(
153156
"Missing 'name' attribute in http-header element"
154157
)
158+
if (!headerName.matches(Regex("[A-Za-z0-9\\-]+"))) {
159+
throw SmackParsingException("Invalid HTTP header name: $headerName")
160+
}
155161
val headerValue = parser.getAttributeValue("", Connect.HttpHeader.VALUE_ATTR_NAME)
156162
?: throw SmackParsingException.RequiredAttributeMissingException(
157163
"Missing 'value' attribute in http-header element"
158164
)
159-
connect.addHttpHeader(headerName, headerValue)
165+
val sanitizedValue = headerValue.replace("\r", "").replace("\n", "")
166+
connect.addHttpHeader(headerName, sanitizedValue)
160167
}
161168
Connect.Ping.ELEMENT -> {
162169
val intervalStr = parser.getAttributeValue("", Connect.Ping.INTERVAL_ATTR_NAME)

0 commit comments

Comments
 (0)