Skip to content

Commit 05a2f91

Browse files
authored
Downgrade file ops functions to warning (#415)
Downgrade file ops functions to warning
2 parents e8df198 + 80eb76f commit 05a2f91

File tree

3 files changed

+126
-107
lines changed

3 files changed

+126
-107
lines changed

WordPress-VIP-Go/ruleset-test.inc

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
<?php
22

33
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_delete
4-
delete( $file ); // Error + Message.
4+
delete( $file ); // Warning + Message.
55

66
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_file_put_contents
7-
file_put_contents( 'file.txt', '', FILE_APPEND ); // Error + Message.
7+
file_put_contents( 'file.txt', '', FILE_APPEND ); // Warning + Message.
88

99
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_flock
10-
if ( flock( $fp, LOCK_EX ) ) { // Error + Message.
10+
if ( flock( $fp, LOCK_EX ) ) { // Warning + Message.
1111
}
1212

1313
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_fputcsv
14-
fputcsv( $fp, $array ); // Error + Message.
14+
fputcsv( $fp, $array ); // Warning + Message.
1515

1616
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_fputs
17-
fputs( $fp, 'test' ); // Error + Message.
17+
fputs( $fp, 'test' ); // Warning + Message.
1818

1919
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_fwrite
20-
fwrite( $fp, 'test' ); // Error + Message.
20+
fwrite( $fp, 'test' ); // Warning + Message.
2121

2222
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_ftruncate
23-
ftruncate( $fp, 1 ); // Error + Message.
23+
ftruncate( $fp, 1 ); // Warning + Message.
2424

2525
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_is_writable
26-
is_writable( 'file.txt' ); // Error + Message.
26+
is_writable( 'file.txt' ); // Warning + Message.
2727

2828
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_is_writeable
29-
is_writeable( $file ); // Error + Message.
29+
is_writeable( $file ); // Warning + Message.
3030

3131
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_link
32-
link( 'file.txt', 'newfile.txt' ); // Error + Message.
32+
link( 'file.txt', 'newfile.txt' ); // Warning + Message.
3333

3434
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_rename
35-
rename( 'oldfile.txt', $file ); // Error + Message.
35+
rename( 'oldfile.txt', $file ); // Warning + Message.
3636

3737
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_symlink
38-
symlink( $file, 'file.txt' ); // Error + Message.
38+
symlink( $file, 'file.txt' ); // Warning + Message.
3939

4040
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_tempname
41-
tempnam( $dir, 'pre' ); // Error + Message.
41+
tempnam( $dir, 'pre' ); // Warning + Message.
4242

4343
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_touch
44-
touch( $file ); // Error + Message.
44+
touch( $file ); // Warning + Message.
4545

4646
// WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink
47-
unlink( $file ); // Error + Message.
47+
unlink( $file ); // Warning + Message.
4848

4949
// WordPressVIPMinimum.Functions.RestrictedFunctions.cookies_setcookie
50-
setcookie( 'cookie[three]', 'cookiethree' ); // EError + Message.
50+
setcookie( 'cookie[three]', 'cookiethree' ); // Error + Message.
5151

5252
// WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___COOKIE
5353
$x = sanitize_key( $_COOKIE['bar'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- Error + Message.
@@ -57,13 +57,13 @@ if ( ! isset( $_SERVER['HTTP_USER_AGENT'] ) ) { // Error + Message.
5757
}
5858

5959
// WordPress.WP.AlternativeFunctions.file_system_read_fclose
60-
fclose( $fp ); // Error + Message.
60+
fclose( $fp ); // Warning + Message.
6161

6262
// WordPress.WP.AlternativeFunctions.file_system_read_fopen
63-
fopen( 'file.txt', 'r' ); // Error + Message.
63+
fopen( 'file.txt', 'r' ); // Warning + Message.
6464

6565
// WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown
66-
$external_resource = file_get_contents( $test ); // Error + Message.
66+
$external_resource = file_get_contents( $test ); // Warning + Message.
6767
$file_content = file_get_contents( 'my-file.svg' ); // Ok.
6868
wpcom_vip_file_get_contents( $bar ); // Ok.
6969

@@ -388,24 +388,24 @@ session_status(); // Error.
388388
session_unregister(); // Error.
389389
session_unset(); // Error.
390390
session_write_close(); // Error.
391-
delete(); // Error.
392-
file_put_contents( $file, $text, FILE_APPEND ); // Error.
391+
delete(); // Warning.
392+
file_put_contents( $file, $text, FILE_APPEND ); // Warning.
393393
while ( $count > $loop ) {
394-
if ( flock( $fp, LOCK_EX ) ) { // Error.
395-
fwrite( $fp, $text ); // Error.
394+
if ( flock( $fp, LOCK_EX ) ) { // Warning.
395+
fwrite( $fp, $text ); // Warning.
396396
}
397397
}
398-
fputcsv(); // Error.
399-
fputs(); // Error.
400-
ftruncate(); // Error.
401-
is_writable(); // Error.
402-
is_writeable(); // Error.
403-
link(); // Error.
404-
rename(); // Error.
405-
symlink(); // Error.
406-
tempnam(); // Error.
407-
touch(); // Error.
408-
unlink(); // Error.
398+
fputcsv(); // Warning.
399+
fputs(); // Warning.
400+
ftruncate(); // Warning.
401+
is_writable(); // Warning.
402+
is_writeable(); // Warning.
403+
link(); // Warning.
404+
rename(); // Warning.
405+
symlink(); // Warning.
406+
tempnam(); // Warning.
407+
touch(); // Warning.
408+
unlink(); // Warning.
409409
mkdir(); // Error.
410410
rmdir(); // Error.
411411
chgrp(); // Error.

WordPress-VIP-Go/ruleset-test.php

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,9 @@
1515
// Expected values.
1616
$expected = [
1717
'errors' => [
18-
4 => 1,
19-
7 => 1,
20-
10 => 1,
21-
14 => 1,
22-
17 => 1,
23-
20 => 1,
24-
23 => 1,
25-
26 => 1,
26-
29 => 1,
27-
32 => 1,
28-
35 => 1,
29-
38 => 1,
30-
41 => 1,
31-
44 => 1,
32-
47 => 1,
3318
50 => 1,
3419
53 => 1,
3520
56 => 1,
36-
60 => 1,
37-
63 => 1,
38-
66 => 1,
3921
72 => 1,
4022
83 => 1,
4123
165 => 1,
@@ -109,21 +91,6 @@
10991
388 => 1,
11092
389 => 1,
11193
390 => 1,
112-
391 => 1,
113-
392 => 1,
114-
394 => 1,
115-
395 => 1,
116-
398 => 1,
117-
399 => 1,
118-
400 => 1,
119-
401 => 1,
120-
402 => 1,
121-
403 => 1,
122-
404 => 1,
123-
405 => 1,
124-
406 => 1,
125-
407 => 1,
126-
408 => 1,
12794
409 => 1,
12895
410 => 1,
12996
411 => 1,
@@ -164,6 +131,24 @@
164131
575 => 1,
165132
],
166133
'warnings' => [
134+
4 => 1,
135+
7 => 1,
136+
10 => 1,
137+
14 => 1,
138+
17 => 1,
139+
20 => 1,
140+
23 => 1,
141+
26 => 1,
142+
29 => 1,
143+
32 => 1,
144+
35 => 1,
145+
38 => 1,
146+
41 => 1,
147+
44 => 1,
148+
47 => 1,
149+
60 => 1,
150+
63 => 1,
151+
66 => 1,
167152
85 => 1,
168153
90 => 1,
169154
94 => 1,
@@ -218,6 +203,21 @@
218203
322 => 1,
219204
326 => 1,
220205
332 => 1,
206+
391 => 1,
207+
392 => 1,
208+
394 => 1,
209+
395 => 1,
210+
398 => 1,
211+
399 => 1,
212+
400 => 1,
213+
401 => 1,
214+
402 => 1,
215+
403 => 1,
216+
404 => 1,
217+
405 => 1,
218+
406 => 1,
219+
407 => 1,
220+
408 => 1,
221221
416 => 1,
222222
417 => 1,
223223
418 => 1,
@@ -242,49 +242,49 @@
242242
],
243243
'messages' => [
244244
4 => [
245-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as delete() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
245+
'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://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
246246
],
247247
7 => [
248-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as file_put_contents() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
248+
'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://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
249249
],
250250
10 => [
251-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as flock() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
251+
'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 flock(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
252252
],
253253
14 => [
254-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as fputcsv() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
254+
'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 fputcsv(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
255255
],
256256
17 => [
257-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as fputs() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
257+
'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 fputs(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
258258
],
259259
20 => [
260-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as fwrite() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
260+
'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 fwrite(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
261261
],
262262
23 => [
263-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as ftruncate() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
263+
'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 ftruncate(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
264264
],
265265
26 => [
266-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as is_writable() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
266+
'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 is_writable(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
267267
],
268268
29 => [
269-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as is_writeable() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
269+
'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 is_writeable(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
270270
],
271271
32 => [
272-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as link() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
272+
'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 link(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
273273
],
274274
35 => [
275-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as rename() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
275+
'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 rename(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
276276
],
277277
38 => [
278-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as symlink() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
278+
'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 symlink(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
279279
],
280280
41 => [
281-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as tempnam() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
281+
'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 tempnam(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
282282
],
283283
44 => [
284-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as touch() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
284+
'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 touch(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
285285
],
286286
47 => [
287-
'File system writes only work in /tmp/ and inside the /uploads/ folder on VIP Go. To do filesystem writes you must use the WP_Filesystem class, using functions such as unlink() won\'t work or will return unexpected results. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
287+
'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://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
288288
],
289289
50 => [
290290
'Due to server-side caching, server-side based client related logic might not work. We recommend implementing client side logic in JavaScript instead.',
@@ -296,13 +296,13 @@
296296
'Due to server-side caching, server-side based client related logic might not work. We recommend implementing client side logic in JavaScript instead.',
297297
],
298298
60 => [
299-
'File operations should use WP_Filesystem methods instead of direct PHP filesystem calls. Found: fclose(). Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
299+
'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 fclose(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
300300
],
301301
63 => [
302-
'File operations should use WP_Filesystem methods instead of direct PHP filesystem calls. Found: fopen(). Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
302+
'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 fopen(). For more details, please see: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
303303
],
304304
66 => [
305-
'file_get_contents() is uncached. If this is being used to query a remote file please use wpcom_vip_file_get_contents() instead. If it\'s used for a local file please use WP_Filesystem instead. Read more here: https://wpvip.com/documentation/vip-go/writing-files-on-vip-go/',
305+
'file_get_contents() is uncached. If the function is being used to fetch a remote file (e.g. a URL starting with https://), please use wpcom_vip_file_get_contents() to ensure the results are cached. For more details, please see https://wpvip.com/documentation/vip-go/fetching-remote-data/',
306306
],
307307
90 => [
308308
'Having more than 100 posts returned per page may lead to severe performance problems.',

0 commit comments

Comments
 (0)