-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
validate postId in the site-editor.php #7188
base: trunk
Are you sure you want to change the base?
Changes from 9 commits
4683dbe
038bead
84c3c8a
bb0bb39
8fd4278
a7b6460
32b11c0
a0b8164
fbcd239
ff15ab1
64e135c
25ecd75
39669ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,11 @@ | |
); | ||
} | ||
|
||
$is_template_part = isset( $_GET['postType'] ) && 'wp_template_part' === sanitize_key( $_GET['postType'] ); | ||
$post_type_param = isset( $_GET['postType'] ) ? sanitize_key( wp_unslash( $_GET['postType'] ) ) : ''; | ||
$is_template_part = $post_type_param && 'wp_template_part' === $post_type_param; | ||
$is_template_part_path = isset( $_GET['path'] ) && 'wp_template_partall' === sanitize_key( $_GET['path'] ); | ||
$is_template_part_editor = $is_template_part || $is_template_part_path; | ||
$is_patterns = isset( $_GET['postType'] ) && 'wp_block' === sanitize_key( $_GET['postType'] ); | ||
$is_patterns = $post_type_param && 'wp_block' === $post_type_param; | ||
$is_patterns_path = isset( $_GET['path'] ) && 'patterns' === sanitize_key( $_GET['path'] ); | ||
$is_patterns_editor = $is_patterns || $is_patterns_path; | ||
|
||
|
@@ -34,6 +35,43 @@ | |
} | ||
} | ||
|
||
// Validate postId and postType. | ||
if ( isset( $_GET['postId'] ) && $post_type_param ) { | ||
switch ( $post_type_param ) { | ||
case 'page': | ||
$post = get_post( (int) $_GET['postId'] ); | ||
|
||
if ( null === $post || 'page' !== get_post_type( $post ) ) { | ||
wp_die( __( 'Invalid page ID.' ) ); | ||
} | ||
break; | ||
|
||
case 'wp_block': | ||
$post = get_post( (int) $_GET['postId'] ); | ||
|
||
if ( null === $post || 'wp_block' !== get_post_type( $post ) ) { | ||
wp_die( __( 'Invalid pattern ID.' ) ); | ||
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. Same here, but maybe should link to the Patterns page. 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. Resolved 64e135c |
||
} | ||
break; | ||
|
||
case 'wp_template': | ||
$block_template = get_block_template( $_GET['postId'] ); | ||
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. Noting that 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. This has been fixed |
||
|
||
if ( null === $block_template ) { | ||
wp_die( __( 'Invalid template ID.' ) ); | ||
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. Same here, but maybe should link to the Templates page. 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. Resolved 25ecd75 |
||
} | ||
break; | ||
|
||
case 'wp_template_part': | ||
$block_template = get_block_template( $_GET['postId'], 'wp_template_part' ); | ||
|
||
if ( null === $block_template ) { | ||
wp_die( __( 'Invalid template part ID.' ) ); | ||
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. Same here, but maybe should link to the Templates page. 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. Resolved 39669ab |
||
} | ||
break; | ||
} | ||
} | ||
|
||
// Used in the HTML title tag. | ||
$title = _x( 'Editor', 'site editor title tag' ); | ||
$parent_file = 'themes.php'; | ||
|
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.
To help with the user's experience, please add the following as suggested by @peterwilsoncc :
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.
Resolved ff15ab1