Skip to content

Commit cd2d4fe

Browse files
committed
Safer vars
1 parent d0e8a44 commit cd2d4fe

File tree

6 files changed

+27
-13
lines changed

6 files changed

+27
-13
lines changed

MultisiteLanguageSwitcher.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ function get_the_msls( $attr ): string {
7676
* @param string[] $arr
7777
*/
7878
function the_msls( array $arr = array() ): void {
79+
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
7980
echo get_the_msls( $arr );
8081
}
8182

includes/ContentImport/ContentImporter.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use lloc\Msls\MslsMain;
1010
use lloc\Msls\MslsOptionsPost;
1111
use lloc\Msls\MslsRegistryInstance;
12+
use lloc\Msls\MslsRequest;
1213

1314
/**
1415
* Class ContentImporter
@@ -166,11 +167,12 @@ protected function pre_flight_check( array $data = array() ) {
166167
* @return array|bool
167168
*/
168169
public function parse_sources() {
169-
if ( ! isset( $_POST['msls_import'] ) ) {
170+
if ( ! MslsRequest::has_var( 'msls_import' ) ) {
170171
return false;
171172
}
172173

173-
$import_data = array_filter( explode( '|', trim( $_POST['msls_import'] ) ), 'is_numeric' );
174+
$msls_import = MslsRequest::get_var( 'msls_import' );
175+
$import_data = array_filter( explode( '|', trim( $msls_import ) ), 'is_numeric' );
174176

175177
if ( count( $import_data ) !== 2 ) {
176178
return false;
@@ -195,8 +197,9 @@ protected function get_the_blog_post_ID( $blog_id ) {
195197
return $id;
196198
}
197199

198-
if ( isset( $_REQUEST['post'] ) && filter_var( $_REQUEST['post'], FILTER_VALIDATE_INT ) ) {
199-
return (int) $_REQUEST['post'];
200+
$request = MslsRequest::get_request( array( 'post' ) );
201+
if ( ! empty( $request['post'] ) ) {
202+
return (int) $request['post'];
200203
}
201204

202205
$data = array(

includes/ContentImport/Importers/WithRequestPostAttributes.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace lloc\Msls\ContentImport\Importers;
1212

13+
use lloc\Msls\MslsRequest;
14+
1315
/**
1416
* Trait WithRequestPostAttributes
1517
*
@@ -24,14 +26,11 @@ trait WithRequestPostAttributes {
2426
* @param string $default The default post type to return if none is specified in the `$_REQUEST` super-global.
2527
*
2628
* @return string Either the post type read from the `$_REQUEST` super-global, or the default value.
27-
* @since TBD
28-
*
29+
\ *
2930
*/
3031
protected function read_post_type_from_request( $default = 'post' ) {
31-
if ( ! isset( $_REQUEST['post_type'] ) ) {
32-
return $default;
33-
}
32+
$request = MslsRequest::get_request( array( 'post_type' ), $default );
3433

35-
return filter_var( $_REQUEST['post_type'], FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ?: 'post';
34+
return $request['post_type'];
3635
}
3736
}

includes/ContentImport/MetaBox.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ protected function inline_thickbox_html( $echo = true, array $data = array() ):
121121
?>
122122
<div style="display: none;" id="msls-import-dialog-<?php echo esc_attr( $slug ); ?>">
123123
<h3><?php esc_html_e( 'Select what should be imported and how', 'multisite-language-switcher' ); ?></h3>
124-
<form action="<?php echo add_query_arg( array() ); ?>" method="post">
124+
<form action="<?php echo esc_url( add_query_arg( array() ) ); ?>" method="post">
125125
<?php wp_nonce_field( MslsPlugin::path(), 'msls_noncename' ); ?>
126126
<?php foreach ( $data as $key => $value ) : ?>
127127
<input type="hidden" name="<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $value ); ?>">
@@ -172,7 +172,7 @@ protected function inline_thickbox_html( $echo = true, array $data = array() ):
172172
$html = ob_get_clean();
173173

174174
if ( $echo ) {
175-
echo $html;
175+
echo wp_kses_post( $html );
176176
}
177177

178178
return $html;

includes/MslsFields.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class MslsFields {
1313
const FIELD_MSLS_NONCENAME = 'msls_noncename';
1414
const FIELD_MSLS_ID = 'msls_id';
1515
const FIELD_MSLS_LANG = 'msls_lang';
16+
const FIELD_MSLS_IMPORT = 'msls_import';
17+
const FIELD_POST = 'post';
1618

1719
const CONFIG = array(
1820
self::FIELD_BLOG_ID => array(
@@ -51,5 +53,13 @@ class MslsFields {
5153
INPUT_GET,
5254
FILTER_SANITIZE_FULL_SPECIAL_CHARS,
5355
),
56+
self::FIELD_MSLS_IMPORT => array(
57+
INPUT_POST,
58+
FILTER_SANITIZE_FULL_SPECIAL_CHARS,
59+
),
60+
self::FIELD_POST => array(
61+
INPUT_GET,
62+
FILTER_SANITIZE_NUMBER_INT,
63+
),
5464
);
5565
}

includes/MslsMetaBox.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ public function render_select(): void {
222222
restore_current_blog();
223223
}
224224

225-
printf( '<ul>%s</ul>', $lis );
225+
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
226+
echo ( new Wrapper( 'ul', $lis ) )->render();
226227

227228
$post = $temp;
228229
} else {

0 commit comments

Comments
 (0)