-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
[rb] fix silent hang on oversized WebSocket frames #17655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aguspe
merged 12 commits into
SeleniumHQ:trunk
from
aguspe:rb-fix-websocket-large-frame
Aug 18, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ce6fe48
[rb] fix silent hang on oversized WebSocket frames
aguspe 510ee4e
address qodo comments
aguspe c85c861
Merge branch 'trunk' into rb-fix-websocket-large-frame
aguspe f23041f
Merge branch 'trunk' into rb-fix-websocket-large-frame
aguspe 8f74b3c
Merge branch 'trunk' into rb-fix-websocket-large-frame
aguspe fe70405
address qodo re-review
aguspe a68f5a0
Merge branch 'rb-fix-websocket-large-frame' of github.com:aguspe/sele…
aguspe 2743b29
Merge branch 'trunk' into rb-fix-websocket-large-frame
cgoldberg 0878461
raise IOError from send_cmd fail-fast to keep closed-connection error…
aguspe 646f473
Merge branch 'rb-fix-websocket-large-frame' of github.com:aguspe/sele…
aguspe 6bb8ae3
Merge branch 'trunk' into rb-fix-websocket-large-frame
aguspe 8164bcd
Merge branch 'trunk' into rb-fix-websocket-large-frame
aguspe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
rb/spec/unit/selenium/webdriver/common/websocket_connection_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| require File.expand_path('../spec_helper', __dir__) | ||
| require 'stringio' | ||
|
|
||
| module Selenium | ||
| module WebDriver | ||
| describe WebSocketConnection do | ||
| # Build an instance without opening a socket so the frame-handling logic | ||
| # can be exercised in isolation. | ||
| subject(:connection) { described_class.allocate } | ||
|
|
||
| around do |example| | ||
| original = WebSocket.max_frame_size | ||
| example.call | ||
| ensure | ||
| WebSocket.max_frame_size = original | ||
| end | ||
|
qodo-code-review[bot] marked this conversation as resolved.
|
||
|
|
||
| describe '#apply_frame_size_limit' do | ||
| it 'raises the global limit when it is below the Selenium default' do | ||
| WebSocket.max_frame_size = 1 | ||
|
|
||
| connection.send(:apply_frame_size_limit) | ||
|
|
||
| expect(WebSocket.max_frame_size).to eq(described_class::MAX_FRAME_SIZE) | ||
| end | ||
|
|
||
| it 'leaves a larger user-configured limit untouched' do | ||
| larger = described_class::MAX_FRAME_SIZE * 2 | ||
| WebSocket.max_frame_size = larger | ||
|
|
||
| connection.send(:apply_frame_size_limit) | ||
|
|
||
| expect(WebSocket.max_frame_size).to eq(larger) | ||
| end | ||
| end | ||
|
|
||
| describe '#close' do | ||
| let(:socket) { StringIO.new } | ||
|
|
||
| before do | ||
| connection.instance_variable_set(:@closing_mtx, Mutex.new) | ||
| connection.instance_variable_set(:@socket, socket) | ||
| connection.instance_variable_set(:@callback_threads, ThreadGroup.new) | ||
| end | ||
|
|
||
| it 'still closes the socket when the listener already initiated shutdown' do | ||
| connection.instance_variable_set(:@closing, true) | ||
|
|
||
| connection.close | ||
|
|
||
| expect(socket).to be_closed | ||
| end | ||
| end | ||
|
|
||
| describe '#send_cmd' do | ||
| it 'fails fast when the connection is closing' do | ||
| connection.instance_variable_set(:@closing, true) | ||
|
|
||
| expect { connection.send_cmd(method: 'foo') } | ||
| .to raise_error(IOError, /closed/) | ||
| end | ||
| end | ||
|
|
||
| describe '#frame_dropped?' do | ||
| let(:incoming_frame) { WebSocket::Frame::Incoming::Client.new(version: 13) } | ||
| let(:socket) { StringIO.new } | ||
|
|
||
| before do | ||
| connection.instance_variable_set(:@incoming_frame, incoming_frame) | ||
| connection.instance_variable_set(:@closing_mtx, Mutex.new) | ||
| connection.instance_variable_set(:@socket, socket) | ||
| end | ||
|
|
||
| it 'is false when there is no decoding error' do | ||
| expect(connection.send(:frame_dropped?)).to be(false) | ||
| end | ||
|
|
||
| it 'is true and closes the connection when a frame exceeds the maximum size' do | ||
| WebSocket.max_frame_size = 1 | ||
| raw = WebSocket::Frame::Outgoing::Server.new(version: 13, data: 'a' * 1024, type: 'text').to_s | ||
| incoming_frame << raw | ||
| incoming_frame.next | ||
|
|
||
| expect(connection.send(:frame_dropped?)).to be(true) | ||
| expect(incoming_frame.error?).to be(true) | ||
| expect(connection.instance_variable_get(:@closing)).to be(true) | ||
| expect(socket).to be_closed | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.