Skip to content

Connect URL Parser failure #259

Description

@Astaelan

Based on hunting a customer issue for SignalWire, I came across the following issue that Claude was able to identify:

Symptom: Customer LaML <Connect><Stream url="wss://…/socket/twilio/agent:KlaraL"> fails on SignalWire with "Stream Error – The Connection was Refused"; same URL works on Twilio.

Root cause

URL-parser bug in libks kws_connect_ex at src/libs/libks/src/kws.c:1720-1740. The parser strips the port from the URL before separating the path, so the first : anywhere in the URL is treated as the port delimiter:

host = ks_pstrdup(pool, p);                 // p = everything after wss://
if ((p = strchr(host, ':'))) {              // finds ':' anywhere — including in the path
    *p++ = '\0';
    if (p) port = (ks_port_t)atoi(p);
}
p = strchr(p, '/');                         // search continues from past the ':'
if (p) { path = ks_pstrdup(pool, p); *p = '\0'; }
else   { path = "/"; }

Per RFC 3986, : is a valid character inside path segments (pchar). The customer's URL is well-formed; the parser is wrong.

Proposed fix (libks kws_connect_ex)

Split path first, then look for the port inside only the authority portion:

host = ks_pstrdup(pool, p);

/* split path first */
if ((p = strchr(host, '/'))) {
    path = ks_pstrdup(pool, p);
    *p = '\0';
} else {
    path = "/";
}

/* then look for port within host only */
if ((p = strchr(host, ':'))) {
    *p++ = '\0';
    if (*p) port = (ks_port_t)atoi(p);
}

Worth also handling [ipv6]:port while touching this block — the existing // if (*host == '[') // todo ipv6 comment shows it's been deferred before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions