Skip to content
Memory corruption Disclosed report Advanced

Buffer Overflow Vulnerability in WebSocket Handling

The WebSocket handling code in curl uses strcpy without bounds checking when copying a base64-encoded nonce, which can overflow a buffer. An attacker could send a crafted WebSocket request with an oversized nonce to overwrite adjacent memory and potentially execute arbitrary code.

hackers_ Follow

Originally disclosed on HackerOne

High 8.6 View original
  • Disclosed after 5 days

Summary:

Hello security team, Hope you are doing well :)

I would like to report a potential security vulnerability in the WebSocket handling code of the curl library. The issue is related to the usage of the strcpy function, which can lead to a buffer overflow if the length of the input is not properly checked. The vulnerable code snippet is located at this link.

Steps To Reproduce:

  1. Trigger the WebSocket functionality with a crafted request.
  2. Provide a base64-encoded nonce value that exceeds the buffer size.
  3. Observe that the strcpy function is used without proper bounds checking.

Fix:

To address this issue, it is recommended to replace the strcpy function with the safer alternative strncpy and explicitly specify the maximum length to copy. Here's an example fix:

C
strncpy(keyval, randstr, sizeof(keyval) - 1);
keyval[sizeof(keyval) - 1] = '\0';  // Null-terminate the string

This modification ensures that only a specified number of characters (up to the buffer size minus 1) are copied, preventing buffer overflow.

Reference:

https://cwe.mitre.org/data/definitions/122.html

Impact

This vulnerability may allow an attacker to execute arbitrary code, potentially leading to a compromise of the application or system. An attacker could exploit this weakness by providing a specially crafted WebSocket request, causing a buffer overflow and overwriting adjacent memory.

The original report as published on HackerOne, by hackers_. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the code uses strcpy to copy a base64-encoded nonce into a fixed-size buffer without verifying that the input fits, leading to a buffer overflow.

Impact

This vulnerability may allow an attacker to execute arbitrary code, potentially leading to a compromise of the application or system.

What the attacker needed

Ability to send a crafted WebSocket request

The fix

The strcpy call should be replaced with a bounded copy such as strncpy that explicitly limits the number of characters and null-terminates the result.

How it was found

  1. Trigger the WebSocket functionality with a crafted request.
  2. Provide a base64-encoded nonce value that exceeds the buffer size.
  3. Observe that the strcpy function is used without proper bounds checking.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A buffer overflow happens when a program copies more data into a fixed-size memory area than it can hold, so the extra data spills over and corrupts nearby memory. Here, the curl library copies a user-supplied value into a small buffer without checking its length, so a malicious WebSocket request could overwrite other data and possibly let an attacker run their own code.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.