Skip to content

Commit b33a818

Browse files
Merge pull request #107 from PaystackOSS/release/4.0.6
Release 4.0.6
2 parents b606a6a + cfc4694 commit b33a818

18 files changed

Lines changed: 674 additions & 43 deletions

‎.distignore‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
/node_modules
55

66
.distignore
7-
.gitignore
7+
.gitignore
8+
/tests
9+
/docs

‎includes/classes/class-form-shortcode.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public function form_shortcode( $atts ) {
111111
// First lets check for a public key.
112112
$public_key = $this->helpers->get_public_key();
113113
if ( ! $public_key ) {
114+
if ( ! current_user_can( Settings::get_capability() ) ) {
115+
return '<h5>' . esc_html__( 'Payment is not available right now. Please contact the site administrator.', 'pff-paystack' ) . '</h5>';
116+
}
114117
$settings_link = esc_url( get_admin_url( null, 'edit.php?post_type=paystack_form&page=settings' ) );
115118
return sprintf(
116119
'<h5>%s <a href="%s">%s</a></h5>',

‎includes/classes/class-forms-list.php‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public function quick_edit_links( $actions, $post ) {
3636
if ( get_post_type( $post ) === 'paystack_form' ) {
3737
unset( $actions['view'] );
3838
unset( $actions['quick edit'] );
39-
$actions['export'] = '<a href="' . admin_url( 'edit.php?post_type=paystack_form&page=submissions&form=' . $post->ID ) . '" >' . esc_html__( 'View Payments', 'payment_forms' ) . '</a>';
39+
if ( current_user_can( Submissions::get_capability() ) ) {
40+
$actions['export'] = '<a href="' . admin_url( 'edit.php?post_type=paystack_form&page=submissions&form=' . $post->ID ) . '" >' . esc_html__( 'View Payments', 'payment_forms' ) . '</a>';
41+
}
4042
}
4143
return $actions;
4244
}
@@ -52,9 +54,11 @@ public function register_columns( $columns ) {
5254
'cb' => '<input type="checkbox" />',
5355
'title' => esc_html__( 'Name', 'pff-paystack' ),
5456
'shortcode' => esc_html__( 'Shortcode', 'pff-paystack' ),
55-
'payments' => esc_html__( 'Payments', 'pff-paystack' ),
56-
'date' => esc_html__( 'Date', 'pff-paystack' )
5757
);
58+
if ( current_user_can( Submissions::get_capability() ) ) {
59+
$columns['payments'] = esc_html__( 'Payments', 'pff-paystack' );
60+
}
61+
$columns['date'] = esc_html__( 'Date', 'pff-paystack' );
5862
return $columns;
5963
}
6064

‎includes/classes/class-helpers.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ public function format_meta_as_custom_fields( $metadata ) {
767767
break;
768768

769769
default:
770-
$display_name = ucwords( str_replace( array( '_', '-', 'pf' ), ' ', $key ) );
770+
$display_name = sanitize_text_field( ucwords( str_replace( array( '_', '-', 'pf' ), ' ', $key ) ) );
771771
$fields[] = array(
772772
'display_name' => $display_name,
773773
'variable_name' => $key,

‎includes/classes/class-payments-list-table.php‎

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ public function format_row_data( $alldata ) {
164164
}
165165
$new_data[] = array(
166166
'id' => $new_key,
167-
'email' => '<a href="mailto:' . $row->email . '">' . $row->email . '</a>',
168-
'amount' => $currency . '<b>' . number_format( $row->amount ) . '</b>',
169-
'txn_code' => $txn_code,
167+
'email' => '<a href="' . esc_url( 'mailto:' . $row->email ) . '">' . esc_html( $row->email ) . '</a>',
168+
'amount' => esc_html( $currency ) . '<b>' . number_format( $row->amount ) . '</b>',
169+
'txn_code' => esc_html( $txn_code ),
170170
'metadata' => $this->format_metadata( $row->metadata ),
171-
'date' => $row->created_at
171+
'date' => esc_html( $row->created_at )
172172
);
173173
}
174174
return $new_data;
@@ -181,26 +181,35 @@ public function format_row_data( $alldata ) {
181181
* @return string
182182
*/
183183
public function format_metadata( $data ) {
184-
$new = json_decode( $data );
184+
$new = json_decode( $data, true );
185185
$text = '';
186186

187+
if ( ! is_array( $new ) ) {
188+
return '';
189+
}
190+
187191
// Determine both for backwards compatability
188-
if ( array_key_exists( "0", $new ) ) {
189-
foreach ( $new as $key => $item ) {
190-
if ( $item->type == 'text' ) {
191-
$text .= '<b>' . $item->display_name . ": </b> " . $item->value . "<br />";
192+
if ( array_key_exists( 0, $new ) ) {
193+
foreach ( $new as $item ) {
194+
if ( ! is_array( $item ) ) {
195+
continue;
196+
}
197+
$display_name = isset( $item['display_name'] ) ? esc_html( (string) $item['display_name'] ) : '';
198+
$value = isset( $item['value'] ) && is_scalar( $item['value'] ) ? (string) $item['value'] : '';
199+
if ( isset( $item['type'] ) && 'text' === $item['type'] ) {
200+
$text .= '<b>' . $display_name . ": </b> " . esc_html( $value ) . "<br />";
192201
} else {
193-
$text .= '<b>' . $item->display_name . ": </b> <a target='_blank' href='" . $item->value . "'>link</a><br />";
202+
$text .= '<b>' . $display_name . ": </b> <a target='_blank' rel='noopener noreferrer' href='" . esc_url( $value ) . "'>link</a><br />";
194203
}
195204
}
196205
} else {
197-
$text = '';
198-
if ( count( $new ) > 0 ) {
199-
foreach ( $new as $key => $item ) {
200-
$text .= '<b>' . $key . ": </b> " . $item . "<br />";
206+
foreach ( $new as $key => $item ) {
207+
if ( ! is_scalar( $item ) ) {
208+
continue;
201209
}
210+
$text .= '<b>' . esc_html( $key ) . ": </b> " . esc_html( (string) $item ) . "<br />";
202211
}
203212
}
204213
return $text;
205214
}
206-
}
215+
}

‎includes/classes/class-paystack-forms.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ private function set_variables() {
113113
'email-receipt' => 'Email_Receipt',
114114
'email-receipt-owner' => 'Email_Receipt_Owner',
115115
'retry-submit' => 'Retry_Submit',
116+
'php-version-notice' => 'PHP_Version_Notice',
116117
);
117118
}
118119

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
<?php
2+
/**
3+
* Warns administrators when the server runs a vulnerable PHP version.
4+
*
5+
* @package \paystack\payment_forms
6+
*/
7+
8+
namespace paystack\payment_forms;
9+
10+
if ( ! defined( 'ABSPATH' ) ) {
11+
exit;
12+
}
13+
14+
/**
15+
* PHP version notice class.
16+
*/
17+
class PHP_Version_Notice {
18+
19+
/**
20+
* First patched release per supported minor branch.
21+
*
22+
* CVE-2026-109618 / CVE-2026-109619; 8.1 and older are end of life with no fix.
23+
*
24+
* @var array
25+
*/
26+
const FIXED_PATCH = array(
27+
'8.2' => 35,
28+
'8.3' => 36,
29+
'8.4' => 27,
30+
'8.5' => 12,
31+
);
32+
33+
/**
34+
* Construct the class.
35+
*/
36+
public function __construct() {
37+
add_filter( 'site_status_tests', array( $this, 'add_site_health_test' ) );
38+
add_action( 'admin_notices', array( $this, 'admin_notice' ) );
39+
}
40+
41+
/**
42+
* Check whether a PHP version is affected.
43+
*
44+
* @param string $version PHP version string.
45+
*
46+
* @return bool
47+
*/
48+
public static function is_affected( $version ) {
49+
if ( ! preg_match( '/^(\d+)\.(\d+)(?:\.(\d+))?/', (string) $version, $matches ) ) {
50+
return false;
51+
}
52+
53+
$major = (int) $matches[1];
54+
$minor = (int) $matches[2];
55+
$patch = isset( $matches[3] ) ? (int) $matches[3] : 0;
56+
57+
if ( $major < 8 || ( 8 === $major && $minor < 2 ) ) {
58+
return true;
59+
}
60+
61+
$key = $major . '.' . $minor;
62+
63+
return isset( self::FIXED_PATCH[ $key ] ) && $patch < self::FIXED_PATCH[ $key ];
64+
}
65+
66+
/**
67+
* Get the running PHP release, without any distro suffix.
68+
*
69+
* @return string
70+
*/
71+
private static function current_version() {
72+
return PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;
73+
}
74+
75+
/**
76+
* Whether this is a distro build whose security fixes may be backported.
77+
*
78+
* @return bool
79+
*/
80+
private static function is_distro_build() {
81+
return '' !== PHP_EXTRA_VERSION;
82+
}
83+
84+
/**
85+
* Whether the running version is affected, ignoring distro backports.
86+
*
87+
* @return bool
88+
*/
89+
private function is_vulnerable() {
90+
return self::is_affected( self::current_version() ) && apply_filters( 'pff_paystack_php_version_warning', true );
91+
}
92+
93+
/**
94+
* Whether the admin notice should be shown.
95+
*
96+
* @return bool
97+
*/
98+
private function should_warn() {
99+
return $this->is_vulnerable() && ! self::is_distro_build();
100+
}
101+
102+
/**
103+
* Build the warning message.
104+
*
105+
* @return string
106+
*/
107+
private function message() {
108+
$fixed = array();
109+
foreach ( self::FIXED_PATCH as $branch => $patch ) {
110+
$fixed[] = $branch . '.' . $patch;
111+
}
112+
113+
return sprintf(
114+
/* translators: 1: PHP version, 2: list of fixed PHP versions. */
115+
esc_html__( 'Payment Forms for Paystack: this server runs PHP %1$s, which is affected by critical security vulnerabilities (CVE-2026-109618, CVE-2026-109619) that allow remote code execution. Ask your hosting provider to upgrade to PHP %2$s or later. If your host backports security fixes to older PHP builds, this warning may not apply.', 'pff-paystack' ),
116+
esc_html( PHP_VERSION ),
117+
esc_html( implode( ', ', $fixed ) )
118+
);
119+
}
120+
121+
/**
122+
* Add the Site Health test.
123+
*
124+
* @param array $tests Site Health tests.
125+
*
126+
* @return array
127+
*/
128+
public function add_site_health_test( $tests ) {
129+
$tests['direct']['pff_paystack_php_version'] = array(
130+
'label' => esc_html__( 'Payment Forms for Paystack PHP version', 'pff-paystack' ),
131+
'test' => array( $this, 'site_health_result' ),
132+
);
133+
134+
return $tests;
135+
}
136+
137+
/**
138+
* Site Health test callback.
139+
*
140+
* @return array
141+
*/
142+
public function site_health_result() {
143+
$affected = $this->is_vulnerable();
144+
if ( ! $affected ) {
145+
$status = 'good';
146+
} else {
147+
$status = self::is_distro_build() ? 'recommended' : 'critical';
148+
}
149+
$colors = array(
150+
'good' => 'blue',
151+
'recommended' => 'orange',
152+
'critical' => 'red',
153+
);
154+
155+
return array(
156+
'label' => $affected
157+
? esc_html__( 'PHP version has known critical vulnerabilities', 'pff-paystack' )
158+
: esc_html__( 'PHP version is not affected by CVE-2026-109618 or CVE-2026-109619', 'pff-paystack' ),
159+
'status' => $status,
160+
'badge' => array(
161+
'label' => esc_html__( 'Security', 'pff-paystack' ),
162+
'color' => $colors[ $status ],
163+
),
164+
'description' => '<p>' . ( $affected
165+
? $this->message()
166+
: esc_html__( 'This server\'s PHP version is not affected by CVE-2026-109618 or CVE-2026-109619.', 'pff-paystack' ) ) . '</p>',
167+
'actions' => sprintf(
168+
'<p><a href="%s" target="_blank" rel="noopener noreferrer">%s</a></p>',
169+
esc_url( 'https://www.php.net/supported-versions.php' ),
170+
esc_html__( 'View supported PHP versions', 'pff-paystack' )
171+
),
172+
'test' => 'pff_paystack_php_version',
173+
);
174+
}
175+
176+
/**
177+
* Display the admin notice.
178+
*
179+
* @return void
180+
*/
181+
public function admin_notice() {
182+
if ( ! current_user_can( Settings::get_capability() ) || ! $this->should_warn() ) {
183+
return;
184+
}
185+
186+
$screen = get_current_screen();
187+
if ( ! $screen || ( 'plugins' !== $screen->id && 'paystack_form' !== $screen->post_type ) ) {
188+
return;
189+
}
190+
191+
echo '<div class="notice notice-warning"><p>' . $this->message() . '</p></div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in message().
192+
}
193+
}

0 commit comments

Comments
 (0)