Fix an issue where ActiveMQ failed to properly support STOMP spec#1
Fix an issue where ActiveMQ failed to properly support STOMP spec#1ehossack-aws wants to merge 3 commits intomainfrom
Conversation
| } else if (b == Stomp.ESCAPE) { | ||
| isEscaping = true; | ||
| } | ||
| outputStream.write(b); |
There was a problem hiding this comment.
what about trailing ESCAPE? is it valid?
There was a problem hiding this comment.
What's a trailing escape? In this context, these are headers, so there must be a body that follows
There was a problem hiding this comment.
I was wondering what if line 205 is executed and the next byte is '\n'? Can a legit header value end with an unescaped backslash?
There was a problem hiding this comment.
Yeah it should be just a backslash then. There's nothing in the spec to prevent that.
| baos.write(b); | ||
| if (isEscaping) { | ||
| if (!isValidEscapedCharacter(b)) { | ||
| throw new ProtocolException("Undefined escape sequence [\\"+((char) (b & 0xFF))+"] found in header!", true); |
There was a problem hiding this comment.
We should not check escape sequences' validity for the CONNECT frame's headers.
(Moreover, we should not decode them as well, but that's clearly out of scope of this PR.)
Reason: stomp v1.2 provides backward compatibility with v1.0 and thats why CONNECT's headers should not be escaped: https://stomp.github.io/stomp-specification-1.2.html#Connecting
One of the possible headers for the CONNECT frame is password. And password might contain just anything, including an unescaped backslash followed by an alphanumeric symbol.
Here is a couple of examples of popular clients that do not escape CONNECT's headers:
-
stomp.py makes an explicit exception:
https://github.com/jasonrbriggs/stomp.py/blob/fbab0c82d4e91ed364c17fd4977fdd6fe2b58b27/stomp/protocol.py#L241 -
stomp-js only enables escaping upon receiving CONNECTED (i.e. after the CONNECT frame is sent)
https://github.com/stomp-js/stompjs/blob/develop/src/stomp-handler.ts#L197
This fixes an issue where ActiveMQ incorrectly accepts undefined header escape sequences. https://stomp.github.io/stomp-specification-1.1.html\#Value_Encoding https://stomp.github.io/stomp-specification-1.2.html\#Value_Encoding
c570d7e to
6121255
Compare
|
|
||
| @Test(timeout = 60000) | ||
| public void testStompHeaderWithUndefinedEscapeSequenceInAllowedConnectHeader() throws Exception { | ||
| String connectFrame = "CONN\\xECT\n" + |
There was a problem hiding this comment.
it's not clear to me why \\x is just ignored here
There was a problem hiding this comment.
Oh hmm.. I misread your interpretation of the spec as us not reading escaped characters in the CONNECT frame.
What do you think the previous patch was missing? The code I have touched deals with CONNECT/CONNECTED decoding whereas the code you referenced deals with encoding on the response.
There was a problem hiding this comment.
Hmmm. I referenced CONNECT frame's headers.
This is what I would expect to work without any attempt to decode the password:
CONNECT
login:ololo
passcode:bla\h\blah\na\\h
...
And this is something weird, that should not result in CONNECTED %) (but not because of escaping;))
CONN\\xECT
...
There was a problem hiding this comment.
Gotcha, I'm less confused now! I think I woke up too early today 😅
The STOMP spec lists several allowed escaped characters in headers, with the rest noted:
An attempt was previously made to fix this by Gary Tully (https://issues.apache.org/jira/browse/AMQ-3501), but the validated escape sequences were not correct. (Example of correct escaping: jasonrbriggs/stomp.py@c2c0824#diff-f0aa9543d5e7800d4ac1074798a70e058ea1d7859f106a3a4de95e54b6bf98faR122)
This was fixed in Artemis: apache/artemis@a99617a
and this is an implementation for ActiveMQ.
This is a breaking change, but I believe it's the best for consumers as to not cause confusion.
Here's some sample code that would previously have worked but no longer works: