Skip to content

Commit c3a80f0

Browse files
committed
Downgrade WordPressVIPMinimum.Security.ProperEscapingFunction.htmlAttrNotByEscHTML to warning
1 parent e1eb7c9 commit c3a80f0

File tree

8 files changed

+22
-25
lines changed

8 files changed

+22
-25
lines changed

WordPress-VIP-Go/ruleset-test.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ $test = @in_array( $array, $needle, true ); // Error.
253253

254254
// WordPressVIPMinimum.Security.ProperEscapingFunction.htmlAttrNotByEscHTML
255255
echo '<a href="' . esc_attr( $some_var ) . '"></a>'; // Error.
256-
echo '<a title="' . esc_html( $some_var ) . '"></a>'; // Error.
256+
echo '<a title="' . esc_html( $some_var ) . '"></a>'; // Warning.
257257
echo '<a href="' . esc_url( $some_var ) . '"></a>'; // OK.
258258
?><a href="<?php echo esc_attr( $some_var ); ?>">Hello</a> <!-- Error. -->
259-
<a href="" class="<?php echo esc_html( $some_var); ?>">Hey</a> <!-- Error. -->
259+
<a href="" class="<?php echo esc_html( $some_var); ?>">Hey</a> <!-- Warning. -->
260260
<a href="<?php esc_url( $url );?>"></a> <!-- Ok. -->
261261
<a title="<?php esc_attr( $url );?>"></a> <?php // Ok.
262262

WordPress-VIP-Go/ruleset-test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
188 => 1,
2828
252 => 1,
2929
255 => 1,
30-
256 => 1,
3130
258 => 1,
32-
259 => 1,
3331
318 => 1,
3432
329 => 1,
3533
334 => 1,
@@ -193,6 +191,8 @@
193191
245 => 1,
194192
246 => 1,
195193
247 => 1,
194+
256 => 1,
195+
259 => 1,
196196
265 => 1,
197197
269 => 1,
198198
273 => 1,

WordPress-VIP-Go/ruleset.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,6 @@
229229
<rule ref="Generic.PHP.NoSilencedErrors">
230230
<severity>1</severity>
231231
</rule>
232-
<rule ref="WordPressVIPMinimum.Security.ProperEscapingFunction.htmlAttrNotByEscHTML">
233-
<!-- This is still safe, just sub-optimal-->
234-
<severity>3</severity>
235-
</rule>
236232
<rule ref="WordPressVIPMinimum.Functions.RestrictedFunctions.is_multi_author_is_multi_author">
237233
<severity>1</severity>
238234
</rule>

WordPressVIPMinimum/Sniffs/Security/ProperEscapingFunctionSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ public function process_token( $stackPtr ) {
205205

206206
if ( $escaping_type === 'html' ) {
207207
$message = 'Wrong escaping function. HTML attributes should be escaped by `esc_attr()`, not by `%s()`.';
208-
$this->phpcsFile->addError( $message, $stackPtr, 'htmlAttrNotByEscHTML', $data );
209-
return;
208+
$this->phpcsFile->addWarning( $message, $stackPtr, 'htmlAttrNotByEscHTML', $data );
209+
return; // Warning level because sub-optimal due to different filters, but still OK.
210210
}
211211
}
212212

WordPressVIPMinimum/Tests/Security/ProperEscapingFunctionUnitTest.inc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ echo '<a title="' . esc_attr( $some_var ) . '"></a>'; // OK.
1212

1313
echo "<a title='" . \esc_attr( $some_var ) . "'></a>"; // OK.
1414

15-
echo '<a title="' . esc_html_x( $some_var ) . '"></a>'; // Error.
15+
echo '<a title="' . esc_html_x( $some_var ) . '"></a>'; // Warning.
1616

17-
echo "<a title='" . \esc_html( $some_var ) . "'></a>"; // Error.
17+
echo "<a title='" . \esc_html( $some_var ) . "'></a>"; // Warning.
1818

