Skip to content

Commit 6509fa4

Browse files
authored
Merge pull request #386 from lloc/raise-coverage
Security fixes
2 parents 6dcea8b + 603ec7d commit 6509fa4

File tree

8 files changed

+21
-17
lines changed

8 files changed

+21
-17
lines changed

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
.idea/
2+
.phpunit.result.cache
3+
.phpunit.cache
14
composer.lock
25
composer.phar
6+
multisite-language-switcher/
7+
multisite-language-switcher.zip
38
package-lock.json
49
phpunit.xml.bak
5-
.idea/
6-
.phpunit.result.cache
7-
.phpunit.cache
810
tests/coverage/
911
tests/playwright-results/
1012
tests/playwright-report/

includes/Map/HrefLang.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class HrefLang {
1313

1414
/**
15-
* @var array<string, array<int, string>>
15+
* @var array<string, string>
1616
*/
1717
protected $map = array();
1818

includes/MslsCustomColumn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function td( $column_name, $item_id ): void {
9494
printf(
9595
'<span class="msls-icon-wrapper %1$s">%2$s</span>',
9696
esc_attr( $this->options->get_icon_type() ),
97-
$icon->get_a()
97+
wp_kses_post( $icon->get_a() )
9898
);
9999

100100
restore_current_blog();

includes/MslsOutput.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ public function get( ?int $display, bool $filter = false, $exists = false ): arr
9595
* @return string
9696
*/
9797
public function get_alternate_links() {
98-
$blogs = msls_blog_collection();
99-
$hreflang = new HrefLang( $blogs );
100-
$options = MslsOptions::create();
98+
$blogs = msls_blog_collection();
99+
$hlObj = new HrefLang( $blogs );
100+
$options = MslsOptions::create();
101101

102102
$arr = array();
103103
$default = '';
@@ -110,13 +110,14 @@ public function get_alternate_links() {
110110
}
111111

112112
$description = $blog->get_description();
113+
$hreflang = $hlObj->get( $blog->get_language() );
113114

114115
$format = '<link rel="alternate" hreflang="%s" href="%s" title="%s" />';
115116
if ( '' === $default ) {
116-
$default = sprintf( $format, 'x-default', $url, esc_attr( $description ) );
117+
$default = sprintf( $format, 'x-default', esc_url( $url ), esc_attr( $description ) );
117118
}
118119

119-
$arr[] = sprintf( $format, $hreflang->get( $blog->get_language() ), $url, esc_attr( $description ) );
120+
$arr[] = sprintf( $format, esc_attr( $hreflang ), esc_url( $url ), esc_attr( $description ) );
120121
}
121122

122123
if ( 1 === count( $arr ) ) {

includes/MslsPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function init_i18n_support(): void {
190190
*/
191191
public static function message_handler( $message, $css_class = 'error' ) {
192192
if ( ! empty( $message ) ) {
193-
printf( '<div id="msls-warning" class="%s"><p>%s</p></div>', $css_class, $message );
193+
printf( '<div id="msls-warning" class="%s"><p>%s</p></div>', esc_attr( $css_class ), esc_html( $message ) );
194194

195195
return true;
196196
}

includes/MslsPostTag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo
160160

161161
$this->maybe_set_linked_term( $mydata );
162162

163-
printf( $title_format, $this->get_select_title(), $type );
163+
printf( wp_kses_post( $title_format ), esc_html( $this->get_select_title() ), esc_attr( $type ) );
164164

165165
foreach ( $blogs as $blog ) {
166166
switch_to_blog( $blog->userblog_id );
@@ -179,7 +179,7 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo
179179
}
180180
}
181181

182-
printf( $item_format, $blog->userblog_id, $icon, $language, $value, $title );
182+
printf( wp_kses_post( $item_format ), esc_attr( $blog->userblog_id ), wp_kses_post( $icon ), esc_attr( $language ), esc_attr( $value ), esc_attr( $title ) );
183183

184184
restore_current_blog();
185185
}

includes/MslsPostTagClassic.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo
7777

7878
$this->maybe_set_linked_term( $mydata );
7979

80-
printf( $title_format, $this->get_select_title() );
80+
printf( wp_kses_post( $title_format ), esc_html( $this->get_select_title() ) );
8181

8282
foreach ( $blogs as $blog ) {
8383
$this->print_option( $blog, $type, $mydata, $item_format );
@@ -119,14 +119,14 @@ public function print_option( MslsBlog $blog, string $type, MslsOptionsTax $myda
119119
foreach ( $terms as $term ) {
120120
$options .= sprintf(
121121
'<option value="%s" %s>%s</option>',
122-
$term->term_id,
122+
esc_attr( $term->term_id ),
123123
selected( $term->term_id, $mydata->$language, false ),
124-
$term->name
124+
esc_html( $term->name )
125125
);
126126
}
127127
}
128128

129-
printf( $item_format, $language, $icon, $options );
129+
printf( wp_kses_post( $item_format ), esc_attr( $language ), wp_kses_post( $icon ), wp_kses_post( $options ) );
130130

131131
restore_current_blog();
132132
}

tests/phpunit/MslsUnitTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected function setUp(): void {
2626
Functions\when( 'esc_url' )->returnArg();
2727
Functions\when( '__' )->returnArg();
2828
Functions\when( 'wp_kses' )->returnArg();
29+
Functions\when( 'wp_kses_post' )->returnArg();
2930
Functions\when( 'sanitize_text_field' )->returnArg();
3031
}
3132

0 commit comments

Comments
 (0)