Skip to content

Commit 1803348

Browse files
committed
Check STOMP headers against ending backslash
Issue: SPR-12418
1 parent 1988f8c commit 1803348

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ private String unescape(String inString) {
260260

261261
while (index >= 0) {
262262
sb.append(inString.substring(pos, index));
263+
if((index + 1) >= inString.length()) {
264+
throw new StompConversionException("Illegal escape sequence at index " + index + ": " + inString);
265+
}
263266
Character c = inString.charAt(index + 1);
264267
if (c == 'r') {
265268
sb.append('\r');

spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/BufferingStompDecoderTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ public void incompleteCommand() throws InterruptedException {
185185
assertEquals(0, messages.size());
186186
}
187187

188+
@Test(expected = StompConversionException.class) // SPR-12418
189+
public void endingBackslashHeaderValueCheck() throws InterruptedException {
190+
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
191+
String payload = "SEND\na:alpha\\\n\nMessage body\0";
192+
stompDecoder.decode(toByteBuffer(payload));
193+
}
194+
188195

189196
private ByteBuffer toByteBuffer(String chunk) {
190197
return ByteBuffer.wrap(chunk.getBytes(Charset.forName("UTF-8")));

0 commit comments

Comments
 (0)