Skip to content

Commit b8e663a

Browse files
authored
Merge pull request #2691 from drgrice1/sanitize-course-name
Sanitize the courseID from either the URL path or the request parameters.
2 parents 6395021 + 0c28eae commit b8e663a

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/WeBWorK/CourseEnvironment.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ sub new {
9696
$seedVars->{pg_dir} //= $WeBWorK::SeedCE{pg_dir} // $ENV{PG_ROOT};
9797

9898
$seedVars->{courseName} ||= '___'; # prevents extraneous error messages
99+
$seedVars->{courseName} =~ s/'.*$//;
99100

100101
# The following line is a work around for a bug that occurs on some systems. See
101102
# https://rt.cpan.org/Public/Bug/Display.html?id=77916 and

lib/WeBWorK/Utils/Routes.pm

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ my %routeParameters = (
296296
logout options instructor_tools problem_list)
297297
],
298298
module => 'ProblemSets',
299-
path => '/#courseID'
299+
path => { '/#courseID' => [ courseID => qr/[\w-]*/ ] }
300300
},
301301

302302
logout => {
@@ -429,7 +429,7 @@ my %routeParameters = (
429429
instructor_problem_grader => {
430430
title => x('Manual Grader'),
431431
module => 'Instructor::ProblemGrader',
432-
path => '/grader/#setID/#problemID'
432+
path => '/grader/#setID/<problemID:num>'
433433
},
434434
instructor_add_users => {
435435
title => x('Add Users'),
@@ -471,7 +471,7 @@ my %routeParameters = (
471471
instructor_problem_editor_withset_withproblem => {
472472
title => '[_3]',
473473
module => 'Instructor::PGProblemEditor',
474-
path => '/#problemID'
474+
path => '/<problemID:num>'
475475
},
476476
instructor_scoring => {
477477
title => x('Scoring Tools'),
@@ -503,7 +503,7 @@ my %routeParameters = (
503503
instructor_problem_statistics => {
504504
title => '[_3]',
505505
module => 'Instructor::Stats',
506-
path => '/#problemID'
506+
path => '/<problemID:num>'
507507
},
508508
instructor_user_statistics => {
509509
title => '[_1]',
@@ -570,7 +570,7 @@ my %routeParameters = (
570570
title => '[_3]',
571571
children => [qw(show_me_another)],
572572
module => 'Problem',
573-
path => '/#problemID',
573+
path => '/<problemID:num>',
574574
unrestricted => 1
575575
},
576576
show_me_another => {
@@ -617,15 +617,22 @@ sub setup_content_generator_routes_recursive {
617617
my $action = $routeParameters{$child}{action} // 'go';
618618

619619
if ($routeParameters{$child}{children}) {
620-
my $child_route = $route->under($routeParameters{$child}{path}, [ problemID => qr/\d+/ ])->name($child);
620+
my $child_route = $route->under(
621+
ref($routeParameters{$child}{path}) eq 'HASH'
622+
? %{ $routeParameters{$child}{path} }
623+
: $routeParameters{$child}{path})->name($child);
621624
$child_route->any($routeParameters{$child}{methods} // (), '/')->to("$routeParameters{$child}{module}#$action")
622625
->name($child);
623626
for (@{ $routeParameters{$child}{children} }) {
624627
setup_content_generator_routes_recursive($child_route, $_);
625628
}
626629
} else {
627-
$route->any($routeParameters{$child}{methods} // (), $routeParameters{$child}{path}, [ problemID => qr/\d+/ ])
628-
->to("$routeParameters{$child}{module}#$action")->name($child);
630+
$route->any(
631+
$routeParameters{$child}{methods} // (),
632+
ref($routeParameters{$child}{path}) eq 'HASH'
633+
? %{ $routeParameters{$child}{path} }
634+
: $routeParameters{$child}{path}
635+
)->to("$routeParameters{$child}{module}#$action")->name($child);
629636
}
630637

631638
return;

0 commit comments

Comments
 (0)