Skip to content

Commit

Permalink
Functions/RestrictedFunctions: remove reference to function which doe…
Browse files Browse the repository at this point in the history
…sn't exist

PHP does not contain a `delete()` function, so searching for it will only yield false positives.

Ref: https://www.php.net/manual/en/function.delete.php
  • Loading branch information
jrfnl committed Aug 22, 2023
1 parent df070e7 commit 756b1a5
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 9 deletions.
6 changes: 3 additions & 3 deletions WordPress-VIP-Go/ruleset-test.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
$file = ''; $fp = ''; $dir = ''; $test = ''; $bar = ''; $array = []; $query_args = []; $url = ''; $query = ''; $page_title = ''; $true = true; $some_nasty_var = ''; $data = ''; $group = ''; $testing = ''; $needle = ''; $some_var = ''; $blogid = 1; $text = ''; $category_id = 123; $foo = ''; $bar = ''; $var = ''; $wp_rewrite = ''; $count = 1; $loop = 1; $a = ''; $b = ''; $obj = ''; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- All set for VariableAnalysis checks.
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_delete
delete( $file ); // Warning + Message.
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink
unlink( $file ); // Warning + Message.

// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_file_put_contents
file_put_contents( 'file.txt', '', FILE_APPEND ); // Warning + Message.
Expand Down Expand Up @@ -388,7 +388,7 @@ session_status(); // Error.
session_unregister(); // Error.
session_unset(); // Error.
session_write_close(); // Error.
delete(); // Warning.
unlink(); // Warning.
file_put_contents( $file, $text, FILE_APPEND ); // Warning.
while ( $count > $loop ) {
if ( flock( $fp, LOCK_EX ) ) { // Warning.
Expand Down
2 changes: 1 addition & 1 deletion WordPress-VIP-Go/ruleset-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
],
'messages' => [
4 => [
'File system operations only work on the `/tmp/` and `wp-content/uploads/` directories. To avoid unexpected results, please use helper functions like `get_temp_dir()` or `wp_get_upload_dir()` to get the proper directory path when using functions such as delete(). For more details, please see: https://docs.wpvip.com/technical-references/vip-go-files-system/local-file-operations/',
'File system operations only work on the `/tmp/` and `wp-content/uploads/` directories. To avoid unexpected results, please use helper functions like `get_temp_dir()` or `wp_get_upload_dir()` to get the proper directory path when using functions such as unlink(). For more details, please see: https://docs.wpvip.com/technical-references/vip-go-files-system/local-file-operations/',
],
7 => [
'File system operations only work on the `/tmp/` and `wp-content/uploads/` directories. To avoid unexpected results, please use helper functions like `get_temp_dir()` or `wp_get_upload_dir()` to get the proper directory path when using functions such as file_put_contents(). For more details, please see: https://docs.wpvip.com/technical-references/vip-go-files-system/local-file-operations/',
Expand Down
2 changes: 1 addition & 1 deletion WordPress-VIP-Go/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<rule ref="WordPressVIPMinimum"/>

<!-- Things that may be incompatible with the VIP Go infrastructure and needs a dev to review -->
<rule ref="WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_delete">
<rule ref="WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink">
<type>warning</type>
<severity>6</severity>
<message>File system operations only work on the `/tmp/` and `wp-content/uploads/` directories. To avoid unexpected results, please use helper functions like `get_temp_dir()` or `wp_get_upload_dir()` to get the proper directory path when using functions such as %s(). For more details, please see: https://docs.wpvip.com/technical-references/vip-go-files-system/local-file-operations/</message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ public function getGroups() {
'type' => 'error',
'message' => 'Filesystem writes are forbidden, please do not use %s().',
'functions' => [
'delete',
'file_put_contents',
'flock',
'fputcsv',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ while ( $count > $loop ) {

fclose( $fp ); // Ok.

delete(); // Error.

fputcsv(); // Error.
fputs(); // Error.
ftruncate(); // Error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public function getErrorList() {
174 => 1,
175 => 1,
177 => 1,
182 => 1,
183 => 1,
184 => 1,
185 => 1,
Expand Down
2 changes: 1 addition & 1 deletion WordPressVIPMinimum/ruleset-test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ session_status(); // Error.
session_unregister(); // Error.
session_unset(); // Error.
session_write_close(); // Error.
delete(); // Error.
unlink(); // Error.
file_put_contents( $file, $text, FILE_APPEND ); // Error.
while ( $count > $loop ) {
if ( flock( $fp, LOCK_EX ) ) { // Error.
Expand Down

0 comments on commit 756b1a5

Please sign in to comment.