Skip to content

Authentication via web socket crashes Electron #48505

Closed

Description

@CezaryKulakowski

Preflight Checklist

Electron Version

39.0.0-beta.1

What operating system(s) are you using?

Windows

Operating System Version

Windows 11

What arch are you using?

x64

Last Known Working Electron version

No response

Does the issue also appear in Chromium / Google Chrome?

No

Reproduction steps

  1. Start local http / websocket servers with following config:
const http = require('http');
const { WebSocketServer } = require('ws');

const server = http.createServer();

const wss = new WebSocketServer({ noServer: true });

server.on('upgrade', (req, socket, head) => {
  const auth = req.headers['authorization'] || '';
  const expected = 'Basic ' + Buffer.from('user:pass').toString('base64');

  if (auth !== expected) {
    // Respond with proper 401 for WebSocket handshake
    socket.write(
      'HTTP/1.1 401 Unauthorized\r\n' +
      'WWW-Authenticate: Basic realm="Test"\r\n' +
      'Content-Length: 0\r\n' +
      '\r\n'
    );
    socket.destroy();
    return;
  }

  // Accept the WebSocket upgrade
  wss.handleUpgrade(req, socket, head, (ws) => {
    wss.emit('connection', ws, req);
  });
});

wss.on('connection', ws => {
  ws.send('Authenticated!');
});

server.listen(8080, () => console.log('Auth WebSocket server running on ws://localhost:8080'));
  1. Start following Electron app:
    web_socket.zip

Expected Behavior

App doesn't crash.

Actual Behavior

App crashes with following callstack:

 	[Inline Frame] chrome.dll!base::ImmediateCrash() Line 186	C++
 	[Inline Frame] chrome.dll!logging::NotReachedFailure() Line 26	C++
>	[Inline Frame] chrome.dll!electron::ProxyingWebSocket::OnAuthRequiredComplete(electron::ProxyingWebSocket::AuthRequiredResponse rv) Line 389	C++
 	chrome.dll!electron::ProxyingWebSocket::OnHeadersReceivedCompleteForAuth(const net::AuthChallengeInfo & auth_info, int rv) Line 408	C++
 	[Inline Frame] chrome.dll!base::RepeatingCallback<void (media::CdmContext::Event)>::Run(media::CdmContext::Event args) Line 361	C++
 	[Inline Frame] chrome.dll!base::internal::DecayedFunctorTraits<base::RepeatingCallback<void (media::CdmContext::Event)>,media::CdmContext::Event &&>::Invoke(base::RepeatingCallback<void (media::CdmContext::Event)> && callback, media::CdmContext::Event && args) Line 820	C++
 	[Inline Frame] chrome.dll!base::internal::InvokeHelper<0,base::internal::FunctorTraits<base::RepeatingCallback<void (media::CdmContext::Event)> &&,media::CdmContext::Event &&>,void,0>::MakeItSo(base::RepeatingCallback<void (media::CdmContext::Event)> && functor, std::__Cr::tuple<media::CdmContext::Event> && bound) Line 920	C++
 	[Inline Frame] chrome.dll!base::internal::Invoker<base::internal::FunctorTraits<base::RepeatingCallback<void (media::CdmContext::Event)> &&,media::CdmContext::Event &&>,base::internal::BindState<0,1,1,base::RepeatingCallback<void (media::CdmContext::Event)>,media::CdmContext::Event>,void ()>::RunImpl(base::RepeatingCallback<void (media::CdmContext::Event)> && functor, std::__Cr::tuple<media::CdmContext::Event> && bound, std::__Cr::integer_sequence<unsigned long long,0>) Line 1057	C++
 	chrome.dll!base::internal::Invoker<base::internal::FunctorTraits<base::RepeatingCallback<void (media::CdmContext::Event)> &&,media::CdmContext::Event &&>,base::internal::BindState<0,1,1,base::RepeatingCallback<void (media::CdmContext::Event)>,media::CdmContext::Event>,void ()>::RunOnce(base::internal::BindStateBase * base) Line 970	C++
 	[Inline Frame] chrome.dll!base::OnceCallback<void ()>::Run() Line 156	C++
 	chrome.dll!base::TaskAnnotator::RunTaskImpl(base::PendingTask & pending_task) Line 209	C++
 	[Inline Frame] chrome.dll!base::TaskAnnotator::RunTask(perfetto::StaticString event_name, base::PendingTask & pending_task, base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl::<lambda_4> && args) Line 106	C++
 	[Inline Frame] chrome.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::LazyNow * continuation_lazy_now) Line 456	C++
 	chrome.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() Line 330	C++
 	chrome.dll!base::MessagePumpForUI::DoRunLoop() Line 265	C++
 	chrome.dll!base::MessagePumpWin::Run(base::MessagePump::Delegate * delegate) Line 89	C++
 	chrome.dll!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run(bool application_tasks_allowed, base::TimeDelta timeout) Line 629	C++
 	chrome.dll!base::RunLoop::Run(const base::Location & location) Line 136	C++
 	chrome.dll!content::BrowserMainLoop::RunMainMessageLoop() Line 1091	C++
 	[Inline Frame] chrome.dll!content::BrowserMainRunnerImpl::Run() Line 156	C++
 	chrome.dll!content::BrowserMain(content::MainFunctionParams parameters) Line 32	C++
 	[Inline Frame] chrome.dll!content::RunBrowserProcessMain(content::MainFunctionParams main_function_params, content::ContentMainDelegate * delegate) Line 713	C++
 	chrome.dll!content::ContentMainRunnerImpl::RunBrowser(content::MainFunctionParams main_params, bool start_minimal_browser) Line 1292	C++
 	chrome.dll!content::ContentMainRunnerImpl::Run() Line 1150	C++
 	[Inline Frame] chrome.dll!content::RunContentProcess(content::ContentMainParams params, content::ContentMainRunner * content_main_runner) Line 351	C++
 	chrome.dll!content::ContentMain(content::ContentMainParams params) Line 364	C++
 	chrome.dll!ChromeMain(HINSTANCE__ * instance, wchar_t * cmd, sandbox::SandboxInterfaceInfo * sandbox_info, __int64 exe_entry_point_ticks, __int64 preread_begin_ticks, __int64 preread_end_ticks) Line 243	C++
 	[External Code]	

Testcase Gist URL

No response

Additional Information

It started to crash when Chromium changed behaviour of NOTREACHED. Earlier it was a no-op on release build, now it induces a crash.

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

Metadata

Metadata

Assignees

Type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions