Skip to content

Commit 0ab86ce

Browse files
authored
Fixes
1 parent 872369f commit 0ab86ce

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- **CSRF in admin_init**: Restored nonce verification in `admin_init()` before processing form data to prevent CSRF. The v1.5.1 removal was incorrect — without it, `$_POST` is accessed before any security check.
12+
- **XSS in Success Notice**: Wrapped `sprintf()` output in `esc_html()` (using `__()` instead of `esc_html__()` for the format string) to properly escape the final rendered output.
13+
1014
## [1.5.1] - 2026-02-23
1115
### Fixed
1216
- **Double-Escaping in Product Dropdown**: Removed premature `esc_html()` calls in `get_products_for_dropdown()` that caused double-escaping when rendered. Escaping now occurs only at render time in `render_product_selection_field()`.

free-gift-bulk-coupon-generator.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,11 @@ public function add_admin_menu() {
117117
* Initialize admin functionality
118118
*/
119119
public function admin_init() {
120-
// Handle form submission nonce verified inside handle_coupon_generation().
120+
// Handle form submission with nonce verification.
121121
if ( isset( $_POST['scg_generate_coupons'] ) ) {
122+
if ( ! isset( $_POST['scg_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['scg_nonce'] ) ), 'scg_generate_coupons_action' ) ) {
123+
return;
124+
}
122125
$this->handle_coupon_generation();
123126
}
124127
}
@@ -243,10 +246,12 @@ function () {
243246
'admin_notices',
244247
function () use ( $generated_coupons ) {
245248
echo '<div class="notice notice-success is-dismissible"><p>' .
246-
sprintf(
247-
/* translators: %d: Number of coupons generated */
248-
esc_html__( 'Successfully generated %d coupons.', 'wc-free-gift-coupons-bulk-coupons-generator' ),
249-
(int) $generated_coupons
249+
esc_html(
250+
sprintf(
251+
/* translators: %d: Number of coupons generated */
252+
__( 'Successfully generated %d coupons.', 'wc-free-gift-coupons-bulk-coupons-generator' ),
253+
(int) $generated_coupons
254+
)
250255
) .
251256
'</p></div>';
252257
}

readme.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
108108

109109
== Changelog ==
110110

111+
= Unreleased =
112+
* **CSRF Fix**: Restored nonce verification in `admin_init()` before processing form data.
113+
* **XSS Fix**: Properly escaped `sprintf()` output in success notice.
114+
111115
= 1.5.1 =
112116
* **Double-Escaping Fix**: Fixed product names being double-escaped in the dropdown and success notices.
113117
* **Rate Limiting Fix**: Validation errors no longer lock users out for 5 minutes.

0 commit comments

Comments
 (0)