Skip to content

Commit c9ba020

Browse files
committed
Merge branch 'main' into poc-wpgraphql-logging-monolog
2 parents b93a7a2 + 8a9be18 commit c9ba020

File tree

15 files changed

+169
-53
lines changed

15 files changed

+169
-53
lines changed

.changeset/spotty-mice-behave.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@wpengine/wpgraphql-webhooks-wordpress-plugin": patch
3+
---
4+
5+
fix: security improvements for webhooks plugin
6+
7+
- Enhanced input validation and sanitization
8+
- Improved output escaping
9+
- Strengthened authorization checks
10+
- Added additional security hardening measures

plugins/composer-packages.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
{
22
"packages": {
33
"wpengine/hwp-previews": {
4+
"0.0.8": {
5+
"name": "wpengine/hwp-previews",
6+
"version": "0.0.8",
7+
"type": "wordpress-plugin",
8+
"description": "A WordPress plugin for headless previews.",
9+
"homepage": "https://github.com/wpengine/hwptoolkit",
10+
"license": "GPL-2.0",
11+
"authors": [
12+
{
13+
"name": "WP Engine Headless OSS Development Team",
14+
"email": "[email protected]",
15+
"homepage": "https://wpengine.com/"
16+
}
17+
],
18+
"support": {
19+
"issues": "https://github.com/wpengine/hwptoolkit/issues",
20+
"email": "[email protected]"
21+
},
22+
"dist": {
23+
"url": "https://github.com/wpengine/hwptoolkit/releases/download/%40wpengine%2Fhwp-previews-wordpress-plugin-0.0.8/hwp-previews.zip",
24+
"type": "zip"
25+
},
26+
"require": {
27+
"composer/installers": "~1.0 || ~2.0"
28+
}
29+
},
430
"0.0.7": {
531
"name": "wpengine/hwp-previews",
632
"version": "0.0.7",

plugins/hwp-previews/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# HWP Previews
22

3+
## 0.0.8
4+
5+
### Patch Changes
6+
7+
- [#333](https://github.com/wpengine/hwptoolkit/pull/333) [`cf0a040`](https://github.com/wpengine/hwptoolkit/commit/cf0a0405ae04e0355745a81bf53b3c9065f10739) Thanks [@ahuseyn](https://github.com/ahuseyn)! - 1. Disables Faust front-end redirects for preview url's to solve the iframe conflict. 2. Introduced methods in Faust_Integration to replace Faust-generated preview URLs with the site’s home URL as needed.
8+
39
## 0.0.7
410

511
### Patch Changes

plugins/hwp-previews/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "wordpress-plugin",
44
"description": "A WordPress plugin for headless previews.",
55
"license": "GPL-2.0",
6-
"version": "0.0.7",
6+
"version": "0.0.8",
77
"authors": [
88
{
99
"name": "WP Engine Headless OSS Development Team",

plugins/hwp-previews/hwp-previews.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Author: WPEngine Headless OSS Team
88
* Author URI: https://github.com/wpengine
99
* Update URI: https://github.com/wpengine/hwptoolkit
10-
* Version: 0.0.7
10+
* Version: 0.0.8
1111
* Text Domain: hwp-previews
1212
* Domain Path: /languages
1313
* Requires at least: 6.0
@@ -67,7 +67,7 @@ function hwp_previews_init(): void {
6767
*/
6868
function hwp_previews_constants(): void {
6969
if ( ! defined( 'HWP_PREVIEWS_VERSION' ) ) {
70-
define( 'HWP_PREVIEWS_VERSION', '0.0.7' );
70+
define( 'HWP_PREVIEWS_VERSION', '0.0.8' );
7171
}
7272

7373
if ( ! defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) {

plugins/hwp-previews/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wpengine/hwp-previews-wordpress-plugin",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"private": true,
55
"description": "Headless Previews solution for WordPress: fully configurable preview URLs via the settings page.",
66
"scripts": {

plugins/hwp-previews/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: GraphQL, Headless, Previews, WPGraphQL, React, Rest
44
Requires at least: 6.0
55
Tested up to: 6.8.1
66
Requires PHP: 7.4
7-
Stable tag: 0.0.7
7+
Stable tag: 0.0.8
88
License: GPL-2.0
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010

plugins/hwp-previews/src/Hooks/Preview_Hooks.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace HWP\Previews\Hooks;
66

77
use HWP\Previews\Admin\Settings\Fields\Settings_Field_Collection;
8+
use HWP\Previews\Integration\Faust_Integration;
89
use HWP\Previews\Preview\Parameter\Preview_Parameter_Registry;
910
use HWP\Previews\Preview\Post\Post_Editor_Service;
1011
use HWP\Previews\Preview\Post\Post_Preview_Service;
@@ -226,6 +227,13 @@ public function update_preview_post_link( string $preview_link, WP_Post $post ):
226227

227228
// If the iframe option is enabled, we need to resolve preview on the template redirect level.
228229
if ( $post_type_service->is_iframe() ) {
230+
$faust_helper = new Faust_Integration();
231+
232+
// If Faust post & category rewrites enabled, we should revert the preview link rewrites.
233+
if ( $faust_helper->is_faust_rewrites_enabled() ) {
234+
return $faust_helper->replace_faust_preview_rewrite( $preview_link );
235+
}
236+
229237
return $preview_link;
230238
}
231239

plugins/hwp-previews/src/Integration/Faust_Integration.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,41 @@ public function register_faust_admin_notice(): void {
181181
}, 10, 0 );
182182
}
183183

184+
/**
185+
* Check if Faust rewrites are enabled.
186+
*/
187+
public function is_faust_rewrites_enabled(): bool {
188+
if ( $this->get_faust_enabled() && function_exists( '\WPE\FaustWP\Settings\is_rewrites_enabled' ) ) {
189+
return (bool) \WPE\FaustWP\Settings\is_rewrites_enabled();
190+
}
191+
192+
return false;
193+
}
194+
195+
/**
196+
* Replace Faust preview rewrites with the home URL.
197+
*
198+
* @param string $url The URL to be rewritten.
199+
*/
200+
public function replace_faust_preview_rewrite($url): string {
201+
if ( ! function_exists( '\WPE\FaustWP\Settings\faustwp_get_setting' ) ) {
202+
return $url;
203+
}
204+
205+
$frontend_uri = \WPE\FaustWP\Settings\faustwp_get_setting( 'frontend_uri' );
206+
207+
// Return the URL as is if frontend uri is empty.
208+
if ( ! $frontend_uri ) {
209+
return $url;
210+
}
211+
212+
$frontend_uri = trailingslashit( $frontend_uri );
213+
$home_url = trailingslashit( get_home_url() );
214+
215+
216+
return str_replace( $frontend_uri, $home_url, $url );
217+
}
218+
184219
/**
185220
* Dismiss the Faust admin notice.
186221
*/
@@ -202,9 +237,26 @@ protected function configure_faust(): void {
202237
// Remove FaustWP post preview link filter to avoid conflicts with our custom preview link generation.
203238
remove_filter( 'preview_post_link', 'WPE\FaustWP\Replacement\post_preview_link', 1000 );
204239

240+
// Prevent Faust from redirecting preview URLs to the frontend in iframe mode.
241+
$this->disable_faust_redirects();
242+
205243
$this->display_faust_admin_notice();
206244
}
207245

246+
/**
247+
* Disable Faust's redirect functionality for preview URLs.
248+
*/
249+
protected function disable_faust_redirects(): void {
250+
add_action( 'template_redirect', static function (): void {
251+
// Only run for preview URLs (e.g., ?p=ID&preview=true).
252+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification not required for disabling front-end redirects.
253+
if ( isset( $_GET['preview'] ) && 'true' === $_GET['preview'] ) {
254+
// Remove Faust's redirect callback.
255+
remove_action( 'template_redirect', 'WPE\FaustWP\Deny_Public_Access\deny_public_access', 99 );
256+
}
257+
}, 10, 0 );
258+
}
259+
208260
/**
209261
* If Faust is enabled, show an admin notice about the migration on the settings page.
210262
*/

plugins/wp-graphql-webhooks/src/Admin/WebhooksAdmin.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private function verify_admin_permission(): bool {
168168
* @return bool True if nonce is valid, false otherwise.
169169
*/
170170
private function verify_nonce( string $nonce_name, string $action ): bool {
171-
if ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $action ) ) {
171+
if ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( wp_unslash( $_REQUEST[ $nonce_name ] ), $action ) ) {
172172
wp_die( __( 'Security check failed.', 'wp-graphql-webhooks' ) );
173173
return false;
174174
}
@@ -185,11 +185,6 @@ public function handle_webhook_save() {
185185
wp_die( __( 'Unauthorized', 'wp-graphql-webhooks' ) );
186186
}
187187

188-
$webhook_id = isset( $_POST['webhook_id'] ) ? intval( $_POST['webhook_id'] ) : 0;
189-
if ( ! $this->verify_admin_permission() || ! $this->verify_nonce( 'webhook_nonce', 'webhook_save' ) ) {
190-
wp_die( __( 'Unauthorized', 'wp-graphql-webhooks' ) );
191-
}
192-
193188
$webhook_id = isset( $_POST['webhook_id'] ) ? intval( $_POST['webhook_id'] ) : 0;
194189
$webhook = new Webhook(
195190
$webhook_id,
@@ -375,7 +370,7 @@ public function ajax_test_webhook(): void {
375370
] );
376371
}
377372

378-
if ( ! current_user_can( 'manage_options' ) ) {
373+
if ( ! $this->verify_admin_permission() ) {
379374
wp_send_json_error( [
380375
'message' => __( 'You do not have permission to test webhooks.', 'wp-graphql-webhooks' ),
381376
'error_code' => 'insufficient_permissions'

0 commit comments

Comments
 (0)