Skip to content

Commit 3ec281c

Browse files
committed
Add X-CSRFToken header to every POST request
1 parent 0cb7e78 commit 3ec281c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/api_client.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ export const HTTP = axios.create({
77
baseURL: PageConfig.getBaseUrl()
88
});
99

10+
HTTP.defaults.headers.post['X-CSRFToken'] = _get_cookie("_xsrf")
11+
12+
function _get_cookie(name: string) {
13+
// Source: https://blog.jupyter.org/security-release-jupyter-notebook-4-3-1-808e1f3bb5e2
14+
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
15+
return r ? r[1] : undefined;
16+
}
17+
1018

1119
export function get_server_config() {
1220
return HTTP.get("gitplus/expanded_server_root")
@@ -18,7 +26,6 @@ export function get_server_config() {
1826
});
1927
}
2028

21-
2229
export function get_modified_repositories(data: {}, show_repository_selection_dialog: Function, command: string, show_repository_selection_failure_dialog: Function) {
2330
let repo_names: string[][] = []
2431
return HTTP.post("gitplus/modified_repo", data)

0 commit comments

Comments
 (0)