Bug 42254: Prevent XSS when testing tags

Signed-off-by: David Cook <dcook@prosentient.com.au>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2026-04-03 10:44:18 +02:00 committed by Lucas Gass
parent 4c91dacfaf
commit 4d82aa7a39
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 37 additions and 26 deletions

View File

@ -1,6 +1,6 @@
review_ajax_params = {
url: "/cgi-bin/koha/tags/review.pl",
dataType: "script",
dataType: "json",
};
var ok_count = 0;
@ -21,6 +21,11 @@ function pull_counts() {
}
function count_approve() {
if (response.status == "success") {
success_approve(response.tag);
} else {
failure_approve(response.tag);
}
pull_counts();
if (nok_count > 0) {
$("#terms_summary_unapproved_count").html(nok_count - 1);
@ -28,7 +33,12 @@ function count_approve() {
}
}
function count_reject() {
function count_reject(response) {
if (response.status == "success") {
success_reject(response.tag);
} else {
failure_reject(response.tag);
}
pull_counts();
if (nok_count > 0) {
$("#terms_summary_unapproved_count").html(nok_count - 1);
@ -40,33 +50,34 @@ var success_approve = function (tag) {
// window.alert(__("AJAX approved tag: ") + tag);
};
var failure_approve = function (tag) {
window.alert(
__("AJAX failed to approve tag: %s").format(decodeURIComponent(tag))
);
window.alert(__("AJAX failed to approve tag: %s").format(escape_str(tag)));
};
var success_reject = function (tag) {
// window.alert(__("AJAX rejected tag: ") + tag);
};
var failure_reject = function (tag) {
window.alert(
__("AJAX failed to reject tag: %s").format(decodeURIComponent(tag))
);
window.alert(__("AJAX failed to reject tag: %s").format(escape_str(tag)));
};
var success_test = function (tag) {
$("#verdict").html(__("%s is permitted!").format(decodeURIComponent(tag)));
$("#verdict").html(__("%s is permitted!").format(escape_str(tag)));
};
var failure_test = function (tag) {
$("#verdict").html(__("%s is prohibited!").format(decodeURIComponent(tag)));
$("#verdict").html(__("%s is prohibited!").format(escape_str(tag)));
};
var indeterminate_test = function (tag) {
$("#verdict").html(
__("%s is neither permitted nor prohibited!").format(
decodeURIComponent(tag)
)
__("%s is neither permitted nor prohibited!").format(escape_str(tag))
);
};
var success_test_call = function () {
var success_test_call = function (response) {
if (response.status == "success") {
success_test(response.tag);
} else if (response.status == "failure") {
failure_test(response.tag);
} else {
indeterminate_test(response.tag);
}
$("#test_button").prop("disabled", false);
$("#test_button").html(
"<i class='fa fa-check-square' aria-hidden='true'></i>" + __(" Test")
@ -213,7 +224,7 @@ $(document).ready(function () {
{ ...review_ajax_params, type: "GET" },
{
data: {
tag: escape_str($("#test").val()),
tag: $("#test").val(),
op: "test",
},
success: success_test_call, // success_reject

View File

@ -23,7 +23,8 @@ use Modern::Perl;
use POSIX qw( ceil );
use CGI qw ( -utf8 );
use CGI::Cookie; # need to check cookies before having CGI parse the POST request
use URI::Escape qw( uri_escape_utf8 uri_unescape );
use URI::Escape qw( uri_unescape );
use JSON qw(encode_json);
use C4::Auth qw( check_cookie_auth get_template_and_user );
use C4::Context;
use C4::Output qw( output_with_http_headers is_ajax pagination_bar output_html_with_http_headers );
@ -59,21 +60,20 @@ if ( is_ajax() ) {
my $js_reply;
my $op = $input->param('op') || q{};
my $tag = $input->param('tag');
my $status;
if ( $op eq 'test' ) {
$tag = uri_unescape($tag);
my $check = is_approved($tag);
$js_reply =
( $check >= 1 ? 'success' : $check <= -1 ? 'failure' : 'indeterminate' )
. "_test('"
. uri_escape_utf8($tag) . "');\n";
$status = $check >= 1 ? 'success' : $check <= -1 ? 'failure' : 'indeterminate';
} elsif ( $op eq 'cud-approve' ) {
$js_reply =
( whitelist( $operator, $tag ) ? 'success' : 'failure' ) . "_approve('" . uri_escape_utf8($tag) . "');\n";
$status = whitelist( $operator, $tag ) ? 'success' : 'failure';
} elsif ( $op eq 'cud-reject' ) {
$js_reply =
( blacklist( $operator, $tag ) ? 'success' : 'failure' ) . "_reject('" . uri_escape_utf8($tag) . "');\n";
$status = blacklist( $operator, $tag ) ? 'success' : 'failure';
}
output_with_http_headers $input, undef, $js_reply, 'js';
my $response = {
status => $status,
tag => $tag,
};
output_with_http_headers $input, undef, encode_json($response), 'js';
exit;
}