IIS ARR Not Passing Query Parameters to PHP Ratchet WebSocket Server

94 Views Asked by At

Environment:

PHP Ratchet WebSocket server configured behind IIS with ARR. The ARR setup is intended to forward WebSocket requests to the server listening on port 8080.

Issue:

WebSocket connections via wss://example.com/ntfs are not receiving expected query parameters like session_info, resulting in a 400 Bad Request error. Direct server access (e.g., ws://localhost:8080/ntfs?session_info) works fine, but remote connections fail due to this error. The IIS rewrite rule in the ntfs directory is set to forward requests to port 8080 and append query strings, but the parameters are not being passed, leading to the 400 error.

Logs/Diagnostics:

Conducted IIS failed request tracing, which revealed a 400 Bad Request error at the rewrite module processing stage. The tracing logs indicate that the rewrite rule is being triggered, but query parameters don't seem to be passed correctly.

Any suggestions on what I might be doing wrong?

EDIT

Here are key portions of my failed trace logs and rewrite rules.

  • GENERAL_REQUEST_START:

    • SiteId: [Redacted]
    • AppPoolId: [DefaultAppPool]
    • ConnId: [Redacted]
    • RequestURL: https://[example.com]/ntfs?session_info=%7B%22TLUserID%22%3A[UserID]%2C%22username%22%3A[Username]%2C%22groups%22%3A%5B%22GroupID%22%5D%7D
    • RequestVerb: GET
  • RULE_EVALUATION_START:

    • RuleName: WebSocketProxy
    • QueryString: session_info=%7B%22TLUserID%22%3A[UserID]%2C%22username%22%3A[Username]%2C%22groups%22%3A%5B%22GroupID%22%5D%7D
    • PatternSyntax: Regex
    • StopProcessing: true
    • RelativePath: /ntfs/
  • RULE_EVALUATION_END:

    • RuleName: WebSocketProxy
    • RequestURL: http://[example.com]:8080
    • QueryString: ?session_info=%7B%22TLUserID%22%3A[UserID]%2C%22username%22%3A[Username]%2C%22groups%22%3A%5B%22GroupID%22%5D%7D
    • StopProcessing: true
    • Succeeded: true
  • URL_CHANGED:

    • OldUrl: /ntfs?session_info=%7B%22TLUserID%22%3A[UserID]%2C%22username%22%3A[Username]%2C%22groups%22%3A%5B%22GroupID%22%5D%7D
    • NewUrl: http://[example.com]:8080?session_info=%7B%22TLUserID%22%3A[UserID]%2C%22username%22%3A[Username]%2C%22groups%22%3A%5B%22GroupID%22%5D%7D
  • MODULE_SET_RESPONSE_ERROR_STATUS:

    • ModuleName: ApplicationRequestRouting
    • Notification: EXECUTE_REQUEST_HANDLER
    • HttpStatus: 400
    • HttpReason: Bad Request
    • ErrorCode: The operation completed successfully (0x0)
  • GENERAL_SET_REQUEST_HEADER:

    • HeaderName: AspFilterSessionId
    • HeaderValue: [Empty]
    • Replace: true
  • GENERAL_REQUEST_END:

    • BytesSent: 557
    • BytesReceived: 600
    • HttpStatus: 400
    • HttpSubStatus: 0

Rewrite rules:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="WebSocketProxy" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://example.com:8080" logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
0

There are 0 best solutions below