Skip to content

Commit be26f4e

Browse files
amizurovnormanmaurer
authored andcommitted
Fixed incorrect Sec-WebSocket-Origin header for v13, see netty#9134 (netty#9312)
Motivation: Based on https://tools.ietf.org/html/rfc6455#section-1.3 - for non-browser clients, Origin header field may be sent if it makes sense in the context of those clients. Modification: Replace Sec-WebSocket-Origin to Origin Result: Fixes netty#9134 .
1 parent b02ee11 commit be26f4e

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public WebSocketClientHandshaker13(URI webSocketURL, WebSocketVersion version, S
189189
* Upgrade: websocket
190190
* Connection: Upgrade
191191
* Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
192-
* Sec-WebSocket-Origin: http://example.com
192+
* Origin: http://example.com
193193
* Sec-WebSocket-Protocol: chat, superchat
194194
* Sec-WebSocket-Version: 13
195195
* </pre>
@@ -225,7 +225,7 @@ protected FullHttpRequest newHandshakeRequest() {
225225
.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE)
226226
.set(HttpHeaderNames.SEC_WEBSOCKET_KEY, key)
227227
.set(HttpHeaderNames.HOST, websocketHostValue(wsURL))
228-
.set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, websocketOriginValue(wsURL));
228+
.set(HttpHeaderNames.ORIGIN, websocketOriginValue(wsURL));
229229

230230
String expectedSubprotocol = expectedSubprotocol();
231231
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
@@ -251,7 +251,7 @@ protected FullHttpRequest newHandshakeRequest() {
251251
*
252252
* @param response
253253
* HTTP response returned from the server for the request sent by beginOpeningHandshake00().
254-
* @throws WebSocketHandshakeException
254+
* @throws WebSocketHandshakeException if handshake response is invalid.
255255
*/
256256
@Override
257257
protected void verify(FullHttpResponse response) {

codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker13.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public WebSocketServerHandshaker13(
115115
* Upgrade: websocket
116116
* Connection: Upgrade
117117
* Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
118-
* Sec-WebSocket-Origin: http://example.com
118+
* Origin: http://example.com
119119
* Sec-WebSocket-Protocol: chat, superchat
120120
* Sec-WebSocket-Version: 13
121121
* </pre>

codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker07Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected CharSequence[] getHandshakeHeaderNames() {
4646
HttpHeaderNames.CONNECTION,
4747
HttpHeaderNames.SEC_WEBSOCKET_KEY,
4848
HttpHeaderNames.HOST,
49-
HttpHeaderNames.SEC_WEBSOCKET_ORIGIN,
49+
getOriginHeaderName(),
5050
HttpHeaderNames.SEC_WEBSOCKET_VERSION,
5151
};
5252
}

codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13Test.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@
1515
*/
1616
package io.netty.handler.codec.http.websocketx;
1717

18+
import io.netty.handler.codec.http.HttpHeaderNames;
1819
import io.netty.handler.codec.http.HttpHeaders;
1920

2021
import java.net.URI;
2122

2223
public class WebSocketClientHandshaker13Test extends WebSocketClientHandshaker07Test {
24+
2325
@Override
2426
protected WebSocketClientHandshaker newHandshaker(URI uri, String subprotocol, HttpHeaders headers,
2527
boolean absoluteUpgradeUrl) {
2628
return new WebSocketClientHandshaker13(uri, WebSocketVersion.V13, subprotocol, false, headers,
2729
1024, true, true, 10000,
2830
absoluteUpgradeUrl);
2931
}
32+
33+
@Override
34+
protected CharSequence getOriginHeaderName() {
35+
return HttpHeaderNames.ORIGIN;
36+
}
37+
3038
}

codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketRequestBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ public FullHttpRequest build() {
138138
headers.set(HttpHeaderNames.SEC_WEBSOCKET_KEY, key);
139139
}
140140
if (origin != null) {
141-
headers.set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, origin);
141+
if (version == WebSocketVersion.V13 || version == WebSocketVersion.V00) {
142+
headers.set(HttpHeaderNames.ORIGIN, origin);
143+
} else {
144+
headers.set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, origin);
145+
}
142146
}
143147
if (version != null) {
144148
headers.set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, version.toHttpHeaderValue());

0 commit comments

Comments
 (0)