Skip to content
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

Enable ValidatedSanitizedInput rule in plugin review check #583

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions phpcs-rulesets/plugin-review.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
<type>warning</type>
</rule>

<!-- Sanitized Input rules -->
<rule ref="WordPress.Security.ValidatedSanitizedInput">
<type>error</type>
<severity>7</severity>
</rule>
swissspidy marked this conversation as resolved.
Show resolved Hide resolved

<!-- Prohibit the use of the backtick operator. -->
<rule ref="Generic.PHP.BacktickOperator"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
ob_start();
the_author_email();
$the_author_email = ob_get_clean();

$var_post_not_sanitized = $_POST['not_sanitized'];
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
ob_start();
the_author_meta( 'email');
$the_author_email = ob_get_clean();

$var_sanitized = isset( $data['sanitized'] ) ? sanitize_text_field( wp_unslash( $data['sanitized'] ) ) : '';
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function test_run_with_errors() {

$this->assertNotEmpty( $errors );
$this->assertArrayHasKey( 'load.php', $errors );
$this->assertEquals( 2, $check_result->get_error_count() );
$this->assertEquals( 5, $check_result->get_error_count() );
davidperezgar marked this conversation as resolved.
Show resolved Hide resolved

// Check for Generic.PHP.DisallowShortOpenTag.Found error on Line no 6 and column no at 1.
$this->assertArrayHasKey( 6, $errors['load.php'] );
Expand All @@ -35,6 +35,12 @@ public function test_run_with_errors() {
$this->assertArrayHasKey( 5, $errors['load.php'][12] );
$this->assertArrayHasKey( 'code', $errors['load.php'][12][5][0] );
$this->assertEquals( 'WordPress.WP.DeprecatedFunctions.the_author_emailFound', $errors['load.php'][12][5][0]['code'] );

// Check for WordPress.Security.ValidatedSanitizedInput.InputNotValidated error on Line no 15 and column no at 27.
$this->assertArrayHasKey( 15, $errors['load.php'] );
$this->assertArrayHasKey( 27, $errors['load.php'][15] );
$this->assertArrayHasKey( 'code', $errors['load.php'][15][27][0] );
$this->assertEquals( 'WordPress.Security.ValidatedSanitizedInput.InputNotValidated', $errors['load.php'][15][27][0]['code'] );
}

public function test_run_without_errors() {
Expand Down