Skip to content

Commit e52d204

Browse files
kkangshawnSiwon Kang
authored andcommitted
bpo-38863: Improve is_cgi() in http.server
is_cgi() function of http.server library does not currently handle a cgi script if one of the cgi_directories is located at the sub-directory of given path. Since is_cgi() in CGIHTTPRequestHandler class separates given path into (dir, rest) based on the first seen '/', multi-level directories like /sub/dir/cgi-bin/hello.py is divided into head=/sub, rest=dir/cgi-bin/hello.py then check whether '/sub' exists in cgi_directories = [..., '/sub/dir/cgi-bin']. This patch makes the is_cgi() keep expanding dir part to the next '/' then checking if that expanded path exists in the cgi_directories. Signed-off-by: Siwon Kang <[email protected]>
1 parent 4dedd0f commit e52d204

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Lib/http/server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,8 +1014,10 @@ def is_cgi(self):
10141014
"""
10151015
collapsed_path = _url_collapse_path(self.path)
10161016
dir_sep = collapsed_path.find('/', 1)
1017-
head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:]
1018-
if head in self.cgi_directories:
1017+
while dir_sep > 0 and not collapsed_path[:dir_sep] in self.cgi_directories:
1018+
dir_sep = collapsed_path.find('/', dir_sep+1)
1019+
if dir_sep > 0:
1020+
head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:]
10191021
self.cgi_info = head, tail
10201022
return True
10211023
return False

0 commit comments

Comments
 (0)