Skip to content

Commit

Permalink
Send the CSRF token in Fiber requests
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Jul 1, 2021
1 parent 7a7fc51 commit 8a560e3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion panel/src/config/fiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { toJson } from "../api/request.js";

const Fiber = {
base: null,
csrf: null,
page: null,
swap: null,

Expand All @@ -40,11 +41,13 @@ const Fiber = {
*
* @param {object} options
*/
init({ page, swap, base }) {
init({ csrf, page, swap, base }) {

// set the base URL for all requests
this.base = base || document.querySelector("base").href;

this.csrf = csrf;

// callback function which handles
// swapping components
this.swap = swap;
Expand Down Expand Up @@ -278,7 +281,10 @@ const Fiber = {
const response = await fetch(url, {
method: options.method,
body: this.body(options.body),
credentials: "same-origin",
cache: "no-store",
headers: {
"X-CSRF": this.csrf,
"X-Fiber": true,
"X-Fiber-Referrer": this.page.$view.path,
...options.headers,
Expand Down Expand Up @@ -479,6 +485,7 @@ export const component = {
created() {
Fiber.init({
page: window.fiber,
csrf: window.fiber.$system.csrf,
swap: async ({ component, page, preserveState }) => {
this.component = component;
this.page = page;
Expand Down

0 comments on commit 8a560e3

Please sign in to comment.