๐งฐ curl for Bug Bounty PoCs: 6 Defaults That Change Your Request
A proof of concept has one job: someone else runs it and sees what you saw. Most reports use a curl command for that, because everyone has curl and a one-liner is easy to paste. The catch is that curl is a helpful clien
A proof of concept has one job: someone else runs it and sees what you saw. Most reports use a curl command for that, because everyone has curl and a one-liner is easy to paste.
The catch is that curl is a helpful client, not a raw socket. It tidies your URL, reformats your body, expands characters you thought were literal and decides which headers survive a redirect. Usually that's what you want. In a PoC it means the request in your report and the request that reached the server can be two different things, and the triager closes the report as "could not reproduce".
This post covers six of those defaults, the flag that turns each one off, and a small local server that shows you what really arrived. Every output below is from curl 8.21.0 talking to that server on my own machine. Only test systems you own or are authorized to test.
See what the server received
Don't trust what you typed. Look at what arrived. This is a small echo server using only the Python standard library. It prints the request line, a few headers and the body exactly as received:
# echo_server.py: prints exactly what arrived. Local use only.
import sys
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
SHOW = ("host", "content-type", "authorization", "cookie", "x-api-key")
class Echo(BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"
def handle_any(self):
length = int(self.headers.get("Content-Length") or 0)
body = self.rfile.read(length)
print(f"[{PORT}] {self.requestline}", flush=True)
for name, value in self.headers.items():
if name.lower() in SHOW:
print(f" {name}: {value}", flush=True)
if body:
print(f" body: {body!r}", flush=True)
if self.path.startswith("/go"): # /go?to=<url> answers 302
target = self.path.split("to=", 1)[1]
self.send_response(302)
self.send_header("Location", target)
self.send_header("Content-Length", "0")
self.end_headers()
return
out = b'{"ok":true}\n'
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(out)))
self.end_headers()
self.wfile.write(out)
do_GET = do_POST = do_PUT = do_DELETE = handle_any
def log_message(self, *args): # silence the default access log
pass
ThreadingHTTPServer(("127.0.0.1", PORT), Echo).serve_forever()
Run python3 echo_server.py 8000 in one terminal and send requests from another. In the outputs below, lines starting with [8000] are what the server printed. I've left out the Host line where it doesn't matter.
1. curl removes ../ before sending
curl "http://127.0.0.1:8000/static/../admin/"
[8000] GET /admin/ HTTP/1.1
The ../ never left your machine. curl's docs say it squashes /../ and /./ sequences according to the standards, the step that RFC 3986 calls removing dot segments. On my build, the encoded form /static/%2e%2e/admin/ arrived as /admin/ too.
For a path traversal or a proxy path-confusion PoC, this is the whole bug. The request you believe you sent was never sent. The flag is --path-as-is:
curl --path-as-is "http://127.0.0.1:8000/static/../admin/"
[8000] GET /static/../admin/ HTTP/1.1
It also works the other way round: if a traversal "doesn't work" in curl but works in your proxy tool, check this before you decide the target is safe.
2. -d rewrites your body
-d was built for HTML forms, and it has three behaviors that surprise people who use it for JSON. Take this file:
{
"role": "admin",
"note": "line one"
}
curl -d @body.json "http://127.0.0.1:8000/profile"
[8000] POST /profile HTTP/1.1
Content-Type: application/x-www-form-urlencoded
body: b'{ "role": "admin", "note": "line one"}'
First, the content type is application/x-www-form-urlencoded. An API that only parses JSON bodies may ignore the body or reject it, and your "it accepted the field" claim stops reproducing. Second, the newlines are gone: the docs say that when -d reads from a file it strips carriage returns, newlines and null bytes. That's harmless for this JSON, and fatal for any payload where a line break is the point.
Third, a leading @ means "read a file". If the value you want to send is the literal text @admin:
curl -d "@admin" "http://127.0.0.1:8000/login"
curl: Failed to open admin
curl: option -d: error encountered when reading a file
Nothing was sent. And if a file with that name happens to exist in the current directory, its contents get sent instead, which is worse.
The fixes:
-
--data-rawsends the value as given, with no special meaning for@. The server receivedbody: b'@admin'. -
--data-binary @filekeeps the file byte for byte. -
--jsonis, per the docs, a shortcut for--data-binaryplusContent-Type: application/jsonandAccept: application/json. It's a newer option, so checkcurl --help allon older systems. curl doesn't check that the data is valid JSON.
curl --json @body.json "http://127.0.0.1:8000/profile"
[8000] POST /profile HTTP/1.1
Content-Type: application/json
body: b'{\n "role": "admin",\n "note": "line one"\n}\n'
3. {} and [] in the URL are globbing
curl can fetch many URLs from one pattern: {a,b} is a list and [1-3] is a range. The docs call this globbing, and it's on by default. API URLs use those same characters:
curl "http://127.0.0.1:8000/items?fields={id,email}"
[8000] GET /items?fields=id HTTP/1.1
[8000] GET /items?fields=email HTTP/1.1
That's two requests, and neither is the one you wrote. Brackets fail in a different way:
curl "http://127.0.0.1:8000/items?filter[id]=1"
curl: (3) bad range in position 36:
http://127.0.0.1:8000/items?filter[id]=1
^
And /items/[1-3] really did send three requests, for /items/1, /items/2 and /items/3. In a report, a pattern like that can quietly touch objects you never meant to touch.
-g (--globoff) switches it off:
curl -g "http://127.0.0.1:8000/items?fields={id,email}&filter[id]=1"
[8000] GET /items?fields={id,email}&filter[id]=1 HTTP/1.1
The docs point out that these characters should be percent-encoded in a URL anyway. If the bug depends on the raw characters, use -g. If it doesn't, encode them and say so in the report.
Related: curl doesn't encode a query string for you. A raw space in the URL was rejected on my build (URL rejected: Malformed input to a URL function). Let curl do the encoding with -G --data-urlencode:
curl -G --data-urlencode "q=a b&c=d" --data-urlencode "n=1" "http://127.0.0.1:8000/search"
[8000] GET /search?q=a+b%26c%3Dd&n=1 HTTP/1.1
4. -X POST plus -L repeats the method on every hop
-X only changes the method word. The docs are direct about it: it doesn't change how curl behaves, and with --location the method you set is used for every request in the chain. My server's /go endpoint answers with a 302. First without -X:
curl -L -d "a=1" "http://127.0.0.1:8000/go?to=/final"
[8000] POST /go?to=/final HTTP/1.1
body: b'a=1'
[8000] GET /final HTTP/1.1
After a 301, 302 or 303, curl follows a POST with a GET, as its docs describe. Now with the habitual -X POST:
curl -L -X POST -d "a=1" "http://127.0.0.1:8000/go?to=/final"
[8000] POST /go?to=/final HTTP/1.1
body: b'a=1'
[8000] POST /final HTTP/1.1
The second hop is now a POST. -L -X DELETE did the same, a DELETE to both URLs. Two problems follow. The PoC shows behavior a real client wouldn't produce, and a state-changing method lands on a URL you didn't choose.
So leave -X out when -d or --json already implies POST. Recent curl versions also have --follow, which keeps a custom method only where the HTTP spec says to. On my build, --follow -X POST -d a=1 sent POST and then GET. For a PoC, the clearest option is often not to follow redirects at all: send each hop as its own command, so the reader sees every step.
5. Redirects decide which secrets travel
I started the same server on a second port to stand in for another origin, then sent three kinds of credentials through a redirect to it:
curl -L -H "Authorization: Bearer test-token-A" -H "Cookie: session=test-A" \
-H "X-Api-Key: test-key-A" \
"http://127.0.0.1:8000/go?to=http://127.0.0.1:8001/landing"
[8000] GET /go?to=http://127.0.0.1:8001/landing HTTP/1.1
Authorization: Bearer test-token-A
Cookie: session=test-A
X-Api-Key: test-key-A
[8001] GET /landing HTTP/1.1
X-Api-Key: test-key-A
curl dropped Authorization and Cookie when the origin changed. The docs say those two aren't passed to other origins unless you use --location-trusted, and that a change of hostname, scheme or port counts as another host. The custom header went along: the docs warn that headers set with -H are sent on every request, including after redirects.
This matters in both directions:
- If the flow you're proving crosses origins, the second hop arrives unauthenticated and the PoC fails for the triager. Send that hop as a separate command.
- If your API key sits in a custom header,
-Lwill hand it to wherever the redirect points. On a target with an open redirect, that's your own test credential going to a third party.
When the redirect stayed on the same origin, both headers arrived on both hops, as you'd expect.
6. A Host header isn't a different host
To aim a request at one specific backend, or to test routing, people write -H "Host: app.example.com" against an IP address. Over plain HTTP that does change the header. Over HTTPS it's only half the story: Everything curl explains that the server name in the TLS handshake (SNI) is taken from the URL, not from your header, so the two disagree and you can end up testing a different virtual host than you think.
--resolve keeps the URL honest and only changes where curl connects:
curl --resolve app.example.com:8000:127.0.0.1 "http://app.example.com:8000/api/me"
[8000] GET /api/me HTTP/1.1
Host: app.example.com:8000
The URL, the Host header and (over HTTPS) the SNI name and certificate check all agree, and the connection goes to the address you named. Keep the header trick for cases where the mismatch itself is what you're testing, and say that in the report.
Turn it into a PoC that reproduces
Detection isn't proof, and a command that only works on your machine isn't proof either. Here's a shape that holds up, with stand-in values:
BASE="https://app.example.com"
OUT='%{response_code} %{size_download} bytes %{url_effective}\n'
# 1. control: account A reads its own invoice (expect 200)
curl -sS -g --path-as-is -o /dev/null -w "control $OUT" \
-H "Authorization: Bearer $TOKEN_A" "$BASE/api/invoices/1001"
# 2. test: account B asks for A's invoice (a fixed app answers 403 or 404)
curl -sS -g --path-as-is -o /dev/null -w "test $OUT" \
-H "Authorization: Bearer $TOKEN_B" "$BASE/api/invoices/1001"
Why it's built this way:
- A control first. It shows the endpoint and your token work, so the second result means something.
-
-g --path-as-isso curl sends the URL as written. -
No
-L. If a redirect is part of the bug, show each hop. -
-winstead of a screenshot.response_code,size_downloadandurl_effectiveare documented write-out variables, and one line per request is easy to compare. Use-iwhen the response headers are the evidence. - Tokens in variables, both accounts yours. The command in the report never contains a live secret, and nobody else's data is involved.
Three more things to do before you paste it:
-
Run it from a clean shell. If it only works with your aliases or your
~/.curlrc, it won't work for the triager.curl -qas the first argument skips the config file. -
Scrub the verbose output.
-vshows the request curl sent (the lines starting with>), which is the best check you have. The docs warn that verbose and trace output can contain credentials, so replace tokens before you share it. The same goes for your browser's "Copy as cURL": read it forCookieandAuthorizationheaders first. -
Include
curl --version. Defaults differ between builds. For example, a build with HTTP/2 support negotiates HTTP/2 forhttps://URLs by default, and mine doesn't have it.%{http_version}in-wshows what was used and--http1.1pins it.
On Windows PowerShell 5.1, curl is an alias for Invoke-WebRequest, which is a different tool with different rules. Type curl.exe.
Try it yourself
Save echo_server.py, start it on ports 8000 and 8001, and run each command above with and without its flag. Ten minutes of watching what arrives will teach you more than the man page.
Then practice on targets built for it (only test what you own or are authorized to test):
-
PortSwigger lab: File path traversal, simple case. Solve it in the browser or a proxy, then reproduce it as a curl command. Whether you need
--path-as-isdepends on where the payload goes: curl's squashing applies to the URL path, so compare with and without. - PortSwigger lab: Insecure direct object references. Write it up as a control plus a test.
- OWASP Juice Shop running locally. Pick any solved challenge and turn it into a script that a teammate can run without asking you a question.
Conclusion
curl changes requests in ways that are documented and easy to miss: it squashes paths, reformats bodies, expands braces and brackets, repeats custom methods across redirects, filters credentials between origins, and takes the TLS name from the URL. Each one has a flag. The habit matters more than the flags: check what the server received, start with a control, and hand over a command that gives the same answer for someone else. Until then, it's a claim.
Further reading
-
curl man page:
--path-as-is,--data,--data-raw,--data-binary,--json,--globoff,--request,--location,--location-trusted,--follow,--header,--resolve,--write-out,--verbose - Everything curl: URL globbing
-
Everything curl: Name resolve tricks (Host header, SNI,
--resolve,--connect-to) - Everything curl: Customize headers
- RFC 3986, section 5.2.4: Remove Dot Segments
- HackerOne docs: Quality Reports (clear steps to reproduce)
- Chrome DevTools: Network features reference (Copy as cURL)
I'm Krishna, a pentester and the founder of Xalgorix, an open-source AI pentester that only reports vulnerabilities it has actually exploited.
๐ If this was useful, follow me for more hands-on web & API security write-ups.
๐ Connect with me on LinkedIn: https://www.linkedin.com/in/xalgord/
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.