{"data":{"id":148,"slug":"working-with-csrf-tokens-part-8-148","title":"Working with CSRF tokens, part 8","excerpt":"This is part 8 of our series, and this time we focus on edge cases readers asked about. Cross-site request forgery tokens are one of the first things that trip up a script trying to log in to a site:…","seriesName":"Working with CSRF tokens","seriesPart":8,"sections":[{"heading":"Introduction","paragraphs":["This is part 8 of our series, and this time we focus on edge cases readers asked about. 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":"Putting it into practice","paragraphs":["Validate the data you extract. Prices without currencies, dates without time zones and empty fields are common sources of silent errors downstream.","Before writing a single line of code, look at how the page actually loads its data. Open the network panel, reload, and note which requests return the content you care about. Very often the data you want arrives as JSON from an endpoint you can call directly."]},{"heading":"Step by step","paragraphs":["Time zones matter more than they seem. Store timestamps in UTC and convert only when displaying them.","Character encodings still cause trouble. Decode responses using the charset the server declares, and normalise text before comparing or storing it."]},{"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":3,"authorName":"Priya Nakamura","authorSlug":"priya-nakamura","category":"Testing","tags":["ethics","javascript","python"],"publishedAt":"2025-01-03T00:00:00.000Z","wordCount":188,"readingTimeMinutes":2}}