From 182e2604720758cf67726543ed45f906cd845ed9 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 26 Jun 2011 11:09:13 -0700 Subject: [PATCH] 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 --- src/workflow/base/ArcanistBaseWorkflow.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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)) { -- 2.43.0