From: epriestley Date: Sun, 26 Jun 2011 18:09:13 +0000 (-0700) Subject: Verify that ~/.arcrc is 600 before reading from it X-Git-Tag: conduit-4~300 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=182e2604720758cf67726543ed45f906cd845ed9;p=arcanist.git Verify that ~/.arcrc is 600 before reading from it 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 --- diff --git a/src/workflow/base/ArcanistBaseWorkflow.php b/src/workflow/base/ArcanistBaseWorkflow.php index 21168950..4bf2c540 100644 --- a/src/workflow/base/ArcanistBaseWorkflow.php +++ b/src/workflow/base/ArcanistBaseWorkflow.php @@ -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)) {