Add consistent CSRF token verification to API endpoints; address security concern with non-CSRF protected endpoints
This commit is contained in:
parent
cc31a0a6d0
commit
bf9cbe2c6d
7 changed files with 59 additions and 14 deletions
|
@ -7,10 +7,21 @@ const http: AxiosInstance = axios.create({
|
|||
'X-Requested-With': 'XMLHttpRequest',
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': (window as any).X_CSRF_TOKEN as string || '',
|
||||
},
|
||||
});
|
||||
|
||||
http.interceptors.request.use(req => {
|
||||
const cookies = document.cookie.split(';').reduce((obj, val) => {
|
||||
const [ key, value ] = val.trim().split('=').map(decodeURIComponent);
|
||||
|
||||
return { ...obj, [key]: value };
|
||||
}, {} as Record<string, string>);
|
||||
|
||||
req.headers['X-XSRF-TOKEN'] = cookies['XSRF-TOKEN'] || 'nil';
|
||||
|
||||
return req;
|
||||
});
|
||||
|
||||
http.interceptors.request.use(req => {
|
||||
if (!req.url?.endsWith('/resources') && (req.url?.indexOf('_debugbar') || -1) < 0) {
|
||||
store.getActions().progress.startContinuous();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue