Skip to content

Commit d24f9f6

Browse files
authored
Merge pull request #449 from kevin-bates/escape-user-input
Escape user input in handlers flagged during code scans
2 parents d690965 + 151931b commit d24f9f6

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

examples/simple/simple_ext1/handlers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from jupyter_server.base.handlers import JupyterHandler
22
from jupyter_server.extension.handler import ExtensionHandlerMixin, ExtensionHandlerJinjaMixin
3+
from jupyter_server.utils import url_escape
34

45
class DefaultHandler(ExtensionHandlerMixin, JupyterHandler):
56
def get(self):
@@ -19,8 +20,8 @@ def get(self, matched_part=None, *args, **kwargs):
1920
var1 = self.get_argument('var1', default=None)
2021
components = [x for x in self.request.path.split("/") if x]
2122
self.write('<h1>Hello Simple App 1 from Handler.</h1>')
22-
self.write('<p>matched_part: {}</p>'.format(matched_part))
23-
self.write('<p>var1: {}</p>'.format(var1))
23+
self.write('<p>matched_part: {}</p>'.format(url_escape(matched_part)))
24+
self.write('<p>var1: {}</p>'.format(url_escape(var1)))
2425
self.write('<p>components: {}</p>'.format(components))
2526

2627
class BaseTemplateHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler): pass

examples/simple/simple_ext2/handlers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from jupyter_server.base.handlers import JupyterHandler
22
from jupyter_server.extension.handler import ExtensionHandlerMixin, ExtensionHandlerJinjaMixin
3+
from jupyter_server.utils import url_escape
34

45
class ParameterHandler(ExtensionHandlerMixin, JupyterHandler):
56
def get(self, matched_part=None, *args, **kwargs):
67
var1 = self.get_argument('var1', default=None)
78
components = [x for x in self.request.path.split("/") if x]
89
self.write('<h1>Hello Simple App 2 from Handler.</h1>')
9-
self.write('<p>matched_part: {}</p>'.format(matched_part))
10-
self.write('<p>var1: {}</p>'.format(var1))
10+
self.write('<p>matched_part: {}</p>'.format(url_escape(matched_part)))
11+
self.write('<p>var1: {}</p>'.format(url_escape(var1)))
1112
self.write('<p>components: {}</p>'.format(components))
1213

1314
class BaseTemplateHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler): pass

jupyter_server/services/contents/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def get(self, path):
282282
self.redirect(url_path_join(
283283
self.base_url,
284284
'api/contents',
285-
path
285+
url_escape(path)
286286
))
287287

288288
put = patch = post = delete = get

0 commit comments

Comments
 (0)