Skip to content

fix: reject backslashes in WebSocket destination paths - #497

Merged
Tony133 merged 3 commits into
mainfrom
fix/reject-path-backslashes
Nov 15, 2026
Merged

Tony133 merged 3 commits into
mainfrom
fix/reject-path-backslashes

Conversation

@mcollina

Copy link
Copy Markdown
Member

Since @fastify/reply-from 12.8.1, plain HTTP requests whose decoded path contains a backslash are rejected with a 400, but WebSocket upgrades don't go through reply-from and still forwarded paths such as /pub/foo%5Cbar to the upstream. This makes validateDestination reject raw and percent-encoded backslashes in the path, so HTTP requests, WebSocket upgrades and reply.fromParameters all behave the same. Backslashes in the query string are still forwarded.

The WebSocket test that expected %5C to be forwarded now expects a rejection on both transports, with a new control for a %5C in the query string. The httpExpected test plumbing added in c32e69c is no longer needed and is removed. The README documents the behavior.

This is a behavior change for WebSocket users who relied on encoded backslashes in paths.

Since @fastify/reply-from 12.8.1, HTTP requests whose decoded path contains
a backslash are rejected with a 400, while WebSocket upgrades, which do not
go through reply-from, still forwarded them. Reject raw and percent-encoded
backslashes in validateDestination so HTTP, WebSocket and
reply.fromParameters behave the same. Backslashes in the query string are
still forwarded.

@Tony133 Tony133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

One non-blocking note: there is no WebSocket test for a raw backslash without .. (e.g. /pub/foo\bar). Might be worth adding one.

@Tony133 Tony133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Tony133
Tony133 merged commit 741d984 into main Nov 15, 2026
20 checks passed
@Tony133
Tony133 deleted the fix/reject-path-backslashes branch November 15, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants