Skip to main content
Menu
Advisories

Open redirect via protocol-relative path in HLS and WebRTC trailing-slash redirects

GHSA-48F4-WM59-FXC5Published Updated GitHub

Description

The HLS and WebRTC HTTP servers each defined a local mergePathAndQuery helper used to build the Location header for the automatic redirect issued when a request path is missing its trailing slash (e.g. GET /mypath → 302 Location: /mypath/). This helper simply concatenated ctx.Request.URL.Path + "/" with the raw query string, performing no validation or sanitization of the path.

Because ctx.Request.URL.Path is taken directly from the incoming request and can contain multiple leading slashes, a request such as GET //interact.sh/en causes the server to respond with Location: //interact.sh/en/. A Location header beginning with // is a protocol-relative URL, which browsers resolve against the same scheme but an attacker-chosen host, resulting in an open redirect from the MediaMTX server to an arbitrary external domain.

This helper was introduced when both HTTP servers were changed to use absolute paths in the Location header, replacing an earlier helper that stripped leading slashes before rebuilding the path — effectively reintroducing an open-redirect flaw that had already been fixed once before.

The issue was fixed in PR #5708, which replaced the unsafe helper with two new functions, trailingSlashLocation and sanitizeLocation, in both HTTP servers. Both call path.Clean on the raw path and then strip all leading slashes and backslashes before re-prepending a single /, neutralizing protocol-relative payloads regardless of how many leading slashes are supplied.

Affected versions

References

GitHub · bluenviron/mediamtx