Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 18a5b44

Browse files
committedMar 13, 2025·
Check paths before rendering static files.
Test quickly, merge quickly. Don't ask questions.
1 parent f27977b commit 18a5b44

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed
 

‎lib/Mojolicious/WeBWorK.pm

+13-7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use WeBWorK;
3030
use WeBWorK::CourseEnvironment;
3131
use WeBWorK::Utils::Logs qw(writeTimingLogEntry);
3232
use WeBWorK::Utils::Routes qw(setup_content_generator_routes);
33+
use WeBWorK::Utils::Files qw(path_is_subdir);
3334

3435
sub startup ($app) {
3536
# Set up logging.
@@ -193,9 +194,11 @@ sub startup ($app) {
193194
$r->any(
194195
"$webwork_htdocs_url/*static" => sub ($c) {
195196
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);
197199
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/");
199202
return $c->render(data => 'File not found', status => 404);
200203
}
201204
);
@@ -204,16 +207,18 @@ sub startup ($app) {
204207
$r->any(
205208
"$pg_htdocs_url/*static" => sub ($c) {
206209
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/");
208212
return $c->render(data => 'File not found', status => 404);
209213
}
210214
);
211215

212216
# Provide access to course-specific resources.
213217
$r->any(
214218
"$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);
217222
return $c->render(data => 'File not found', status => 404);
218223
}
219224
);
@@ -222,7 +227,7 @@ sub startup ($app) {
222227
$r->any(
223228
"$ce->{webworkURLs}{htdocs_temp}/*static" => sub ($c) {
224229
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}/");
226231
return $c->render(data => 'File not found', status => 404);
227232
}
228233
);
@@ -249,7 +254,8 @@ sub startup ($app) {
249254
$r->any(
250255
"/.well-known/*static" => sub ($c) {
251256
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/");
253259
return $c->render(data => 'File not found', status => 404);
254260
}
255261
);

0 commit comments

Comments
 (0)
Please sign in to comment.