Repository navigation
Add support for websockets - #4579
Conversation
|
Hi ! This looks pretty cool ! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4579 +/- ##
==========================================
+ Coverage 81.18% 81.20% +0.02%
==========================================
Files 375 376 +1
Lines 98917 99209 +292
==========================================
+ Hits 80303 80565 +262
- Misses 18614 18644 +30
🚀 New features to boost your workflow:
|
106cc9a to
60a13b7
Compare
|
Is there anything that's currently stopping the PR from being merged? |
|
This branch has a conflict with http.py Would you be able to resolve it? |
There was a problem hiding this comment.
Pull request overview
Adds a new WebSocket dissector as a Scapy contrib layer and updates HTTP parsing to better handle WebSocket upgrade traffic (notably responses that omit the reason phrase), with accompanying pcaps and unit tests to exercise the new functionality.
Changes:
- Add
scapy.contrib.websocketWebSocket layer with TCP stream reassembly support and optional permessage-deflate handling. - Update HTTP request/response first-line dissection to tolerate missing components (e.g., omitted reason phrase).
- Add new test pcaps and a contrib
.utstest suite for WebSocket parsing/building.
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
scapy/contrib/websocket.py |
New WebSocket layer implementation (framing, masking, TCP reassembly, compression hooks). |
scapy/layers/http.py |
Adjust HTTP start-line parsing to allow missing reason phrase (WebSocket upgrade responses). |
test/contrib/websocket.uts |
New unit tests validating WebSocket frame build/dissect and TCPSession behavior using pcaps. |
test/pcaps/websocket_compressed_session.pcap |
Fixture pcap for TCPSession + permessage-deflate coverage. |
test/pcaps/websocket_invalid_handshakes.pcap |
Fixture pcap for invalid/partial upgrade sequences coverage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
AI-Assisted: no
AI-Assisted: no
Preserve explicit payload lengths and reuse the length field during TCP reassembly. Add standard WebSocket HTTP headers and handle compression per sender. AI-Assisted: yes (Codex, GPT-6)
Preserve compressed bodies when editing frame headers and handle final DEFLATE blocks with context takeover. Add RFC examples and gzip capture fixtures. AI-Assisted: yes (Codex, GPT-6)
Count all body layers while excluding subsequent WebSocket frames and padding. AI-Assisted: yes (Codex, GPT-6)
Count each body layer up to the next WebSocket frame to keep chained-frame builds linear. AI-Assisted: yes (Codex, GPT-6)
Add HTTP_Server.upgrade() and WebSocket handshake preparation, then switch the connection to frame parsing after an accepted upgrade. AI-Assisted: yes (Codex, GPT-6)
AI-Assisted: yes (Codex, GPT-6)
Prepare the h2c handshake and initial SETTINGS, retain the stream-1 request, and reassemble frames after the client connection preface. AI-Assisted: yes (Codex, GPT-6)
AI-Assisted: yes (Codex, GPT-6)
Move protocol switching into StreamSocket.set_proto() and retain buffered bytes and shared session state. Process queued peekless data before reading from the network. AI-Assisted: yes (Codex, GPT-6)
Avoid DNS dissection when the regression campaign enables debug_dissector. AI-Assisted: yes (Codex, GPT-6) tests: use TCP in the stream protocol switch test AI-Assisted: yes (Codex, GPT-6)
AI-Assisted: yes (Codex, GPT-6)
|
Congrats! |
Adds support for websockets.
HTTP dissector has been updated to support omitting the reason phrase as this is usually done when upgrading to websocket connection.
fixes #4578