A free, self-hostable news aggregator…
More robust application of access permissions (#5062)
Alexandre Alapetitee899e4edd97c
diff --git a/Docker/entrypoint.sh b/Docker/entrypoint.shindex 018946397..cbc2443d6 100755--- a/Docker/entrypoint.sh+++ b/Docker/entrypoint.sh@@ -7,8 +7,6 @@ find /etc/php*/ -type f -name php.ini -exec sed -r -i "\\#^;?date.timezone#s#^.*find /etc/php*/ -type f -name php.ini -exec sed -r -i "\\#^;?post_max_size#s#^.*#post_max_size = 32M#" {} \;find /etc/php*/ -type f -name php.ini -exec sed -r -i "\\#^;?upload_max_filesize#s#^.*#upload_max_filesize = 32M#" {} \;-php -f ./cli/prepare.php >/dev/null-if [ -n "$LISTEN" ]; thenfind /etc/apache2/ -type f -name FreshRSS.Apache.conf -exec sed -r -i "\\#^Listen#s#^.*#Listen $LISTEN#" {} \;fi@@ -24,6 +22,10 @@ if [ -n "$CRON_MIN" ]; then-r "s#^[^ ]+ #$CRON_MIN #" | crontab -fi+./cli/access-permissions.sh++php -f ./cli/prepare.php >/dev/null+if [ -n "$FRESHRSS_INSTALL" ]; then# shellcheck disable=SC2046php -f ./cli/do-install.php -- \@@ -57,9 +59,6 @@ if [ -n "$FRESHRSS_USER" ]; thenfifi-chown -R :www-data .-chmod -R g+r .-chmod -R g+w ./data/-chmod g+x ./extensions/+./cli/access-permissions.shexec "$@"diff --git a/README.fr.md b/README.fr.mdindex 99b5a1a2c..221385ab5 100644--- a/README.fr.md+++ b/README.fr.md@@ -113,7 +113,7 @@ cd FreshRSSsudo git checkout $(git describe --tags --abbrev=0)# Mettre les droits d’accès pour le serveur Web-sudo chown -R :www-data . && sudo chmod -R g+r . && sudo chmod -R g+w ./data/+sudo cli/access-permissions.sh# Si vous souhaitez permettre les mises à jour par l’interface Websudo chmod -R g+w .@@ -126,7 +126,7 @@ sudo ln -s /usr/share/FreshRSS/p /var/www/html/FreshRSS# Mettre à jour FreshRSS vers une nouvelle version par gitcd /usr/share/FreshRSSsudo git pull-sudo chown -R :www-data . && sudo chmod -R g+r . && sudo chmod -R g+w ./data/+sudo cli/access-permissions.sh```Voir la [documentation de la ligne de commande](cli/README.md) pour plus de détails.diff --git a/app/Controllers/userController.php b/app/Controllers/userController.phpindex 55b4ca7cb..ac8f3be82 100644--- a/app/Controllers/userController.php+++ b/app/Controllers/userController.php@@ -242,7 +242,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {}if ($ok) {if (!is_dir($homeDir)) {- mkdir($homeDir);+ mkdir($homeDir, 0770, true);}$ok &= (file_put_contents($configPath, "<?php\n return " . var_export($userConfig, true) . ';') !== false);}diff --git a/app/Models/Feed.php b/app/Models/Feed.phpindex 09cacbd61..f7ff76768 100644--- a/app/Models/Feed.php+++ b/app/Models/Feed.php@@ -979,14 +979,14 @@ class FreshRSS_Feed extends Minz_Model {$key = $hubJson['key']; //To renew our lease}} else {- @mkdir($path, 0777, true);+ @mkdir($path, 0770, true);$key = sha1($path . FreshRSS_Context::$system_conf->salt);$hubJson = array('hub' => $this->hubUrl,'key' => $key,);file_put_contents($hubFilename, json_encode($hubJson));- @mkdir(PSHB_PATH . '/keys/');+ @mkdir(PSHB_PATH . '/keys/', 0770, true);file_put_contents(PSHB_PATH . '/keys/' . $key . '.txt', $this->selfUrl);$text = 'WebSub prepared for ' . $this->url;Minz_Log::debug($text);diff --git a/cli/README.md b/cli/README.mdindex e290cc267..cb43b7340 100644--- a/cli/README.md+++ b/cli/README.md@@ -18,9 +18,7 @@ In any case, when you are done with a series of commands, you should re-apply th```shcd /usr/share/FreshRSS-sudo chown -R :www-data .-sudo chmod -R g+r .-sudo chmod -R g+w ./data/+sudo cli/access-permissions.sh```diff --git a/cli/_cli.php b/cli/_cli.phpindex 10a92385a..0d2c8695f 100644--- a/cli/_cli.php+++ b/cli/_cli.php@@ -44,7 +44,7 @@ function cliInitUser($username) {function accessRights() {echo 'ℹ️ Remember to re-apply the appropriate access rights, such as:',- "\t", 'sudo chown -R :www-data . && sudo chmod -R g+r . && sudo chmod -R g+w ./data/', "\n";+ "\t", 'sudo cli/access-permissions.sh', "\n";}function done($ok = true) {diff --git a/cli/access-permissions.sh b/cli/access-permissions.shnew file mode 100755index 000000000..c13130a4b--- /dev/null+++ b/cli/access-permissions.sh@@ -0,0 +1,19 @@+#!/bin/sh+# Apply access permissions++if [ ! -f './constants.php' ] || [ ! -d './cli/' ]; then+ echo >&2 '⛔ It does not look like a FreshRSS directory; exiting!'+ exit 2+fi++if [ "$(id -u)" -ne 0 ]; then+ echo >&2 '⛔ Applying access permissions require running as root or sudo!'+ exit 3+fi++# Based on group access+chown -R :www-data .+# Read files, and directory traversal+chmod -R g+rX .+# Write access+chmod -R g+w ./data/diff --git a/cli/i18n/I18nFile.php b/cli/i18n/I18nFile.phpindex fca31d662..12a04c6a2 100644--- a/cli/i18n/I18nFile.php+++ b/cli/i18n/I18nFile.php@@ -27,7 +27,7 @@ class I18nFile {foreach ($i18n as $language => $file) {$dir = I18N_PATH . DIRECTORY_SEPARATOR . $language;if (!file_exists($dir)) {- mkdir($dir);+ mkdir($dir, 0770, true);}foreach ($file as $name => $content) {$filename = $dir . DIRECTORY_SEPARATOR . $name;diff --git a/docs/en/admins/06_LinuxInstall.md b/docs/en/admins/06_LinuxInstall.mdindex e92fc3247..1af041efe 100644--- a/docs/en/admins/06_LinuxInstall.md+++ b/docs/en/admins/06_LinuxInstall.md@@ -81,14 +81,7 @@ Change to the new FreshRSS directory, and set the permissions so that your Web s```shcd FreshRSS-chown -R :www-data .-sudo chmod -R g+r .-```--We’ll also need to allow the data folder to be written to, like so:--```sh-chmod -R g+w ./data/+sudo cli/access-permissions.sh```Optional: If you would like to allow updates from the Web interface, set write permissionsdiff --git a/docs/en/admins/07_LinuxUpdate.md b/docs/en/admins/07_LinuxUpdate.mdindex 834dfaaef..27e8ef451 100644--- a/docs/en/admins/07_LinuxUpdate.md+++ b/docs/en/admins/07_LinuxUpdate.md@@ -64,7 +64,7 @@ If your local user doesn’t have write access to the FreshRSS folder, use a sud6. Re-set correct permissions so that your web server can access the files```sh- chown -R :www-data . && chmod -R g+r . && chmod -R g+w ./data/+ cli/access-permissions.sh```## Using the Zip archive@@ -91,7 +91,7 @@ If your local user doesn’t have write access to the FreshRSS folder, use a sud5. Re-set permissions```sh- chown -R :www-data . && chmod -R g+r . && chmod -R g+w ./data/+ cli/access-permissions.sh```6. Clean up the FreshRSS directory by deleting the downloaded zip and the temporary directorydiff --git a/lib/Minz/Migrator.php b/lib/Minz/Migrator.phpindex 0f28237c5..ef89a3b55 100644--- a/lib/Minz/Migrator.php+++ b/lib/Minz/Migrator.php@@ -55,7 +55,7 @@ class Minz_Migrator}$lock_path = $applied_migrations_path . '.lock';- if (!@mkdir($lock_path)) {+ if (!@mkdir($lock_path, 0770, true)) {// Someone is probably already executing the migrations (the folder// already exists).// We should probably return something else, but we don't want the