Skip to content
Misconfiguration Disclosed report Intermediate

urlapi: off-by-one in custom scheme validation skips last character

The custom scheme validation in libcurl's URL API had an off-by-one error, so the final character of a scheme name was never checked. An attacker could get schemes ending in arbitrary bytes accepted when setting the scheme through the API with the non-supported-scheme flag.

otiscui Follow

Originally disclosed on HackerOne

  • Disclosed after 25 hours

Summary

In lib/urlapi.c, the set_url_scheme() function has an off-by-one error when validating custom scheme names. The validation loop checks scheme[0] twice (once by ISALPHA, once in the loop) and never checks the last character. This allows schemes ending with any arbitrary byte (e.g., foo!, bar{, bad/) to pass validation when set via curl_url_set(url, CURLUPART_SCHEME, ..., CURLU_NON_SUPPORT_SCHEME), violating RFC 3986 Section 3.1.

Affected version

curl 8.19.1-DEV (Darwin) libcurl/8.19.1-DEV OpenSSL/3.6.1 zlib/1.2.12 brotli/1.2.0 zstd/1.5.7 libidn2/2.3.8 Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt mqtts pop3 pop3s rtsp smb smbs smtp smtps telnet tftp ws wss Features: alt-svc AsynchDNS brotli HSTS HTTPS-proxy IDN IPv6 Largefile libz NTLM SSL threadsafe TLS-SRP UnixSockets zstd

Tested on macOS (Darwin 25.2.0, arm64). The bug is platform-independent, in lib/urlapi.c lines 1648-1657.

Steps To Reproduce

Build and run this PoC:

C
#include <stdio.h>
#include <curl/curl.h>

int main(void) {
  CURLU *url;
  CURLUcode rc;
  const char *schemes[] = {"bad!", "bad{", "bad/", "bad\\", "a!", NULL};

  for(int i = 0; schemes[i]; i++) {
    url = curl_url();
    rc = curl_url_set(url, CURLUPART_SCHEME, schemes[i],
                      CURLU_NON_SUPPORT_SCHEME);
    char *out = NULL;
    if(rc == CURLUE_OK)
      curl_url_get(url, CURLUPART_SCHEME, &out, 0);
    printf("%-10s  %s", schemes[i],
           rc == CURLUE_OK ? "ACCEPTED (BUG!)" : "REJECTED (correct)");
    if(out) { printf("  stored='%s'", out); curl_free(out); }
    printf("\n");
    curl_url_cleanup(url);
  }
  return 0;
}

Output:

bad! ACCEPTED (BUG!) stored='bad!' bad{ ACCEPTED (BUG!) stored='bad{' bad/ ACCEPTED (BUG!) stored='bad/' bad\ ACCEPTED (BUG!) stored='bad' a! ACCEPTED (BUG!) stored='a!' All should be REJECTED per RFC 3986 Section 3.1.

Root cause in set_url_scheme() (urlapi.c:1648-1657): after the ISALPHA(*s) check, s is not incremented before entering the while(--plen) loop, so the first character is validated twice and the last character is never validated.

Suggested fix: add s++ after the ISALPHA(*s) check, before the loop.

Impact

Summary

  • Input validation bypass: Applications using CURLU_NON_SUPPORT_SCHEME that rely on libcurl's URL API for scheme validation will accept malformed schemes containing illegal characters in the final position.
  • Potential SSRF filter bypass: Security filters that use libcurl's URL parser to validate/normalize URLs before making requests may accept URLs with invalid scheme characters, which downstream components may interpret differently.
  • RFC non-compliance: Violates RFC 3986 Section 3.1 scheme syntax: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )

Note: The bug is only triggerable via the direct CURLUPART_SCHEME API, not when parsing a full URL via CURLUPART_URL (because the URL parser's scheme extraction filters special characters before reaching set_url_scheme()).

The original report as published on HackerOne, by otiscui. 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 an off-by-one in the validation loop: the pointer was not advanced past the first character before the loop, so the first character was checked twice and the last was never checked.

Impact

Applications relying on libcurl's URL API for scheme validation could accept malformed schemes, which may let security filters such as SSRF checks be bypassed if downstream components interpret the URL differently; the bug is only reachable through the direct scheme-setting API, not when parsing a full URL.

What the attacker needed

Code using the URL API; non-supported-scheme flag set

The fix

The text suggests incrementing the pointer after the first-character check, before the loop, so every character including the last is validated.

How it was found

  1. Build and run a small program that sets several custom schemes ending in illegal characters via the URL API with the non-supported-scheme flag.
  2. Observe that each malformed scheme is accepted and stored instead of being rejected.

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 URL scheme is the first part of a web address, like 'http' or 'ftp', and it may only contain letters, digits and a few symbols. libcurl checks each character of a scheme you supply, but a counting mistake meant it checked the first character twice and skipped the last one. So a scheme ending in a forbidden symbol was wrongly accepted.

What is Misconfiguration?

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.