Fix duplicate websocket header handling in IIS Out-Of-Process handler#65077
Fix duplicate websocket header handling in IIS Out-Of-Process handler#65077
Conversation
Co-authored-by: DeagleGross <31598696+DeagleGross@users.noreply.github.com>
Co-authored-by: DeagleGross <31598696+DeagleGross@users.noreply.github.com>
Co-authored-by: DeagleGross <31598696+DeagleGross@users.noreply.github.com>
Co-authored-by: DeagleGross <31598696+DeagleGross@users.noreply.github.com>
|
@copilot updated the function to be generic one, review the code and apply suggestions if any |
…OKEN_LENGTH constant Co-authored-by: DeagleGross <31598696+DeagleGross@users.noreply.github.com>
Reviewed the generic
|
There was a problem hiding this comment.
Pull request overview
This PR fixes an inconsistency between IIS Out-Of-Process and Kestrel when handling WebSocket upgrade requests with duplicate Upgrade: websocket, websocket headers. Previously, IIS Out-Of-Process rejected such requests due to an exact string match check, while Kestrel accepted them by parsing comma-separated header values. The RFC doesn't require header values to be distinct.
Changes:
- Added a generic
ContainsToken()helper function in the ANCM forwarder to properly parse and validate comma-separated HTTP header values - Added a test demonstrating that Kestrel correctly accepts WebSocket upgrade requests with duplicate "websocket" header values
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp | Implements ContainsToken() helper function to parse comma-separated header values and replaces exact string match with token-based matching for WebSocket upgrade detection |
| src/Middleware/WebSockets/test/UnitTests/WebSocketMiddlewareTests.cs | Adds test verifying that duplicate websocket upgrade headers are accepted |
Co-authored-by: DeagleGross <31598696+DeagleGross@users.noreply.github.com>
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
Fix duplicate websocket header handling in IIS Out-Of-Process handler
Fix IIS Out-Of-Process to accept WebSocket requests with duplicate
Upgrade: websocket, websocketheaderDescription
IIS Out-Of-Process rejected WebSocket requests when the
Upgradeheader contained duplicate values likewebsocket, websocket, while Kestrel accepted them. The RFC doesn't require values to be distinct.Root cause: The ANCM check in
forwardinghandler.cpprequired an exact match:This fails when header length != 9 (e.g.,
websocket, websocketis 20 chars).Fix: Added a generic
ContainsToken()helper function that parses comma-separated header values and checks if any token matches the expected value (case-insensitive), matching Kestrel'sGetCommaSeparatedValues()approach.Changes:
forwardinghandler.cpp: Add genericContainsToken()helper function to properly parse comma-separated header valuesWebSocketMiddlewareTests.cs: Add Kestrel unit test for duplicate websocket header scenarioWebSocketTests.cs: Add IIS Out-Of-Process functional test to verify the C++ fix works correctly with duplicateUpgrade: websocket, websocketheadersOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.