Skip to content

Commit 4d2665f

Browse files
committed
fix: resolve PHPCS security warnings
- Replace $_SERVER['HTTP_HOST'] with home_url() in Apple Pay verification - Simplify domain extraction logic using WordPress best practices - Fix multiline phpcs:ignore statement in get_save_payment_card_checkbox() - Add explanation comment for nonce verification ignore - Add WPCS: CSRF ok marker for $_POST access (called after WC nonce verification) All PHPCS errors resolved. Code remains secure - methods accessing $_POST are only invoked after WooCommerce nonce verification in process_payment().
1 parent 24c8082 commit 4d2665f

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/Gateways/Abstracts/WCMoneiPaymentGateway.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,8 @@ protected function get_payment_token_id_if_selected() {
284284
* @return bool
285285
*/
286286
protected function get_save_payment_card_checkbox() {
287-
// phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
288-
return isset( $_POST[ 'wc-' . $this->id . '-new-payment-method' ] ) &&
289-
filter_var( wp_unslash( $_POST[ 'wc-' . $this->id . '-new-payment-method' ] ), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE );
287+
// phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- WooCommerce handles nonce verification before process_payment()
288+
return isset( $_POST[ 'wc-' . $this->id . '-new-payment-method' ] ) && filter_var( wp_unslash( $_POST[ 'wc-' . $this->id . '-new-payment-method' ] ), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ); // WPCS: CSRF ok.
290289
}
291290

292291
/**

src/Services/MoneiApplePayVerificationService.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,9 @@ public function apple_domain_register() {
4747
}
4848

4949
try {
50-
// Extract domain from HTTP_HOST or get_site_url()
51-
if ( isset( $_SERVER['HTTP_HOST'] ) ) {
52-
// Parse HTTP_HOST to remove port portion and get host only
53-
$host_parts = explode( ':', $_SERVER['HTTP_HOST'] );
54-
$domain = sanitize_text_field( $host_parts[0] );
55-
} else {
56-
// Use wp_parse_url to extract host from get_site_url()
57-
$parsed_url = wp_parse_url( get_site_url() );
58-
$domain = isset( $parsed_url['host'] ) ? sanitize_text_field( $parsed_url['host'] ) : '';
59-
}
50+
// Extract domain from site URL (WordPress best practice)
51+
$parsed_url = wp_parse_url( home_url() );
52+
$domain = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
6053

6154
// Ensure domain is not empty before registering
6255
if ( empty( $domain ) ) {

0 commit comments

Comments
 (0)