Skip to content
Business logic Disclosed report Intermediate

A logic error in detect_proxy caused truncation of environment variable names for long protocol schemes.

The detect_proxy function in curl uses a fixed-size buffer to build proxy environment variable names, so a protocol scheme longer than 12 characters is silently truncated. An attacker who can set environment variables could define a truncated variable name and redirect traffic through an unintended proxy.

herdiyanitdev Follow

Originally disclosed on HackerOne

  • Disclosed after 39 hours

In lib/url.c, the detect_proxy function uses a fixed-size buffer, proxy_env[20], to construct proxy environment variable names (e.g., http_proxy). However, the curl URL parser (lib/urlapi.c) allows protocol schemes up to 40 characters (MAX_SCHEME_LEN). When a protocol scheme longer than 12 characters is used, the environment variable name is silently truncated to 19 characters by curl_msnprintf. This causes a business logic error where curl may read configuration from an unintended (truncated) environment variable, causing potentially unexpected proxy behavior in applications using custom schemes.

Google Gemini AI was used as an analysis aid only; all findings, including the truncation behavior, were manually verified by reviewing the source code and testing a PoC.

Affected Versions

  • curl 8.18.0-DEV (latest master branch)
  • Platform: Windows 10 x64 (platform-independent logic issue)

Steps to Reproduce

  1. Inspect lib/url.c lines 2060–2067.
  2. Note that proxy_env is declared as char proxy_env[20];.
  3. Observe that conn->handler->scheme can be up to 40 characters (MAX_SCHEME_LEN).
  4. Call curl_msnprintf(proxy_env, sizeof(proxy_env), "%s_proxy", conn->handler->scheme); with a long scheme.
  5. Example: "extremelylongprotocolname" (25 characters) will be truncated to "extremelylongsc" instead of "extremelylongprotocolname_proxy".

Supporting/Reference Materials

  • Source code snippet from lib/url.c (lines 2060–2067)
  • PoC code (poc_truncation.c) demonstrating truncation
  • Screenshot of PoC execution showing truncation
  • Screenshot of the vulnerable code in lib/url.c

Impact

A business logic flaw allows proxy configuration manipulation or bypass through truncating environment variable names. This can lead to unexpected network behavior or bypass security policies that rely on protocol-specific proxy settings. An attacker with control over environment variables could set truncated variable names to redirect traffic through an unauthorized proxy.

Attachments

poc_proxy_env_truncation_output.png
poc_proxy_env_truncation_output.png From the original on HackerOne
poc_proxy_env_truncation.c.jpeg
poc_proxy_env_truncation.c.jpeg
proxy_env_truncation.png.jpeg
proxy_env_truncation.png.jpeg

The original report as published on HackerOne, by herdiyanitdev. 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 a fixed-size buffer of 20 bytes is used to hold a proxy environment variable name built from a protocol scheme that can be up to 40 characters, so the name is truncated.

Impact

An attacker with control over environment variables could set a truncated variable name to redirect traffic through an unauthorised proxy, potentially bypassing security policies.

What the attacker needed

Attacker controls environment variables; application uses a custom scheme longer than 12 characters

How it was found

  1. Inspect the detect_proxy function in lib/url.c.
  2. Note the fixed-size proxy_env buffer.
  3. Observe that the protocol scheme can be up to 40 characters.
  4. Build the environment variable name with a long scheme and see it truncated.

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.

curl is a tool that fetches data from the internet. It can read proxy settings from environment variables, which are named settings stored by the operating system. The code that builds those names uses a buffer that is too small for long protocol names, so the name gets cut short and curl may read a different setting than intended.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by herdiyanitdev

View all

1 more disclosed report, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.