Skip to content

Commit 82c3b37

Browse files
authored
Merge pull request #696 from Automattic/revert-693-downgrade_htmlAttrNotByEscHTML
Revert "Downgrade htmlAttrNotByEscHTML to a warning"
2 parents 475870e + e09c47a commit 82c3b37

File tree

8 files changed

+25
-22
lines changed

8 files changed

+25
-22
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>'; // Warning.
256+
echo '<a title="' . esc_html( $some_var ) . '"></a>'; // Error.
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> <!-- Warning. -->
259+
<a href="" class="<?php echo esc_html( $some_var); ?>">Hey</a> <!-- Error. -->
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,7 +27,9 @@
2727
188 => 1,
2828
252 => 1,
2929
255 => 1,
30+
256 => 1,
3031
258 => 1,
32+
259 => 1,
3133
318 => 1,
3234
329 => 1,
3335
334 => 1,
@@ -191,8 +193,6 @@
191193
245 => 1,
192194
246 => 1,
193195
247 => 1,
194-
256 => 1,
195-
259 => 1,
196196
265 => 1,
197197
269 => 1,
198198
273 => 1,

WordPress-VIP-Go/ruleset.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@
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>
232236
<rule ref="WordPressVIPMinimum.Functions.RestrictedFunctions.is_multi_author_is_multi_author">
233237
<severity>1</severity>
234238
</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->addWarning( $message, $stackPtr, 'htmlAttrNotByEscHTML', $data );
209-
return; // Warning level because sub-optimal due to different filters, but still OK.
208+
$this->phpcsFile->addError( $message, $stackPtr, 'htmlAttrNotByEscHTML', $data );
209+
return;
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>'; // Warning.
15+
echo '<a title="' . esc_html_x( $some_var ) . '"></a>'; // Error.
1616

17-
echo "<a title='" . \esc_html( $some_var ) . "'></a>"; // Warning.
17+
echo "<a title='" . \esc_html( $some_var ) . "'></a>"; // Error.
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> <!-- Warning. -->
23+
<a href="" class="<?php esc_html_e( $some_var); ?>">Hey</a> <!-- Error. -->
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) . '\'>'; // Warning.
75-
echo "<div class=\"" . \esc_html__($class) . '">'; // Warning.
76-
echo "<div $someAttribute class=\"" . esc_html($class) . '">'; // Warning.
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.
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: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ public function getErrorList() {
2727
return [
2828
3 => 1,
2929
5 => 1,
30+
15 => 1,
31+
17 => 1,
3032
21 => 1,
33+
23 => 1,
3134
33 => 1,
3235
37 => 1,
3336
41 => 1,
@@ -42,6 +45,9 @@ public function getErrorList() {
4245
69 => 1,
4346
72 => 1,
4447
73 => 1,
48+
74 => 1,
49+
75 => 1,
50+
76 => 1,
4551
77 => 1,
4652
78 => 1,
4753
79 => 1,
@@ -60,14 +66,7 @@ public function getErrorList() {
6066
* @return array <int line number> => <int number of warnings>
6167
*/
6268
public function getWarningList() {
63-
return [
64-
15 => 1,
65-
17 => 1,
66-
23 => 1,
67-
74 => 1,
68-
75 => 1,
69-
76 => 1,
70-
];
69+
return [];
7170
}
7271

7372
}

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>'; // Warning.
551+
echo '<a title="' . esc_html( $some_var ) . '"></a>'; // Error.
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,6 +179,7 @@
179179
523 => 1,
180180
525 => 1,
181181
550 => 1,
182+
551 => 1,
182183
554 => 1,
183184
569 => 1,
184185
570 => 1,
@@ -289,7 +290,6 @@
289290
535 => 1,
290291
538 => 1,
291292
545 => 1,
292-
551 => 1,
293293
559 => 1,
294294
565 => 1,
295295
589 => 1,

0 commit comments

Comments
 (0)