Skip to content

Commit

Permalink
include xsrf token in event stream request
Browse files Browse the repository at this point in the history
JupyterHub 4.1 increases strictness of xsrf checks

omitting it is no longer allowed on `Sec-Fetch: cors` requests
  • Loading branch information
minrk committed Mar 28, 2024
1 parent 518c9c8 commit 9b7813c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions nbgitpuller/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def __init__(self, *args, **kwargs):
if 'git_lock' not in self.settings:
self.settings['git_lock'] = locks.Lock()

def get_login_url(self):
# raise on failed auth, not redirect
# can't redirect EventStream to login
raise web.HTTPError(403)

@property
def git_lock(self):
return self.settings['git_lock']
Expand Down
4 changes: 3 additions & 1 deletion nbgitpuller/static/js/gitsync.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
export class GitSync {
constructor(baseUrl, repo, branch, depth, targetpath, path) {
constructor(baseUrl, repo, branch, depth, targetpath, path, xsrf) {
// Class that talks to the API backend & emits events as appropriate
this.baseUrl = baseUrl;
this.repo = repo;
this.branch = branch;
this.depth = depth;
this.targetpath = targetpath;
this.redirectUrl = baseUrl + path;
this._xsrf = xsrf;

this.callbacks = {};
}
Expand All @@ -30,6 +31,7 @@ export class GitSync {
start() {
// Start git pulling handled by SyncHandler, declared in handlers.py
let syncUrlParams = new URLSearchParams({
_xsrf: this._xsrf,
repo: this.repo,
targetpath: this.targetpath
});
Expand Down
3 changes: 2 additions & 1 deletion nbgitpuller/static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const gs = new GitSync(
getBodyData('branch'),
getBodyData('depth'),
getBodyData('targetpath'),
getBodyData('path')
getBodyData('path'),
getBodyData('xsrf'),
);

const gsv = new GitSyncView(
Expand Down
1 change: 1 addition & 0 deletions nbgitpuller/templates/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
data-base-url="{{ base_url | urlencode }}"
data-repo="{{ repo | urlencode }}"
data-path="{{ path | urlencode }}"
data-xsrf="{{ xsrf_token | urlencode }}"
{% if branch %}data-branch="{{ branch | urlencode }}"{% endif %}
{% if depth %}data-depth="{{ depth | urlencode }}"{% endif %}
data-targetpath="{{ targetpath | urlencode }}"
Expand Down

0 comments on commit 9b7813c

Please sign in to comment.