Merge pull request #9155 from MrPetovan/bug/9154-forbid-bin
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Mon, 7 Sep 2020 11:01:10 +0000 (13:01 +0200)
committerGitHub <noreply@github.com>
Mon, 7 Sep 2020 11:01:10 +0000 (13:01 +0200)
Forbid non-CLI access to command-line scripts

.gitignore
.htaccess-dist
bin/.htaccess [new file with mode: 0644]
bin/auth_ejabberd.php
bin/console.php
bin/daemon.php
bin/testargs.php
bin/wait-for-connection
bin/worker.php
mods/sample-nginx.config

index 2d8acf0..3250fb0 100644 (file)
@@ -71,8 +71,8 @@ venv/
 /addons
 /addon
 
-#ignore .htaccess
-.htaccess
+#ignore base .htaccess
+/.htaccess
 
 #ignore filesystem storage default path
 /storage
index a671cc6..3c90982 100644 (file)
@@ -1,3 +1,6 @@
+# This file is meant to be copied to ".htaccess" on Apache-powered web servers.
+# The created .htaccess file can be edited manually and will not be overwritten by Friendica updates.
+
 Options -Indexes
 AddType application/x-java-archive .jar
 AddType audio/ogg .oga
diff --git a/bin/.htaccess b/bin/.htaccess
new file mode 100644 (file)
index 0000000..716a932
--- /dev/null
@@ -0,0 +1,10 @@
+# This file prevents browser access to Friendica command-line scripts on Apache-powered web servers.
+# It isn't meant to be edited manually, please check the base Friendica folder for the .htaccess-dist file instead.
+
+<IfModule authz_host_module>
+    Require all denied
+</IfModule>
+<IfModule !authz_host_module>
+    Order Allow,Deny
+    Deny from all
+</IfModule>
index fa71faf..e921829 100755 (executable)
  *
  */
 
+if (php_sapi_name() !== 'cli') {
+       header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden');
+       exit();
+}
+
 use Dice\Dice;
 use Friendica\App\Mode;
 use Friendica\Util\ExAuth;
index 27522d8..4d5b4c7 100755 (executable)
  *
  */
 
+if (php_sapi_name() !== 'cli') {
+       header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden');
+       exit();
+}
+
 use Dice\Dice;
 use Psr\Log\LoggerInterface;
 
index 596f4de..3fe803d 100755 (executable)
  * This script was taken from http://php.net/manual/en/function.pcntl-fork.php
  */
 
+if (php_sapi_name() !== 'cli') {
+       header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden');
+       exit();
+}
+
 use Dice\Dice;
 use Friendica\Core\Logger;
 use Friendica\Core\Worker;
index b7d7125..9aed353 100644 (file)
  *
  */
 
+if (php_sapi_name() !== 'cli') {
+       header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden');
+       exit();
+}
 
 if (($_SERVER["argc"] > 1) && isset($_SERVER["argv"][1])) {
        echo $_SERVER["argv"][1];
index b6c03a6..de860e9 100755 (executable)
  * Usage: php bin/wait-for-connection {HOST} {PORT} [{TIMEOUT}]
  */
 
+if (php_sapi_name() !== 'cli') {
+       header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden');
+       exit();
+}
+
 $timeout = 60;
 switch ($argc) {
        case 4:
index 1b70a20..833e5b0 100755 (executable)
  * Starts the background processing
  */
 
+if (php_sapi_name() !== 'cli') {
+       header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden');
+       exit();
+}
+
 use Dice\Dice;
 use Friendica\App;
 use Friendica\Core\Update;
index 71d3785..b90e1fe 100644 (file)
@@ -141,4 +141,9 @@ server {
   location ~ /\. {
     deny all;
   }
+
+  # deny access to the CLI scripts
+  location ^~ /bin {
+    deny all;
+  }
 }