mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-17 20:16:32 +01:00
Frontend: CSRF support
This commit is contained in:
parent
ee69429898
commit
2436ff143f
5 changed files with 63 additions and 1 deletions
30
src-ui/src/app/interceptors/csrf.interceptor.ts
Normal file
30
src-ui/src/app/interceptors/csrf.interceptor.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
HttpRequest,
|
||||
HttpHandler,
|
||||
HttpEvent,
|
||||
HttpInterceptor
|
||||
} from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
|
||||
@Injectable()
|
||||
export class CsrfInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(private cookieService: CookieService) {
|
||||
|
||||
}
|
||||
|
||||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
let csrfToken = this.cookieService.get('csrftoken')
|
||||
if (csrfToken) {
|
||||
request = request.clone({
|
||||
setHeaders: {
|
||||
'X-CSRFToken': csrfToken
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return next.handle(request);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue