···99 --max-redirs 20 \
1010 --retry 3 \
1111 --cacert $cacert/etc/ssl/certs/ca-bundle.crt \
1212+ -b cookies \
1313+ -c cookies \
1214 $curlOpts \
1315 $NIX_CURL_FLAGS"
14161517# We don't want the password to be on any program's argv, as it may be
1618# visible in /proc. Writing it to file with echo should be safe, since
1719# it's a shell builtin.
1818-echo "password=$password" > password
2020+echo -n "$password" > password
1921# Might as well hide the username as well.
2020-echo "username-or-email=$username" > username
2222+echo -n "$username" > username
2323+2424+# Get a CSRF token.
2525+csrf=$($curl $loginUrl | xidel - -e '//input[@id="csrf_token"]/@value')
21262227# Log in. We don't especially care about the result, but let's check if login failed.
2323-$curl -c cookies -d @username -d @password $loginUrl -D headers > /dev/null
2828+$curl --data-urlencode csrf_token="$csrf" \
2929+ --data-urlencode username_or_email@username \
3030+ --data-urlencode password@password \
3131+ -d action=Login \
3232+ $loginUrl -D headers > /dev/null
24332525-if grep -q 'Location: /' headers; then
3434+if grep -q 'Location: https://' headers; then
2635 # Now download. We need --insecure for this, but the sha256 should cover us.
2727- $curl -b cookies --insecure --location $url > $out
3636+ $curl --insecure --location $url > $out
3737+ set +x
2838else
3939+ set +x
2940 echo 'Login failed'
3041 echo 'Please set username and password with config.nix,'
3142 echo 'or /etc/nix/nixpkgs-config.nix if on NixOS.'