File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -162,8 +162,15 @@ def do_GET(self):
162
162
self .wfile .write (response .encode ("UTF-8" , "replace" ))
163
163
elif self .symcov_data .has_file (norm_path ):
164
164
filename = norm_path
165
- filepath = os .path .join (self .src_path , filename )
166
- if not os .path .exists (filepath ):
165
+ # Construct the full file path, normalizing it to avoid traversal
166
+ abs_src_path = os .path .realpath (self .src_path )
167
+ abs_file_path = os .path .realpath (os .path .join (self .src_path , filename ))
168
+ # Check containment: file must reside within src_path
169
+ if not abs_file_path .startswith (abs_src_path + os .sep ):
170
+ self .send_response (403 )
171
+ self .end_headers ()
172
+ return
173
+ if not os .path .exists (abs_file_path ):
167
174
self .send_response (404 )
168
175
self .end_headers ()
169
176
return
@@ -174,7 +181,7 @@ def do_GET(self):
174
181
175
182
linemap = self .symcov_data .compute_linemap (filename )
176
183
177
- with open (filepath , "r" , encoding = "utf8" ) as f :
184
+ with open (abs_file_path , "r" , encoding = "utf8" ) as f :
178
185
content = "\n " .join (
179
186
[
180
187
"<span class='{cls}'>{line} </span>" .format (
You can’t perform that action at this time.
0 commit comments