Skip to content

Commit 47fe531

Browse files
authored
Merge pull request #53 from GrahamCampbell/patch-1
Avoid the getenv function when unsafe
2 parents 773a6d1 + 7a13c13 commit 47fe531

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/CaBundle.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ public static function getSystemCaRootBundlePath(LoggerInterface $logger = null)
7171

7272
// If SSL_CERT_FILE env variable points to a valid certificate/bundle, use that.
7373
// This mimics how OpenSSL uses the SSL_CERT_FILE env variable.
74-
$caBundlePaths[] = getenv('SSL_CERT_FILE');
74+
$caBundlePaths[] = self::getEnvVariable('SSL_CERT_FILE');
7575

7676
// If SSL_CERT_DIR env variable points to a valid certificate/bundle, use that.
7777
// This mimics how OpenSSL uses the SSL_CERT_FILE env variable.
78-
$caBundlePaths[] = getenv('SSL_CERT_DIR');
78+
$caBundlePaths[] = self::getEnvVariable('SSL_CERT_DIR');
7979

8080
$caBundlePaths[] = ini_get('openssl.cafile');
8181
$caBundlePaths[] = ini_get('openssl.capath');
@@ -299,6 +299,19 @@ public static function reset()
299299
self::$useOpensslParse = null;
300300
}
301301

302+
private static function getEnvVariable($name)
303+
{
304+
if (isset($_SERVER[$name])) {
305+
return (string) $_SERVER[$name];
306+
}
307+
308+
if (PHP_SAPI === 'cli' && ($value = getenv($name)) !== false && $value !== null) {
309+
return (string) $value;
310+
}
311+
312+
return false;
313+
}
314+
302315
private static function caFileUsable($certFile, LoggerInterface $logger = null)
303316
{
304317
return $certFile && @is_file($certFile) && @is_readable($certFile) && static::validateCaFile($certFile, $logger);

0 commit comments

Comments
 (0)