An authenticated WebSocket handshake does not authorize every STOMP destination; inbound MESSAGE and SUBSCRIBE frames need separate destination rules.
Spring STOMP authorization: separate SEND from SUBSCRIBE permissions
Two frame types, two capabilities
A receipt client may send a command to an application prefix and subscribe to updates, but it must not publish directly to the broker topic. Authorization rules should allow the intended MESSAGE destination and deny client MESSAGE frames to broker prefixes. A SUBSCRIBE rule must also constrain which tenant or user queue can be observed. Handshake identity] establishes the principal; destination checks govern actions after connection.
Apply ownership to identifiers
A pattern such as /topic/tenants/{tenantId}/receipts is not safe merely because the caller is authenticated. Compare the tenantId with a verified tenant claim or domain authorization result. Keep a final deny rule for unhandled MESSAGE and SUBSCRIBE frames. Server-originated sends through SimpMessageSendingOperations follow a different path from client inbound messages. The STOMP boundary] explains that distinction.
Attack-test the matrix
Connect as two tenants. For each principal, attempt an allowed application SEND, a forbidden direct broker SEND, a permitted subscription, and a cross-tenant subscription. Assert denial at the inbound frame boundary and check that no forbidden message is broadcast. A successful HTTP handshake is not evidence that these four cases are covered.
Implementation contract
@Configuration
@EnableWebSocketSecurity
class ReceiptSocketSecurity {
@Bean
AuthorizationManager<Message<?>> messageAuthorization(
MessageMatcherDelegatingAuthorizationManager.Builder messages) {
messages.simpSubscribeDestMatchers("/user/queue/receipts")
.authenticated();
messages.simpTypeMatchers(SimpMessageType.SUBSCRIBE).denyAll();
messages.simpDestMatchers("/topic/**", "/queue/**").denyAll();
messages.simpDestMatchers("/app/receipts/**").authenticated();
messages.simpTypeMatchers(SimpMessageType.MESSAGE).denyAll();
messages.anyMessage().authenticated();
return messages.build();
}
}Cost and verification
Each inbound frame incurs matcher and authorization work. Broad subscriptions can also drive high fan-out and broker memory use; authorization and slow-client budgets] address different costs.
Common Mistakes
- Do not rely on HTTP handshake authentication as destination authorization.
- Do not permit client MESSAGE frames to broker-owned destinations.
- Do not use an authenticated-only rule for tenant-addressed subscriptions without checking tenant ownership.
Read next
Spring WebSocket STOMP identity: authenticate the handshake, authorize destinations, Spring WebSocket and STOMP: authenticate the handshake, authorize messages, Spring STOMP slow clients: send buffer and message-size limits, Spring STOMP simple broker versus relay: the multi-instance boundary, Spring Security filter chain: authentication, CSRF and request order.
