Skip to content

Instantly share code, notes, and snippets.

@sadiqsalau
Last active April 10, 2023 05:47
Show Gist options
  • Save sadiqsalau/65129719838967d49a9f6b82608d5a31 to your computer and use it in GitHub Desktop.
Save sadiqsalau/65129719838967d49a9f6b82608d5a31 to your computer and use it in GitHub Desktop.
Laravel Thunder Client CSRF Filter

[UPDATE] Use this instead: https://gist.github.com/sadiqsalau/32b054dc42b4b0582e296b43efc7c496

You will need to follow these procedures to use the filter.

Consult docs: https://github.com/rangav/thunder-client-support

  1. Create an environment and attach it to your collection.
  2. Add a test to your collection by navigating to the Tests tab. Select Set Env Variable, set query to cookie.xsrf-token and value to {{XSRF-TOKEN}}
  3. Add the file csrf-filter.js to your scripts.
  4. In the Pre-Run tab, select custom filter and choose setCSRFToken

Note: You might need to reopen thunder client tab to select the custom filter.

function setCSRFToken() {
tc.request.headers.push({
name: "X-XSRF-TOKEN",
value: decodeURIComponent(getCSRFToken()),
});
}
function getCSRFToken() {
return tc.getVar("XSRF-TOKEN");
}
module.exports = [setCSRFToken, getCSRFToken];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment