Skip to content

Commit

Permalink
Merge pull request #449 from kevin-bates/escape-user-input
Browse files Browse the repository at this point in the history
Escape user input in handlers flagged during code scans
  • Loading branch information
blink1073 committed Mar 18, 2021
2 parents d690965 + 151931b commit d24f9f6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions examples/simple/simple_ext1/handlers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.extension.handler import ExtensionHandlerMixin, ExtensionHandlerJinjaMixin
from jupyter_server.utils import url_escape

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

class BaseTemplateHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler): pass
Expand Down
5 changes: 3 additions & 2 deletions examples/simple/simple_ext2/handlers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.extension.handler import ExtensionHandlerMixin, ExtensionHandlerJinjaMixin
from jupyter_server.utils import url_escape

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

class BaseTemplateHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler): pass
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/contents/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def get(self, path):
self.redirect(url_path_join(
self.base_url,
'api/contents',
path
url_escape(path)
))

put = patch = post = delete = get
Expand Down

0 comments on commit d24f9f6

Please sign in to comment.