Download the PHP package craftcms/url-validator without Composer

On this page you can find all versions of the php package craftcms/url-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package url-validator

URL Validator

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Validate URLs and IP addresses before opening a connection, to guard against Server-Side Request Forgery (SSRF) and DNS rebinding.

By default, the validator rejects:

All checks happen before any connection is opened, and the validator returns the set of IP addresses the host resolved to so you can pin the eventual connection to them (preventing DNS rebinding between validation and download).

Installation

Install the package via Composer:

Usage

Use the resolved IPs to pin the connection (e.g. with cURL’s CURLOPT_RESOLVE) so the hostname can’t be re-resolved to a different, internal address between validation and the request:

Validating an IP address directly

validateScheme(string $url): bool and validateHostname(string $url): bool are also exposed if you need to check those pieces individually.

Customizing DNS resolution

By default hostnames are resolved against the system DNS. You can pass a custom resolver to the constructor — useful for testing, or for plugging in a caching/alternate resolver:

Customizing other options

The following options can also be configured by passing an array to the constructor as a second parameter. The following options are customizable:

See the codebase for the default values and expected types.

Allowing internal hosts

Private IP addresses (e.g. 10.0.0.0/8, 192.168.0.0/16, fd00::/8) are rejected by default. If your app needs to reach internal services, for example in local development or between containers in Docker or Kubernetes, list the hostnames that may resolve to private addresses:

[!WARNING]

  • Only list hostnames whose DNS you control.
  • List individual services rather than whole internal domains. Every listed host is reachable by anyone who can make your app send a request to it.

Pinning with curl

Validating a URL and then letting curl resolve its hostname again leaves room for DNS rebinding. curlResolve() validates the URL and returns a CURLOPT_RESOLVE value that pins the hostname and port to the validated IP addresses.

Using with Guzzle

Requires guzzlehttp/guzzle. GuzzleMiddleware validates and pins every request a Guzzle client sends, including the ones sent while following redirects. A disallowed URL makes the request throw an UrlValidationException.

If the client has already been created, you can add the middleware to its handler stack:

Otherwise, create the client with the handler stack:

[!NOTE]

  • Pinning only works with Guzzle’s curl handler. The middleware turns the stream request option off, because the stream handler would ignore the pin.
  • When requests go through an HTTP proxy, the proxy resolves the hostname itself, so the pin doesn’t apply there. URLs are still validated, but the proxy should enforce its own egress rules.

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of url-validator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0.2
ext-filter Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package craftcms/url-validator contains the following files

Loading the files please wait ...