]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Verify that ~/.arcrc is 600 before reading from it
authorepriestley <git@epriestley.com>
Sun, 26 Jun 2011 18:09:13 +0000 (11:09 -0700)
committerepriestley <git@epriestley.com>
Sun, 26 Jun 2011 18:55:31 +0000 (11:55 -0700)
Summary:
Since this has auth information in it now, we should prevent other users on the
system from reading it. Detect readable files and prompt the user to fix them.

Test Plan:
Did "o+r" on my ~/.arcrc, ran "arc list", got prompted, hit "Y", verified it set
perms to 600, ran "arc list" again and wasn't prompted.

Reviewed By: jungejason
Reviewers: fratrik, jungejason, aran, tuomaspelkonen
CC: aran, jungejason, epriestley
Differential Revision: 532

src/workflow/base/ArcanistBaseWorkflow.php

index 21168950f0b528e4b68dee0c6ee7e4e54ce4e712..4bf2c54062ff324ae4f2a2273fc3cce407541ea2 100644 (file)
@@ -645,6 +645,20 @@ class ArcanistBaseWorkflow {
     $user_config = array();
     $user_config_path = self::getUserConfigurationFileLocation();
     if (Filesystem::pathExists($user_config_path)) {
+      $mode = fileperms($user_config_path);
+      if (!$mode) {
+        throw new Exception("Unable to get perms of '{$user_config_path}'!");
+      }
+      if ($mode & 0177) {
+        // Mode should allow only owner access.
+        $prompt = "File permissions on your ~/.arcrc are too open. ".
+                  "Fix them by chmod'ing to 600?";
+        if (!phutil_console_confirm($prompt, $default_no = false)) {
+          throw new ArcanistUsageException("Set ~/.arcrc to file mode 600.");
+        }
+        execx('chmod 600 %s', $user_config_path);
+      }
+
       $user_config_data = Filesystem::readFile($user_config_path);
       $user_config = json_decode($user_config_data, true);
       if (!is_array($user_config)) {