fix(csrf): remove all csrf bypass

This commit is contained in:
Oliver Eyton-Williams
2020-03-17 23:28:23 +05:30
committed by mrugesh
parent f183df0d88
commit 23b899f50f
20 changed files with 84 additions and 56 deletions
+33
View File
@@ -8141,6 +8141,16 @@
"resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-1.0.0.tgz",
"integrity": "sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4="
},
"csrf": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/csrf/-/csrf-3.1.0.tgz",
"integrity": "sha512-uTqEnCvWRk042asU6JtapDTcJeeailFy4ydOQS28bj1hcLnYRiqi8SsD2jS412AY1I/4qdOwWZun774iqywf9w==",
"requires": {
"rndm": "1.2.0",
"tsscmp": "1.0.6",
"uid-safe": "2.1.5"
}
},
"css": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/css/-/css-2.2.4.tgz",
@@ -22220,6 +22230,11 @@
"ret": "~0.1.10"
}
},
"random-bytes": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz",
"integrity": "sha1-T2ih3Arli9P7lYSMMDJNt11kNgs="
},
"randombytes": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",
@@ -23989,6 +24004,11 @@
"inherits": "^2.0.1"
}
},
"rndm": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/rndm/-/rndm-1.2.0.tgz",
"integrity": "sha1-8z/pz7Urv9UgqhgyO8ZdsRCht2w="
},
"rst-selector-parser": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/rst-selector-parser/-/rst-selector-parser-2.2.3.tgz",
@@ -26173,6 +26193,11 @@
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz",
"integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ=="
},
"tsscmp": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/tsscmp/-/tsscmp-1.0.6.tgz",
"integrity": "sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA=="
},
"tsutils": {
"version": "3.17.1",
"resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.17.1.tgz",
@@ -26286,6 +26311,14 @@
"resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.17.tgz",
"integrity": "sha512-uRdSdu1oA1rncCQL7sCj8vSyZkgtL7faaw9Tc9rZ3mGgraQ7+Pdx7w5mnOSF3gw9ZNG6oc+KXfkon3bKuROm0g=="
},
"uid-safe": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz",
"integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==",
"requires": {
"random-bytes": "~1.0.0"
}
},
"unc-path-regex": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/unc-path-regex/-/unc-path-regex-0.1.2.tgz",
+1
View File
@@ -22,6 +22,7 @@
"bezier-easing": "^2.1.0",
"browser-cookies": "^1.2.0",
"chai": "^4.2.0",
"csrf": "^3.1.0",
"date-fns": "^1.30.1",
"entities": "^1.1.2",
"enzyme": "^3.10.0",
@@ -31,7 +31,7 @@ function ShowUnsubscribed({ unsubscribeId }) {
block={true}
bsSize='lg'
bsStyle='primary'
href={`${apiLocation}/internal/resubscribe/${unsubscribeId}`}
href={`${apiLocation}/resubscribe/${unsubscribeId}`}
>
You can click here to resubscribe
</Button>
+1
View File
@@ -115,6 +115,7 @@ export const preventProgressDonationRequests = createAction(
export const onlineStatusChange = createAction(types.onlineStatusChange);
// TODO: re-evaluate this since /internal is no longer used.
// `hardGoTo` is used to hit the API server directly
// without going through /internal
// used for things like /signin and /signout
+9 -5
View File
@@ -1,14 +1,18 @@
import { apiLocation } from '../../config/env.json';
import { _csrf } from '../redux/cookieValues';
import axios from 'axios';
import Tokens from 'csrf';
const base = apiLocation + '/internal';
const baseUnauthenticated = apiLocation + '/unauthenticated';
const base = apiLocation;
const tokens = new Tokens();
axios.defaults.withCredentials = true;
export function postUnauthenticated(path, body) {
return axios.post(`${baseUnauthenticated}${path}`, body);
// _csrf is passed to the client as a cookie. Tokens are sent back to the server
// via headers:
if (_csrf) {
axios.defaults.headers.post['CSRF-Token'] = tokens.create(_csrf);
axios.defaults.headers.put['CSRF-Token'] = tokens.create(_csrf);
}
function get(path) {