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.
More on Credentials & security
What credential types does Jenkins support out of the box?BeginnerWhat is the difference between Global and System credential scope?IntermediateHow do folder-scoped credentials help multi-team controllers?IntermediateHow does Jenkins mask secrets in logs and what are its limits?AdvancedWhat authorization strategies are available?IntermediateWhat are the key permissions to understand in matrix auth?Intermediate