瀏覽代碼

Prevent user@host URLs from freezing processes

Jordi Boggiano 13 年之前
父節點
當前提交
da5b084192
共有 1 個文件被更改,包括 11 次插入1 次删除
  1. 11 1
      src/Packagist/WebBundle/Entity/Package.php

+ 11 - 1
src/Packagist/WebBundle/Entity/Package.php

@@ -94,6 +94,7 @@ class Package
     private $indexedAt;
 
     private $entityRepository;
+    private $repositoryClass;
 
     public function __construct()
     {
@@ -129,7 +130,11 @@ class Package
 
         $repo = $this->repositoryClass;
         if (!$repo) {
-            $context->addViolation('No valid/supported repository was found at the given URL', array(), null);
+            if (preg_match('{//.+@}', $this->repository)) {
+                $context->addViolation('URLs with user@host are not supported, use a read-only public URL', array(), null);
+            } else {
+                $context->addViolation('No valid/supported repository was found at the given URL', array(), null);
+            }
             return;
         }
         try {
@@ -264,6 +269,11 @@ class Package
     {
         $this->repository = $repository;
 
+        // avoid user@host URLs
+        if (preg_match('{//.+@}', $repository)) {
+            return;
+        }
+
         $repositoryManager = new RepositoryManager;
         $repositoryManager->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
         $repositoryManager->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository');