From d9c53256cb477799220023304ae5dbaa20997049 Mon Sep 17 00:00:00 2001 From: Martin Tschammer Date: Fri, 9 Sep 2016 12:52:36 +0200 Subject: [PATCH 1/2] Moving the retrieval of the csrf cookie so that it happens per request. This enables logging in on another tab. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 321af31..cbc2e68 100644 --- a/index.js +++ b/index.js @@ -4,9 +4,9 @@ var request = require('superagent'); // patch superagent to attach CSRF-token to all requests try { - var csrf = document.cookie.match(/csrftoken=(.*?)(?:$|;)/)[1]; var end = request.Request.prototype.end; request.Request.prototype.end = function(fn) { + var csrf = document.cookie.match(/csrftoken=(.*?)(?:$|;)/)[1]; this.set('X-CSRFToken', csrf); return end.call(this, fn); }; From 78e8958724d14e8fcfa1f6ba9233f0b34ca890b8 Mon Sep 17 00:00:00 2001 From: Martin Tschammer Date: Fri, 9 Sep 2016 13:01:30 +0200 Subject: [PATCH 2/2] Version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 952f73c..5e42c60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "superagent-django-csrf", - "version": "0.1.3", + "version": "0.1.4", "description": "Patch to add `csrftoken` from cookies as `X-CSRFToken` header to every superagent's request", "main": "index.js", "scripts": {