1919
?>
2020

2121
<a href="<?php echo esc_attr( $some_var ); ?>">Hello</a> <!-- Error. -->
2222

23-
<a href="" class="<?php esc_html_e( $some_var); ?>">Hey</a> <!-- Error. -->
23+
<a href="" class="<?php esc_html_e( $some_var); ?>">Hey</a> <!-- Warning. -->
2424

2525
<a href="<?php esc_url( $url );?>"></a> <!-- OK. -->
2626

@@ -71,9 +71,9 @@ echo "<$tag> " , esc_attr( $test ) , "</$tag>"; // Error.
7171
<?php echo "<div>" . $test . "</div>"; // OK.
7272
echo "<{$tag}>" . esc_attr( $tag_content ) . "</{$tag}>"; // Error.
7373
echo "<$tag" . ' >' . esc_attr( $tag_content ) . "</$tag>"; // Error.
74-
echo '<div class=\'' . esc_html($class) . '\'>'; // Error.
75-
echo "<div class=\"" . \esc_html__($class) . '">'; // Error.
76-
echo "<div $someAttribute class=\"" . esc_html($class) . '">'; // Error.
74+
echo '<div class=\'' . esc_html($class) . '\'>'; // Warning.
75+
echo "<div class=\"" . \esc_html__($class) . '">'; // Warning.
76+
echo "<div $someAttribute class=\"" . esc_html($class) . '">'; // Warning.
7777
echo '<a href=\'' . esc_html($url) . '\'>'; // Error.
7878
echo "<img src=\"" . esc_html($src) . '"/>'; // Error.
7979
echo "<div $someAttributeName-url=\"" . esc_html($url) . '">'; // Error.

WordPressVIPMinimum/Tests/Security/ProperEscapingFunctionUnitTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ public function getErrorList() {
2727
return [
2828
3 => 1,
2929
5 => 1,
30-
15 => 1,
31-
17 => 1,
3230
21 => 1,
33-
23 => 1,
3431
33 => 1,
3532
37 => 1,
3633
41 => 1,
@@ -45,9 +42,6 @@ public function getErrorList() {
4542
69 => 1,
4643
72 => 1,
4744
73 => 1,
48-
74 => 1,
49-
75 => 1,
50-
76 => 1,
5145
77 => 1,
5246
78 => 1,
5347
79 => 1,
@@ -66,7 +60,14 @@ public function getErrorList() {
6660
* @return array <int line number> => <int number of warnings>
6761
*/
6862
public function getWarningList() {
69-
return [];
63+
return [
64+
15 => 1,
65+
17 => 1,
66+
23 => 1,
67+
74 => 1,
68+
75 => 1,
69+
76 => 1,
70+
];
7071
}
7172

7273
}

WordPressVIPMinimum/ruleset-test.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ echo '<a href="{{href}}">{{{data}}}</div></a>'; // Warning.
548548

549549
// WordPressVIPMinimum.Security.ProperEscapingFunction
550550
echo '<a href="' . esc_attr( $some_var ) . '"></a>'; // Error.
551-
echo '<a title="' . esc_html( $some_var ) . '"></a>'; // Error.
551+
echo '<a title="' . esc_html( $some_var ) . '"></a>'; // Warning.
552552

553553
// WordPressVIPMinimum.Security.StaticStrreplace
554554
str_replace( 'foo', array( 'bar', 'foo' ), 'foobar' ); // Error.

WordPressVIPMinimum/ruleset-test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@
179179
523 => 1,
180180
525 => 1,
181181
550 => 1,
182-
551 => 1,
183182
554 => 1,
184183
569 => 1,
185184
570 => 1,
@@ -290,6 +289,7 @@
290289
535 => 1,
291290
538 => 1,
292291
545 => 1,
292+
551 => 1,
293293
559 => 1,
294294
565 => 1,
295295
589 => 1,

0 commit comments

Comments
 (0)