1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:07:34 +00:00

LibWeb: Send Origin on WebSocket connection

Some services using WebSockets require that the request contains the
Origin header, otherwise these services will return a 403 Forbidden
response. WebSocketServer already supports sending the Origin header,
however LibWeb did not send the origin with the IPC request.
This commit is contained in:
Michiel Visser 2022-02-17 11:19:19 +01:00 committed by Andreas Kling
parent 21ba9c808e
commit 39409438b2
2 changed files with 5 additions and 4 deletions

View file

@ -47,9 +47,9 @@ WebSocketClientManager::WebSocketClientManager(NonnullRefPtr<Protocol::WebSocket
{
}
RefPtr<Protocol::WebSocket> WebSocketClientManager::connect(const AK::URL& url)
RefPtr<Protocol::WebSocket> WebSocketClientManager::connect(const AK::URL& url, String const& origin)
{
return m_websocket_client->connect(url);
return m_websocket_client->connect(url, origin);
}
// https://websockets.spec.whatwg.org/#dom-websocket-websocket
@ -72,7 +72,8 @@ WebSocket::WebSocket(DOM::Window& window, AK::URL& url)
, m_window(window)
{
// FIXME: Integrate properly with FETCH as per https://fetch.spec.whatwg.org/#websocket-opening-handshake
m_websocket = WebSocketClientManager::the().connect(url);
auto origin_string = m_window->associated_document().origin().serialize();
m_websocket = WebSocketClientManager::the().connect(url, origin_string);
m_websocket->on_open = [weak_this = make_weak_ptr()] {
if (!weak_this)
return;