From 9364ef585fd0899f9a81c727bece052420f57916 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 27 Jun 2022 12:41:39 +0300 Subject: [PATCH] fix nextcloud WebDAV csrf error (#1448) --- background/sync-manager.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/background/sync-manager.js b/background/sync-manager.js index cf565baa..30f882bf 100644 --- a/background/sync-manager.js +++ b/background/sync-manager.js @@ -274,11 +274,21 @@ const syncMan = (() => { if (name === 'dropbox' || name === 'google' || name === 'onedrive' || name === 'webdav') { const options = await syncMan.getDriveOptions(name); options.getAccessToken = () => tokenMan.getToken(name); + options.fetch = name === 'webdav' ? fetchWebDAV.bind(options) : fetch; return dbToCloud.drive[name](options); } throw new Error(`unknown cloud name: ${name}`); } + /** @this {Object} DriveOptions */ + function fetchWebDAV(url, init = {}) { + init.credentials = 'omit'; // circumventing nextcloud CSRF token error + init.headers = Object.assign({}, init.headers, { + Authorization: `Basic ${btoa(`${this.username || ''}:${this.password || ''}`)}`, + }); + return fetch(url, init); + } + function schedule(delay = SYNC_DELAY) { chrome.alarms.create('syncNow', { delayInMinutes: delay, // fractional values are supported