Skip to content

Commit

Permalink
Restrict certificate loading to HTTP and HTTPS urls (#34)
Browse files Browse the repository at this point in the history
* Update Certificate.php

* Fix mistake in fetchParentCertificate

* Fix StyleCI issues

* Fix StyleCI issues

* Refactor fetchParentCertificate scheme check and add comment
  • Loading branch information
Manawyrm authored Jul 29, 2020
1 parent 1240470 commit 66fbd0e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use phpseclib\File\ASN1;
use phpseclib\File\X509;
use Spatie\CertificateChain\Exceptions\CouldNotLoadCertificate;
use Spatie\CertificateChain\Exceptions\CouldNotCreateCertificate;
use Spatie\CertificateChain\Exceptions\CouldNotLoadCertificate;

class Certificate
{
Expand Down Expand Up @@ -81,7 +81,16 @@ public function getParentCertificateUrl(): string

public function fetchParentCertificate(): self
{
return static::loadFromUrl($this->getParentCertificateUrl());
$url = $this->getParentCertificateUrl();

// Only allow for parent certificates to be read from HTTP and HTTPS URLs to
// prevent local file inclusion vulnerabilities
$scheme = parse_url($url, PHP_URL_SCHEME);
if (! in_array($scheme, ['http', 'https'])) {
throw CouldNotLoadCertificate::invalidCertificateUrl($url);
}

return static::loadFromUrl($url);
}

public function hasParentInTrustChain(): bool
Expand Down

0 comments on commit 66fbd0e

Please sign in to comment.