File tree Expand file tree Collapse file tree 3 files changed +39
-15
lines changed
Expand file tree Collapse file tree 3 files changed +39
-15
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,29 @@ public function run()
3737 require_once (__DIR__ . '/../vendor/autoload.php ' );
3838 require_once (__DIR__ . '/../core/init.php ' );
3939
40+ // Confirm that process is running as same user that web process uses, otherwise all sorts of permission
41+ // problems may happen and checks cannot be guaranteed to make sense.
42+ $ token = bin2hex (random_bytes (32 ));
43+ $ tmpFile = "/tmp/ob_cli_ {$ token }" ;
44+ touch ($ tmpFile );
45+
46+ $ requestUrl = rtrim (OB_SITE , '/ ' ) . '/same-user.php?token= ' . $ token ;
47+ $ ch = curl_init ($ requestUrl );
48+ curl_setopt_array ($ ch , [
49+ CURLOPT_RETURNTRANSFER => true ,
50+ CURLOPT_NOBODY => true ,
51+ CURLOPT_TIMEOUT => 5 ,
52+ ]);
53+ curl_exec ($ ch );
54+ $ statusCode = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
55+ curl_close ($ ch );
56+ unlink ($ tmpFile );
57+
58+ if ($ statusCode !== 200 ) {
59+ echo Helpers::bold ('CLI process and web server are running as different users. ( ' . $ statusCode . ') ' ) . PHP_EOL ;
60+ exit (1 );
61+ }
62+
4063 // Find the most specific CLI class based on the commands provided.
4164 $ commands = array_slice ($ this ->argv , 1 );
4265 $ cliInstance = null ;
Original file line number Diff line number Diff line change @@ -15,7 +15,6 @@ public function run(array $args): bool
1515 $ checker = new \OBFChecker ();
1616 $ methods = get_class_methods ($ checker );
1717 $ methods = array_filter ($ methods , fn ($ x ) => $ x !== '__construct ' );
18- $ results = [];
1918 $ rows = [];
2019 $ errors = 0 ;
2120 $ warnings = 0 ;
@@ -24,20 +23,7 @@ public function run(array $args): bool
2423 $ check_fatal_error = false ;
2524
2625 foreach ($ methods as $ method ) {
27- // directories valid needs to be run via web. use includes/web.php to do that.
28- if ($ method == 'directories_valid ' ) {
29- $ ob_site = OB_SITE ;
30- if (!str_ends_with ($ ob_site , '/ ' )) {
31- $ ob_site .= '/ ' ;
32- }
33-
34- // This currently fails on most installs on account of the server not allowing direct access to the tools directory.
35- $ web_check_result = json_decode (file_get_contents ($ ob_site . 'tools/cli/includes/web.php ' ), true );
36- $ result = $ web_check_result ['directories_valid ' ] ?? ['Directories ' , 'Unable to check directory permissions. ' , 1 ];
37- } else {
38- $ result = $ checker ->$ method ();
39- }
40- $ results [] = $ result ;
26+ $ result = $ checker ->$ method ();
4127
4228 $ formatting1 = '' ;
4329 $ formatting2 = '' ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ $ token = preg_replace ('/[^a-f0-9]/ ' , '' , $ _GET ['token ' ] ?? '' );
4+ $ tmpFile = "/tmp/ob_cli_ {$ token }" ;
5+
6+ if (strlen ($ token ) !== 64 || ! is_file ($ tmpFile ) || time () - filemtime ($ tmpFile ) > 10 ) {
7+ http_response_code (401 );
8+ exit ();
9+ }
10+
11+ $ fileOwnerUid = fileowner ($ tmpFile );
12+ $ webServerUid = posix_geteuid ();
13+
14+ http_response_code ($ fileOwnerUid === $ webServerUid ? 200 : 403 );
15+ exit ();
You can’t perform that action at this time.
0 commit comments