Added CSRF protection to all ajax requests

This commit is contained in:
Vivek Santayana 2021-11-29 09:13:21 +00:00
parent 6285014938
commit 9e9ceab81f
2 changed files with 22 additions and 0 deletions

View File

@ -53,6 +53,17 @@
crossorigin="anonymous" crossorigin="anonymous"
></script> ></script>
<!-- Custom js --> <!-- Custom js -->
<script type="text/javascript">
var csrf_token = "{{ csrf_token() }}";
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrf_token);
}
}
});
</script>
<script <script
type="text/javascript" type="text/javascript"
src="{{ url_for('.static', filename='js/script.js') }}" src="{{ url_for('.static', filename='js/script.js') }}"

View File

@ -51,6 +51,17 @@
crossorigin="anonymous" crossorigin="anonymous"
></script> ></script>
<!-- Custom js --> <!-- Custom js -->
<script type="text/javascript">
var csrf_token = "{{ csrf_token() }}";
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrf_token);
}
}
});
</script>
<script <script
type="text/javascript" type="text/javascript"
src="{{ url_for('.static', filename='js/script.js') }}" src="{{ url_for('.static', filename='js/script.js') }}"