Server-Side Request Forgery in phpseclib: X.509 Certificate Validation Vulnerability
Summary
GHSA-m557-wrgg-6rp4: When an application validates an untrusted X.509 certificate with phpseclib, X509::validateSignature() reads a URL out of that certificate's Authority Information Access (AIA) extension and connects to it. Affects phpseclib/phpseclib across 3 version ranges.
>= 0.1.1, < 1.0.30
>= 2.0.0, < 2.0.55
>= 3.0.0, < 3.0.54
Fixed in 1.0.30, 2.0.55 or 3.0.54, depending on the release line you run. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
phpseclib is a popular PHP library that provides a range of cryptographic functionalities, including support for X.509 certificates. It is widely used in applications that require secure communications and certificate validation. However, a significant vulnerability has been identified in the way phpseclib handles X.509 certificate validation, specifically in its handling of the Authority Information Access (AIA) extension, which can lead to server-side request forgery (SSRF) attacks.
Vulnerability Detail
The vulnerability arises when phpseclib validates an untrusted X.509 certificate. The function X509::validateSignature() reads a URL from the certificate's AIA extension and connects to it without any restrictions. This allows an attacker to control the host, port, and path of the connection, potentially leading to unauthorized access to internal services or metadata endpoints. The default behavior of enabling URL fetching and the lack of destination restrictions make this a critical issue, as it can be exploited by unauthenticated attackers to probe internal networks.
How To Fix
Fixed versions by release line
The minimum fixed version depends on the release line you run.
-
>= 0.1.1, < 1.0.301.0.30composer require phpseclib/phpseclib:1.0.30 -
>= 2.0.0, < 2.0.552.0.55composer require phpseclib/phpseclib:2.0.55 -
>= 3.0.0, < 3.0.543.0.54composer require phpseclib/phpseclib:3.0.54
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
As a temporary workaround, you can disable URL fetching by calling the method X509::disableURLFetch() before validating any certificates. This will prevent any outbound connections during the validation process. Here is an example code snippet:
<?php require 'vendor/autoload.php'; use phpseclib3\File\X509; ``` X509::disableURLFetch(); // Disable URL fetching $v = new X509(); $v->loadX509(file_get_contents('attacker_cert.pem')); ``` $v->validateSignature(); // This will not connect to any external URL ?>Conclusion
The phpseclib library has a vulnerability in its X.509 certificate validation process that can lead to SSRF attacks. It is crucial to update to the latest patched versions to mitigate this risk. Additionally, using workarounds like disabling URL fetching can provide temporary relief until the library is updated.
See every vulnerability recorded for phpseclib/phpseclib →
FAQ
SSRF is a type of attack where an attacker can make requests from a vulnerable server to internal or external resources, potentially leading to data exposure or unauthorized access.
You can check if your application is affected by using Vulert, which monitors open-source vulnerabilities in real-time. Visit Vulert Scanner to analyze your composer.lock file.
An attacker can gain access to internal services, perform reconnaissance, and potentially exploit other vulnerabilities within your network.
Yes, you can disable URL fetching in phpseclib by using the X509::disableURLFetch() method before validating certificates.
The CVSS score of this vulnerability is 5.8, indicating a moderate level of severity.
References
Related vulnerabilities
Recent vulnerabilities recorded for phpseclib/phpseclib.