jupyter serverextenstion unescaped endpoint

22 views
Skip to first unread message

Benjamin Bertrand

unread,
Dec 6, 2018, 4:52:24 PM12/6/18
to Project Jupyter
Hi,

I'm trying to create a JupyterLab extension to access GitLab based on https://github.com/jupyterlab/jupyterlab-github
I'm having issues with the serverextension that acts as a proxy.

In GitLab, the namespaced path shall be URL-encoded: user/repository shall be encoded as user%2Frepository
GET /api/v4/projects/diaspora%2Fdiaspora

When I call proxiedApiRequest<any>(requestUrl, this._serverSettings) with requestUrl set to http://localhost:8888/gitlab/projects/gitlab-org%2Fci-training-sample/repository/tree? in javascript, on Python side, my handler gets the path /projects/gitlab-org/ci-training-sample/repository/tree which of course results in a 404.
I'd expect to get /projects/gitlab-org%2Fci-training-sample/repository/tree instead.

get: /projects/gitlab-org/ci-training-sample/repository/tree
[W 22:23:42.676 LabApp] 404 GET /gitlab/projects/gitlab-org%2Fci-training-sample/repository/tree?&1544131422149 (::1) 524.77ms referer=http://localhost:8888/lab


Is tornado automatically unescaping the endpoint? Is there a way around that?


The Python code is almost the same as for the jupyterlab_github extension. Any endpoint shall be passed to the handler:

class GitLabHandler(APIHandler):

   
@gen.coroutine
   
def get(self, path):
       
"""
        Proxy API requests to GitLab, adding authentication parameter(s) if
        they have been set.
        """

       
print(f"get: {path}")
       
...


def load_jupyter_server_extension(nb_server_app):
    web_app
= nb_server_app.web_app
    base_url
= web_app.settings["base_url"]
    endpoint
= url_path_join(base_url, "gitlab")
    handlers
= [(endpoint + "(.*)", GitLabHandler)]
    web_app
.add_handlers(".*$", handlers)


Benjamin Bertrand

unread,
Dec 9, 2018, 10:46:01 AM12/9/18
to Project Jupyter
tornado does unescape the path pattern in PathMatches: https://www.tornadoweb.org/en/stable/_modules/tornado/routing.html#PathMatches

I ended encoding in base64 the path on the client side and decoding it in the server extension using urlsafe_b64decode
Reply all
Reply to author
Forward
0 new messages