]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Validate Arcanist install-certificate URIs more carefully
authorepriestley <git@epriestley.com>
Tue, 28 Jun 2016 21:43:41 +0000 (14:43 -0700)
committerepriestley <git@epriestley.com>
Tue, 28 Jun 2016 22:20:06 +0000 (15:20 -0700)
Summary: Fixes T11222. This was lazy-future-proofed for Conduit SSH support, but users are boundlessly creative. Check protocols explicitly.

Test Plan:
```
$ arc install-certificate a.b:1/
Usage Exception: Server URI "a.b:1/" must include the "http" or "https" protocol. It should be in the form "https://phabricator.example.com/".
```

  - Also went through a successful workflow with a URI in the form provided in the example.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11222

Differential Revision: https://secure.phabricator.com/D16188

src/workflow/ArcanistInstallCertificateWorkflow.php

index 41a98519fa84ac002f3e93ecb875fc7fa6d25c06..b437697b7287589a69cb2869323898e1ecc634af 100644 (file)
@@ -196,14 +196,31 @@ EOTEXT
       $uri = $conduit_uri;
     }
 
+    $example = 'https://phabricator.example.com/';
+
     $uri_object = new PhutilURI($uri);
-    if (!$uri_object->getProtocol() || !$uri_object->getDomain()) {
+    $protocol = $uri_object->getProtocol();
+    if (!$protocol || !$uri_object->getDomain()) {
       throw new ArcanistUsageException(
         pht(
           'Server URI "%s" must include a protocol and domain. It should be '.
           'in the form "%s".',
           $uri,
-          'https://phabricator.example.com/'));
+          $example));
+    }
+
+    $protocol = $uri_object->getProtocol();
+    switch ($protocol) {
+      case 'http':
+      case 'https':
+        break;
+      default:
+        throw new ArcanistUsageException(
+          pht(
+            'Server URI "%s" must include the "http" or "https" protocol. '.
+            'It should be in the form "%s".',
+            $uri,
+            $example));
     }
 
     $uri_object->setPath('/api/');