@@ -30,6 +30,7 @@ use WeBWorK;
30
30
use WeBWorK::CourseEnvironment;
31
31
use WeBWorK::Utils::Logs qw( writeTimingLogEntry) ;
32
32
use WeBWorK::Utils::Routes qw( setup_content_generator_routes) ;
33
+ use WeBWorK::Utils::Files qw( path_is_subdir) ;
33
34
34
35
sub startup ($app ) {
35
36
# Set up logging.
@@ -193,9 +194,11 @@ sub startup ($app) {
193
194
$r -> any(
194
195
" $webwork_htdocs_url /*static" => sub ($c ) {
195
196
my $webwork_htdocs_file = " $webwork_htdocs_dir /" . $c -> stash(' static' );
196
- return $c -> reply-> file($webwork_htdocs_file ) if -r $webwork_htdocs_file ;
197
+ return $c -> reply-> file($webwork_htdocs_file )
198
+ if -r $webwork_htdocs_file && path_is_subdir($webwork_htdocs_file , $webwork_htdocs_dir );
197
199
my $pg_htdocs_file = " $ENV {PG_ROOT}/htdocs/" . $c -> stash(' static' );
198
- return $c -> reply-> file($pg_htdocs_file ) if -r $pg_htdocs_file ;
200
+ return $c -> reply-> file($pg_htdocs_file )
201
+ if -r $pg_htdocs_file && path_is_subdir($pg_htdocs_file , " $ENV {PG_ROOT}/htdocs/" );
199
202
return $c -> render(data => ' File not found' , status => 404);
200
203
}
201
204
);
@@ -204,16 +207,18 @@ sub startup ($app) {
204
207
$r -> any(
205
208
" $pg_htdocs_url /*static" => sub ($c ) {
206
209
my $pg_htdocs_file = " $ENV {PG_ROOT}/htdocs/" . $c -> stash(' static' );
207
- return $c -> reply-> file($pg_htdocs_file ) if -r $pg_htdocs_file ;
210
+ return $c -> reply-> file($pg_htdocs_file )
211
+ if -r $pg_htdocs_file && path_is_subdir($pg_htdocs_file , " $ENV {PG_ROOT}/htdocs/" );
208
212
return $c -> render(data => ' File not found' , status => 404);
209
213
}
210
214
);
211
215
212
216
# Provide access to course-specific resources.
213
217
$r -> any(
214
218
" $webwork_courses_url /#course/*static" => sub ($c ) {
215
- my $file = " $webwork_courses_dir /" . $c -> stash(' course' ) . ' /html/' . $c -> stash(' static' );
216
- return $c -> reply-> file($file ) if -r $file ;
219
+ my $course_html_dir = " $webwork_courses_dir /" . $c -> stash(' course' ) . ' /html/' ;
220
+ my $file = $course_html_dir . $c -> stash(' static' );
221
+ return $c -> reply-> file($file ) if -r $file && path_is_subdir($file , $course_html_dir );
217
222
return $c -> render(data => ' File not found' , status => 404);
218
223
}
219
224
);
@@ -222,7 +227,7 @@ sub startup ($app) {
222
227
$r -> any(
223
228
" $ce ->{webworkURLs}{htdocs_temp}/*static" => sub ($c ) {
224
229
my $file = " $ce ->{webworkDirs}{htdocs_temp}/" . $c -> stash(' static' );
225
- return $c -> reply-> file($file ) if -r $file ;
230
+ return $c -> reply-> file($file ) if -r $file && path_is_subdir( $file , " $ce ->{webworkDirs}{htdocs_temp}/ " ) ;
226
231
return $c -> render(data => ' File not found' , status => 404);
227
232
}
228
233
);
@@ -249,7 +254,8 @@ sub startup ($app) {
249
254
$r -> any(
250
255
" /.well-known/*static" => sub ($c ) {
251
256
my $file = " $ce ->{webworkDirs}{tmp}/.well-known/" . $c -> stash(' static' );
252
- return $c -> reply-> file($file ) if -r $file ;
257
+ return $c -> reply-> file($file )
258
+ if -r $file && path_is_subdir($file , " $ce ->{webworkDirs}{tmp}/.well-known/" );
253
259
return $c -> render(data => ' File not found' , status => 404);
254
260
}
255
261
);
0 commit comments