Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14357010
D12170.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D12170.diff
View Options
diff --git a/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php b/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
--- a/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
+++ b/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
@@ -395,10 +395,16 @@
}
}
- $repository->execxRemoteCommand(
- 'clone --noupdate -- %P %s',
- $remote,
- $path);
+ try {
+ $repository->execxRemoteCommand(
+ 'clone --noupdate -- %P %s',
+ $remote,
+ $path);
+ } catch (Exception $ex) {
+ $message = $ex->getMessage();
+ $message = $this->censorMercurialErrorMessage($message);
+ throw new Exception($message);
+ }
}
}
@@ -438,13 +444,39 @@
if ($err == 1 && preg_match('/no changes found/', $stdout)) {
return;
} else {
- throw $ex;
+ $message = $ex->getMessage();
+ $message = $this->censorMercurialErrorMessage($message);
+ throw new Exception($message);
}
}
}
/**
+ * Censor response bodies from Mercurial error messages.
+ *
+ * When Mercurial attempts to clone an HTTP repository but does not
+ * receive a response it expects, it emits the response body in the
+ * command output.
+ *
+ * This represents a potential SSRF issue, because an attacker with
+ * permission to create repositories can create one which points at the
+ * remote URI for some local service, then read the response from the
+ * error message. To prevent this, censor response bodies out of error
+ * messages.
+ *
+ * @param string Uncensored Mercurial command output.
+ * @return string Censored Mercurial command output.
+ */
+ private function censorMercurialErrorMessage($message) {
+ return preg_replace(
+ '/^---%<---.*/sm',
+ pht('<Response body omitted from Mercurial error message.>')."\n",
+ $message);
+ }
+
+
+ /**
* @task hg
*/
private function installMercurialHook() {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 21, 2:01 AM (16 h, 57 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6912472
Default Alt Text
D12170.diff (2 KB)
Attached To
Mode
D12170: Censor response bodies from Mercurial error messages
Attached
Detach File
Event Timeline
Log In to Comment