Skip to content

Commit e8fc44e

Browse files
committed
Fix a potential XSS vulnerability on the hardcopy page.
This is another case where a URL parameter is inserted directly into the page without being escaped. This just escapes the parameter value to prevent the possibility of an XSS attack.
1 parent 0f46cbc commit e8fc44e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/WeBWorK/ContentGenerator/Hardcopy.pm

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ problem sets.
1010

1111
use File::Temp qw/tempdir/;
1212
use Mojo::File;
13+
use Mojo::Util qw(xml_escape);
1314
use String::ShellQuote;
1415
use Archive::Zip qw(:ERROR_CODES);
1516
use XML::LibXML;
@@ -130,14 +131,16 @@ async sub pre_header_initialize ($c) {
130131

131132
# Make sure the format is valid.
132133
unless (grep { $_ eq $hardcopy_format } keys %HC_FORMATS) {
133-
$c->addbadmessage(qq{"$hardcopy_format" is not a valid hardcopy format.});
134+
$c->addbadmessage($c->maketext('"[_1]" is not a valid hardcopy format.', xml_escape($hardcopy_format)));
134135
$validation_failed = 1;
135136
}
136137

137138
# Make sure we are allowed to generate hardcopy in this format.
138139
unless ($authz->hasPermissions($userID, "download_hardcopy_format_$hardcopy_format")) {
139-
$c->addbadmessage(
140-
$c->maketext('You do not have permission to generate hardcopy in [_1] format.', $hardcopy_format));
140+
$c->addbadmessage($c->maketext(
141+
'You do not have permission to generate hardcopy in [_1] format.',
142+
xml_escape($hardcopy_format)
143+
));
141144
$validation_failed = 1;
142145
}
143146

@@ -284,13 +287,14 @@ async sub pre_header_initialize ($c) {
284287
my $fullFilePath = "$ce->{webworkDirs}{tmp}/$courseID/hardcopy/$userID/$tempFile";
285288

286289
unless (-e $fullFilePath) {
287-
$c->addbadmessage($c->maketext('The requested file "[_1]" does not exist on the server.', $tempFile));
290+
$c->addbadmessage(
291+
$c->maketext('The requested file "[_1]" does not exist on the server.', xml_escape($tempFile)));
288292
return;
289293
}
290294

291295
unless ($baseName =~ /\.$userID\./ || $authz->hasPermissions($userID, 'download_hardcopy_multiuser')) {
292296
$c->addbadmessage($c->maketext('You do not have permission to access the requested file "[_1]".'),
293-
$tempFile);
297+
xml_escape($tempFile));
294298
return;
295299
}
296300

0 commit comments

Comments
 (0)