Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/mqtt_broker.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,10 +1016,17 @@ static int callback_broker_mqtt(struct lws *wsi,
char origin[256];
int olen = lws_hdr_copy(wsi, origin, (int)sizeof(origin),
WSI_TOKEN_ORIGIN);
if (olen > 0 &&
XSTRCMP(origin, broker->ws_allowed_origin) != 0) {
/* lws_hdr_copy returns <= 0 both when no Origin header is sent
* (native client, allowed) and when a present Origin is too long
* for the buffer. Deciding on olen alone lets an attacker-chosen
* Origin longer than the buffer be treated as absent and slip past
* the allowlist. Use the header's real length to tell the two
* apart and reject a present-but-unverifiable Origin. */
if (lws_hdr_total_length(wsi, WSI_TOKEN_ORIGIN) > 0 &&
(olen <= 0 ||
XSTRCMP(origin, broker->ws_allowed_origin) != 0)) {
WBLOG_ERR(broker, "broker: ws origin rejected: %s",
BrokerLog_Sanitize(origin));
BrokerLog_Sanitize(olen > 0 ? origin : "(oversized)"));
return -1;
}
}
Expand Down
Loading