hui.liu 2023-12-28

To ensure that curl works for requests involving CSRF tokens, activating the curl's cookie engine is necessary.

There are two related options to consider:

Users very often want to both read cookies from a file and write updated cookies back to a file, so using both -b, --cookie and -c, --cookie-jar in the same command line is common.

man curl

So, a typical workflow might like this:

Firstly, simulating the user's initial arrival at the page with a GET request. E.g.

curl -v -c cookies.txt -b cookies.txt host.com/page/login.html

Subsequently, simulating filling in the form fields and sending them as a POST request. E.g.

curl -v -c cookies.txt -b cookies.txt -d "username=john&password=123&csrf_token=extract_from_hidden_input" host.com/login

Following this process should result in a successful login. All subsequent requests utilizing cookies.txt should be authenticated properly.