Skip to content

Commit

Permalink
Fix security notices (#8474)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwainm authored Mar 26, 2024
1 parent a8068cf commit d3f595e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-multi-currency-phpcs-notices
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Escaping error logs and ignoring noticese where there are no issues.
8 changes: 5 additions & 3 deletions includes/multi-currency/MultiCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public function update_single_currency_settings( string $currency_code, string $
if ( ! is_numeric( $manual_rate ) || 0 >= $manual_rate ) {
$message = 'Invalid manual currency rate passed to update_single_currency_settings: ' . $manual_rate;
Logger::error( $message );
throw new InvalidCurrencyRateException( $message, 'wcpay_multi_currency_invalid_currency_rate', 500 );
throw new InvalidCurrencyRateException( esc_html( $message ), 'wcpay_multi_currency_invalid_currency_rate', 500 );
}
update_option( 'wcpay_multi_currency_manual_rate_' . $currency_code, $manual_rate );
}
Expand Down Expand Up @@ -935,7 +935,7 @@ public function get_raw_conversion( float $amount, string $to_currency, string $
if ( 0 >= $from_currency_rate ) {
$message = 'Invalid rate for from_currency in get_raw_conversion: ' . $from_currency_rate;
Logger::error( $message );
throw new InvalidCurrencyRateException( $message, 'wcpay_multi_currency_invalid_currency_rate', 500 );
throw new InvalidCurrencyRateException( esc_html( $message ), 'wcpay_multi_currency_invalid_currency_rate', 500 );
}

$amount = $amount * ( $to_currency_rate / $from_currency_rate );
Expand Down Expand Up @@ -1019,6 +1019,8 @@ public function display_geolocation_currency_update_notice() {
$notice_id = md5( $message );

echo '<p class="woocommerce-store-notice demo_store" data-notice-id="' . esc_attr( $notice_id . 2 ) . '" style="display:none;">';
// No need to escape here as the function called handles it.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo \WC_Payments_Utils::esc_interpolated_html(
$message,
[
Expand Down Expand Up @@ -1624,7 +1626,7 @@ public function is_initialized(): bool {
private function log_and_throw_invalid_currency_exception( $method, $currency_code, $code = 500 ) {
$message = 'Invalid currency passed to ' . $method . ': ' . $currency_code;
Logger::error( $message );
throw new InvalidCurrencyException( $message, 'wcpay_multi_currency_invalid_currency', $code );
throw new InvalidCurrencyException( esc_html( $message ), 'wcpay_multi_currency_invalid_currency', esc_html( $code ) );
}

/**
Expand Down

0 comments on commit d3f595e

Please sign in to comment.