naimdjon
naimdjon

Reputation: 3624

Azure AppGateway/WAF is removing header on WebSocket connect

I am sending an id header when connecting to my message broker so I can send server-generated messages to specific user. This id header is missing in the connect message. My configuration looks like this (spring boot):

override fun configureClientInboundChannel(registration: ChannelRegistration) {
        registration.interceptors(object : ChannelInterceptor {
            override fun preSend(message: Message<*>, channel: MessageChannel): Message<*> {
                val accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor::class.java)!!
                if (accessor.command == StompCommand.CONNECT) {
                    val id = accessor.getFirstNativeHeader("id")
                    if (id == null) {
                        log.warn("id header is missing: "+accessor.messageHeaders)
                    } else {
                        accessor.user = Principal { id }
                    }
                }
                return message
            }
        })
    }

The log displays the following:

2024-04-05 11:06:41.173 l=WARN  logger=WebSocketConfiguration.kt - id header is missing: {simpMessageType=CONNECT, stompCommand=CONNECT, 
nativeHeaders={accept-version=[1.2,1.1,1.0], heart-beat=[10000,10000]}, simpSessionAttributes={}, 
simpHeartbeat=[J@59f06a38, simpSessionId=1398788d-1ebf-4a20-0b23-9d6ecd27e227} 
t=http-nio-8081-exec-5  

The client connects like this:

const id = anonymousUser.id;
this.client = new Client({
      brokerURL: `${webSocketUrl}/websocket-broker`,
      onConnect: (frame) => {
        logDebug("Connected to broker: " + webSocketUrl);
      },
      connectHeaders: { id },
    });
    this.client.activate();

The Chrome Network Inspector tab shows that the connection has succeeded:

enter image description here

This works as expected in an environment where I do not have enabled WAF. So I believe WAF is somehow stripping the id header. Appreciate any insight.

Upvotes: 0

Views: 42

Answers (0)

Related Questions