{"data":{"id":128,"slug":"working-with-csrf-tokens-part-7-128","title":"Working with CSRF tokens, part 7","excerpt":"For part 7, we revisit the basics with a fresh example and a few lessons learned the hard way. Cross-site request forgery tokens are one of the first things that trip up a script trying to log in to…","seriesName":"Working with CSRF tokens","seriesPart":7,"sections":[{"heading":"Introduction","paragraphs":["For part 7, we revisit the basics with a fresh example and a few lessons learned the hard way. Cross-site request forgery tokens are one of the first things that trip up a script trying to log in to a site: the form posts fine in a browser but fails with a 403 from code."]},{"heading":"Common pitfalls","paragraphs":["Selectors are the most fragile part of any scraper. Prefer stable attributes such as data-testid or semantic structure over generated class names, which can change on every deploy.","Keep configuration such as base URLs, delays and selectors out of your code. Changing a delay should not require a redeploy."]},{"heading":"What to watch for","paragraphs":["Store raw responses alongside parsed output while you are developing. When a parser breaks, you can replay the saved HTML instead of hitting the site again.","Treat HTTP 429 responses as a signal, not an obstacle. Read the Retry-After header, back off, and resume at a slower pace."]},{"heading":"Key takeaway","paragraphs":["Load the form page with a session that keeps cookies, read the hidden token field, and send it back with the same session in the same request."]}],"authorId":2,"authorName":"Noah Bennett","authorSlug":"noah-bennett","category":"Testing","tags":["ethics"],"publishedAt":"2026-04-29T00:00:00.000Z","wordCount":179,"readingTimeMinutes":2}}