Interview Prep/Jenkins/Credentials & security

What is the CSRF crumb and when do you need it?

IntermediateConceptCredentials & security
Answer

Jenkins protects state-changing POST requests with a crumb tied to the user session. Browsers handle it automatically. Scripts using username + API token do not need a crumb (since 2.176.2). Scripts using username + password and a session must first fetch a crumb:

CRUMB=$(curl -s -c jar -u alice:pass 'https://jenkins/crumbIssuer/api/json' | jq -r '.crumbRequestField + ":" + .crumb')
curl -s -b jar -u alice:pass -H "$CRUMB" -X POST https://jenkins/job/app/build

The error without it is HTTP ERROR 403 No valid crumb was included in the request. Never disable CSRF protection.

All Jenkins questions Roadmap: Jenkins

More on Credentials & security