-
Notifications
You must be signed in to change notification settings - Fork 151
Security: Fix capability checks & shortcode exec vuln #1711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sapayth
merged 6 commits into
weDevsOfficial:develop
from
arifulhoque7:security/fix-capability-checks-and-shortcode-execution
Oct 7, 2025
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ea20022
Security: Fix capability checks & shortcode exec vuln
arifulhoque7 95e08fb
fix: patchstack vulnaribility ?
arifulhoque7 8cd0596
code rabbit code issues
arifulhoque7 27ed3e4
fix: patchstack issues
arifulhoque7 b0e6aec
Security: Add strip_shortcodes() to all custom fields to prevent ille…
arifulhoque7 efcafde
fix: sanitize_text_field added
arifulhoque7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,19 +29,26 @@ | |
| private $form_id; | ||
|
|
||
| /** | ||
| * is_preview | ||
| * | ||
| * @var string | ||
| */ | ||
| private $is_preview = true; | ||
|
|
||
| public function __construct() { | ||
| if ( ! isset( $_GET['wpuf_preview'] ) && empty( $_GET['wpuf'] ) ) { | ||
|
Check warning on line 39 in includes/Frontend/Form_Preview.php
|
||
| return; | ||
| } | ||
| $this->form_id = isset( $_GET['form_id'] ) ? intval( $_GET['form_id'] ) : 0; | ||
|
|
||
| // Security: Check user has proper capabilities before allowing preview | ||
| if ( ! is_user_logged_in() || ! current_user_can( wpuf_admin_role() ) ) { | ||
| wp_die( __( 'You do not have permission to preview this form.', 'wp-user-frontend' ), 403 ); | ||
| } | ||
|
|
||
| // Security: Validate and sanitize form_id parameter | ||
| $this->form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0; | ||
|
Check warning on line 49 in includes/Frontend/Form_Preview.php
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. recheck nonce verification |
||
| add_action( 'pre_get_posts', [ $this, 'pre_get_posts' ] ); | ||
| // add_filter( 'template_include', [ $this, 'template_include' ] ); | ||
| add_filter( 'the_title', [ $this, 'the_title' ] ); | ||
| add_filter( 'the_content', [ $this, 'the_content' ] ); | ||
| add_filter( 'get_the_excerpt', [ $this, 'the_content' ] ); | ||
|
|
@@ -76,19 +83,19 @@ | |
| * | ||
| * @return string | ||
| */ | ||
| public function the_content( $content ) { | ||
| if ( $this->is_preview ) { | ||
| if ( ! is_user_logged_in() ) { | ||
| return __( 'You must be logged in to preview this form.', 'wp-user-frontend' ); | ||
| } | ||
| $viewing_capability = apply_filters( 'wpuf_preview_form_cap', | ||
| 'edit_posts' ); // at least has to be contributor | ||
| if ( ! current_user_can( $viewing_capability ) ) { | ||
| return __( 'Sorry, you are not eligible to preview this form.', 'wp-user-frontend' ); | ||
| } | ||
| // Security: Double-check admin capabilities | ||
| if ( ! current_user_can( wpuf_admin_role() ) ) { | ||
| return __( 'You do not have permission to preview this form.', 'wp-user-frontend' ); | ||
| } | ||
|
|
||
| // Security: Validate form_id is a valid integer to prevent injection | ||
| $form_id = absint( $this->form_id ); | ||
| if ( $form_id === 0 ) { | ||
| return __( 'Invalid form ID.', 'wp-user-frontend' ); | ||
| } | ||
|
|
||
| return do_shortcode( sprintf( '[wpuf_form id="%d"]', $this->form_id ) ); | ||
| return do_shortcode( sprintf( '[wpuf_form id="%d"]', $form_id ) ); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard
strip_shortcodes()against array inputssanitize_field_data()is invoked fromFieldableTrait::prepare_meta_fields()for every field exposing that method, regardless of whether the submitted value is scalar or an array. It’s easy to end up with textarea data posted as an array (e.g.,field[], repeatable rows, multi-language variants). With the new code we now hand that array directly tostrip_shortcodes(), which throws a fatalTypeErroron PHP 8+, whereas the previous implementation handled arrays gracefully. Please make sure the shortcode stripping only runs on scalar values and recurse when needed. For example:public function sanitize_field_data( $data, $field ) { - return strip_shortcodes( wp_kses_post( $data ) ); + $sanitized = wp_kses_post( $data ); + + if ( is_array( $sanitized ) ) { + return array_map( + static function ( $value ) { + return is_string( $value ) ? strip_shortcodes( $value ) : $value; + }, + $sanitized + ); + } + + return strip_shortcodes( $sanitized ); }📝 Committable suggestion
🧰 Tools
🪛 PHPMD (2.15.0)
208-208: Avoid unused parameters such as '$field'. (undefined)
(UnusedFormalParameter)
🤖 Prompt for AI Agents