mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
When closing tasks with "Fixes xxx", try to act more authentically as the acting user
Summary: Via HackerOne (<https://hackerone.com/reports/220909>). When we close commits in response to "Fixes Txxx", we currently act as the omnipotent user. This allows users to close tasks they can't see by pushing commits with "Fixes Txxx" in the message. However, we can't actually tell who authored or committed a change: we're just using the "Author" and "Committer" values from Git in most cases, and anyone can forge those. So we can't really get this right, in a security sense. (We can tell who //pushed// a change if we host it, but that's often not the right user. If GPG signing was more prevalent, we could use that. In the future, we could use side channels like having `arc land` tell Phabrcator who was pushing changes.) Since I think the impact of this is fairly minor and this isn't //really// a security issue (more of a confusion/abuse/product issue) I think the behavior is okay more-or-less as-is, but we can do better when we do identify an author: drop permissions, and use their privileges to load the tasks which the commit "fixes". This effectively implements this rule: > If we identify the author of a commit as user X, that commit can only affect tasks which user X can see and edit. Note that: - Commits which we can't identify the author for can still affect any task. - Any user can forge any other user's identity (or an invalid identity) and affect any task. So this is just a guard rail to prevent mistakes by good-faith users who type the wrong task IDs, not a real security measure. Also note that to perform this "attack" you must already have commit access to a repository (or permission to create a repository). Test Plan: - Used `bin/repository reparse --message <commit> --force-autoclose` to run the relevant code. - Made the code `throw` before it actually applied the edit. - Verified that the edit was rejected if the author was recognized and can not see or could not edit the task. - Verified that the edit is accepted if the author can see+edit the task. - Verified that the edit is accepted if we can't figure out who the author is. Reviewers: chad Reviewed By: chad Differential Revision: https://secure.phabricator.com/D17688
This commit is contained in:
parent
69053a40f9
commit
1e43d57c81
1 changed files with 48 additions and 3 deletions
|
@ -163,6 +163,8 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
|||
$author_phid,
|
||||
id(new PhabricatorDiffusionApplication())->getPHID());
|
||||
|
||||
$acting_user = $this->loadActingUser($actor, $acting_as_phid);
|
||||
|
||||
$conn_w = id(new DifferentialRevision())->establishConnection('w');
|
||||
|
||||
// NOTE: The `differential_commit` table has a unique ID on `commitPHID`,
|
||||
|
@ -263,7 +265,8 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
|||
$acting_as_phid,
|
||||
$repository,
|
||||
$commit,
|
||||
$message);
|
||||
$message,
|
||||
$acting_user);
|
||||
}
|
||||
|
||||
$data->save();
|
||||
|
@ -287,7 +290,22 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
|||
$acting_as,
|
||||
PhabricatorRepository $repository,
|
||||
PhabricatorRepositoryCommit $commit,
|
||||
$message) {
|
||||
$message,
|
||||
PhabricatorUser $acting_user = null) {
|
||||
|
||||
// If we we were able to identify an author for the commit, we try to act
|
||||
// as that user when loading tasks marked with "Fixes Txxx". This prevents
|
||||
// mistakes where a user accidentally writes the wrong task IDs and affects
|
||||
// tasks they can't see (and thus can't undo the status changes for).
|
||||
|
||||
// This is just a guard rail, not a security measure. An attacker can still
|
||||
// forge another user's identity trivially by forging author or committer
|
||||
// emails. We also let commits with unrecognized authors act on any task to
|
||||
// make behavior less confusing for new installs.
|
||||
|
||||
if (!$acting_user) {
|
||||
$acting_user = $actor;
|
||||
}
|
||||
|
||||
$maniphest = 'PhabricatorManiphestApplication';
|
||||
if (!PhabricatorApplication::isClassInstalled($maniphest)) {
|
||||
|
@ -321,9 +339,14 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
|||
}
|
||||
|
||||
$tasks = id(new ManiphestTaskQuery())
|
||||
->setViewer($actor)
|
||||
->setViewer($acting_user)
|
||||
->withIDs(array_keys($task_statuses))
|
||||
->needProjectPHIDs(true)
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->execute();
|
||||
|
||||
foreach ($tasks as $task_id => $task) {
|
||||
|
@ -369,4 +392,26 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
|||
}
|
||||
}
|
||||
|
||||
private function loadActingUser(PhabricatorUser $viewer, $user_phid) {
|
||||
if (!$user_phid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$user_type = PhabricatorPeopleUserPHIDType::TYPECONST;
|
||||
if (phid_get_type($user_phid) != $user_type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$user = id(new PhabricatorPeopleQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($user_phid))
|
||||
->executeOne();
|
||||
if (!$user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue