Skip to content

Commit c8cedf1

Browse files
authored
Resolve XSS vulnerability in local Wordnet browser (nltk#3096)
By setting the Content-type to text/plain when an unknown path is used.
1 parent 2e11807 commit c8cedf1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

nltk/app/wordnet_app.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@ def do_GET(self):
127127
else:
128128
# Handle files here.
129129
word = sp
130-
page = get_static_page_by_path(usp)
130+
try:
131+
page = get_static_page_by_path(usp)
132+
except FileNotFoundError:
133+
page = "Internal error: Path for static page '%s' is unknown" % usp
134+
# Set type to plain to prevent XSS by printing the path as HTML
135+
type = "text/plain"
131136
elif sp.startswith("search"):
132137
# This doesn't seem to work with MWEs.
133138
type = "text/html"
@@ -816,8 +821,7 @@ def get_static_page_by_path(path):
816821
return get_static_web_help_page()
817822
elif path == "wx_help.html":
818823
return get_static_wx_help_page()
819-
else:
820-
return "Internal error: Path for static page '%s' is unknown" % path
824+
raise FileNotFoundError()
821825

822826

823827
def get_static_web_help_page():

0 commit comments

Comments
 (0)