Created
May 24, 2018 14:33
-
-
Save ohnotnow/f4f54fd5d0a68aaf4ee291a13c7ab2ae to your computer and use it in GitHub Desktop.
csrf hackyness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("DOMContentLoaded", function () { | |
setInterval(keepTokenAlive, 1000 * 60 * 15); // every 15 mins | |
function keepTokenAlive() { | |
axios.get('/keep-token-alive') | |
.then(response => { | |
let token = response.data.token; | |
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = response.data.token; | |
const formFields = document.querySelectorAll('input[name="_token"]'); | |
Array.from(formFields).forEach(field => { | |
field.value = token; | |
}); | |
}) | |
.catch(error => { | |
console.log(error); | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Auth::routes(); | |
Route::get('/keep-token-alive', function () { | |
return ['token' => csrf_token()]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment