Skip to content
Smuggling / CRLF Disclosed report Intermediate

CRLF Injection in Gopher Protocol (`lib/gopher.c`)

curl's Gopher URL handler decoded percent-encoded carriage-return and line-feed sequences in the path because it used the REJECT_ZERO flag instead of REJECT_CTRL. An attacker who controls a Gopher URL could inject extra lines into the protocol stream sent to the target server, potentially reaching internal services such as Redis or Memcached.

gaurav0212 Follow

Originally disclosed on HackerOne

  • Disclosed after 5 hours

Control characters slip through during URL handling in curl’s Gopher setup. Though null bytes get blocked by the REJECT_ZERO setting, returns and line feeds remain permitted. A specially built address using percent-encoded breaks - like %0D%0A - opens room for command insertion. Because of how decoding works here, unintended instructions may pass into the data flow. Unexpected behavior follows when those sequences reach downstream systems.

Root Cause: lib/gopher.c handles data, decoding occurs within the path segment through a specific function call

C
result = Curl_urldecode(newp, 0, &buf_alloc, &buf_len, REJECT_ZERO);

Because REJECT_CTRL is absent, encoded CRLF sequences become actual line breaks when the request reaches the server.

Steps to Reproduce:

  • Create the listener script: (Use the Python script below to capture raw bytes and detect injection).
Bash
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('127.0.0.1', 7070))
s.listen(1)
print("Server listening on 7070...")
while True:
    conn, addr = s.accept()
    data = conn.recv(4096)
    print(f"Received: {repr(data)}")
    if b'\r\n' in data: print("🚨 CRLF INJECTION DETECTED!")
    conn.close()
  • Execute the Payload: Run curl with an encoded CRLF sequence in the Gopher path:
Bash
curl "gopher://127.0.0.1:7070/x%0D%0AINJECTED_COMMAND"
  • Verify the Injection: Check your listener output. You will see that the INJECTED_COMMAND appears on a new line, confirming that the protocol stream was broken:
Text
[+] Client connected from ('127.0.0.1', 53518)
[RECEIVED] b'yz\r\nINJECTED\r\n'
[HEX] 797a0d0a494e4a45435445440d0a

🚨 CRLF INJECTION DETECTED!

Impact

Security limits may be crossed in this scenario. When an attacker influences the URL or triggers a redirection, interaction with internal systems becomes possible - systems such as Redis, Memcached, or mail components. Execution of unintended instructions follows under these conditions.

Fix: In lib/gopher.c, swap REJECT_ZERO with REJECT_CTRL. This change ensures full suppression of control characters. Implementation now prevents unintended character handling by using the updated flag. Outcome aligns with expected filtering behavior. Final effect appears consistent across test cases.

Disclosure: To test the idea, a basic TCP server was built using a code-generation assistant, focused strictly on recording byte streams from Gopher links. Rather than automating analysis, each stage - examining flaws, tracing origins, judging consequences, replicating issues - was completed by hand. Simplicity guided the design of the server; its purpose limited to exposing how data moves at the protocol layer.

Attachments

01.png
01.png From the original on HackerOne
02.png
02.png
03.png
03.png

The original report as published on HackerOne, by gaurav0212. 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

The Gopher handler called Curl_urldecode with REJECT_ZERO, which blocks null bytes but allows CR and LF, so percent-encoded line breaks survived decoding.

Impact

An attacker who controls a Gopher URL or triggers a redirect could inject commands into protocols used by internal services such as Redis, Memcached or mail components, though the report only demonstrates this against a local test listener.

What the attacker needed

Attacker controls a gopher:// URL; victim runs curl on that URL; target service accepts line-based commands

The fix

The Gopher handler should pass REJECT_CTRL to Curl_urldecode instead of REJECT_ZERO so that all control characters are rejected.

How it was found

  1. Start a local TCP listener that prints received bytes and flags CRLF.
  2. Run curl against a gopher URL whose path contains a percent-encoded CRLF followed by text.
  3. Observe the listener output showing the injected text on a new line.

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.

When curl fetches a gopher:// address, it turns percent-encoded characters like %0D%0A back into real carriage-return and line-feed characters. Those two characters mark the end of a line in many text-based protocols, so an attacker can slip extra commands onto new lines. The fix is to reject all control characters, not just null bytes.

What is Smuggling / CRLF?

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.

More by gaurav0212

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.

Request smuggling and header injection

The lesson behind this report.

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.