Skip to content

Add support for websockets - #4579

Merged
gpotter2 merged 13 commits into
secdev:masterfrom
lucasdrufva:master
Nov 27, 2026
Merged

gpotter2 merged 13 commits into
secdev:masterfrom
lucasdrufva:master

Conversation

@lucasdrufva

@lucasdrufva lucasdrufva commented Nov 3, 2024 •

Copy link
Copy Markdown
Contributor

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

@gpotter2

gpotter2 commented Nov 3, 2024

Copy link
Copy Markdown
Member

Hi ! This looks pretty cool !

@codecov

codecov Bot commented Nov 6, 2024 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.81672% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.20%. Comparing base (7e72d2e) to head (7b3db5a).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
scapy/contrib/websocket.py 88.15% 25 Missing ⚠️
scapy/contrib/http2.py 82.45% 10 Missing ⚠️
scapy/supersocket.py 81.81% 4 Missing ⚠️
scapy/layers/http.py 90.47% 2 Missing ⚠️
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     
Files with missing lines Coverage Δ
scapy/layers/http.py 83.18% <90.47%> (+0.39%) ⬆️
scapy/supersocket.py 78.12% <81.81%> (+1.03%) ⬆️
scapy/contrib/http2.py 96.20% <82.45%> (-0.90%) ⬇️
scapy/contrib/websocket.py 88.15% <88.15%> (ø)

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lucasdrufva
lucasdrufva force-pushed the master branch 2 times, most recently from 106cc9a to 60a13b7 Compare November 8, 2024 16:51
@lucasdrufva
lucasdrufva marked this pull request as ready for review November 8, 2024 17:37
@Nemoumbra

Copy link
Copy Markdown

Is there anything that's currently stopping the PR from being merged?

@polybassa

Copy link
Copy Markdown
Contributor

This branch has a conflict with http.py

Would you be able to resolve it?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.websocket WebSocket 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 .uts test 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.

Comment thread scapy/contrib/websocket.py Resolved
Comment thread scapy/layers/http.py Resolved
Comment thread scapy/contrib/websocket.py Resolved
Comment thread scapy/contrib/websocket.py Resolved
Comment thread scapy/contrib/websocket.py Resolved
Comment thread scapy/contrib/websocket.py Resolved
Comment thread scapy/contrib/websocket.py Resolved
Comment thread scapy/contrib/websocket.py Resolved
Comment thread scapy/contrib/websocket.py Resolved
Comment thread scapy/contrib/websocket.py Resolved
lucasdrufva and others added 6 commits November 27, 2026 01:00
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)
gpotter2
gpotter2 previously approved these changes Nov 27, 2026
@gpotter2
gpotter2 enabled auto-merge (squash) November 27, 2026 00:37
@gpotter2
gpotter2 disabled auto-merge November 27, 2026 00:45
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)
gpotter2
gpotter2 previously approved these changes Nov 27, 2026
@gpotter2
gpotter2 enabled auto-merge (squash) November 27, 2026 00:53
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)
gpotter2
gpotter2 previously approved these changes Nov 27, 2026
@gpotter2
gpotter2 merged commit 77d6079 into secdev:master Nov 27, 2026
22 of 23 checks passed
@Nemoumbra

Copy link
Copy Markdown

Congrats!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Websocket support

5 participants