Download the PHP package dsentker/url-signature without Composer

On this page you can find all versions of the php package dsentker/url-signature. 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-signature

UrlSignature

Create URLs with a signature to prevent modification

PHP from Packagist Packagist Build Status GitHub last commit

This small PHP >7.2.0 library allows developers to build urls with a hash to prevent the modification of URL parts.

Why?

A common attack method that pentesters and actual attackers will use is to capture a URL with "id" values in it (like /user/view?id=1234) and manually change this value to try to bypass authorization checks. While an application should always have some kind of auth check when the URL is called, there's another step that can help to prevent URL changes: a signature value.

This signature value is built using the contents of the current URL along with a "secret" value unique to the application. This signature is then appended to the URL and can be used directly in links. When the URL is used and the request is received, the signature is then checked against the current URL values. If there's no match, the check fails.

Installation

Installing via Composer is simple:

composer require dsentker/url-signature

If you do not like composer, you can download this repository and use any PSR-4-Autoloader to get everything loaded.

There is also a Symfony bundle available:

composer require dsentker/url-signature-bundle

Usage

To sign (or validate) URLs, a key is required (which is of course secret). The key is used to hash special parts* of the URL and attach them as a signature in the query string of the URL.

*) You can decide for yourself which parts of the URL should be hashed.

Later, on validation, the same key is used to hash the current URL. This hash is compared with the hash in query string.

Signing URLs

In this example we've created a new Builder instance with a configuration object, and using it to create the URL based on the data and URL provided. The $url result has the signature (the hash) value appended to the query string.

Verifying URLs

The other half of the equation is the verification of a URL. The library provides a Validator class to help with that. The validator must be initiated with the same configuration as the builder. Otherwise different hash values would be calculated.

Validator::isValid($url) returns a boolean value based on the validation result, nothing more. Validator::verify($url) Will throw some of these exceptions if the url signature (or the expiration parameter) is not valid:

Expiring URLs

The library also provides the ability to create URLs that will fail validation because they've expired. To make use of this, simply pass in a second parameter for the signUrl() method call. This value should either be a relative string (parsable by PHPs strtotime) or a \DateTime object:

You'll notice the addition of a new URL parameter, the _expires value. This value is automatically read when the validate call is made to ensure the URL hasn't timed out. If it has, even if the rest of the data is correct, the result will be false.

Even if the attacker tries to update the _expires date to extend the length of the URL, the validation will fail as that's not the _expires value it was originally hashed with.

Advanced Configuration

Rename query parameter

The URL query keys "_expires" and "_signature" can be modified with the configuration object:

Control what parts of URL to sign

Per default, the following parts of the URL are considered for hash generation:

The configuration allows to modify these components with Bitmask Contants. Use HashConfiguration::setHashMask() to pass the Flags (use the pipe | to join flags).

For example, consider to add the URL scheme to the hashing process. That means that the validation of an URL fails only if the protocols (https <-> http) has changed.

Limitations and Security notes

This library creates a hash from one or more URL parts. That means, that the URL is only valid if the given signature matches the current signature. Like any other hash event (for example, hashing passwords), this is considered quite secure. For a signed URL to be truly secure, the developer must ensure that (when receiving a request) a check is made as to whether a hash check is required and / or whether the submitted signature is correct. In other words, if the user has the ability to retrieve a URL without a signature, the best hashing algorithm will not work.

Do NOT use this library if...

Credits

Based on the ideas by psecio, the project was forked by me to upgrade the code for PHP 7.x applications. The adjustments then resulted in a separate library (this one) and a symfony bundle.

Dependencies

The library uses the URL functions of thephpleague/uri to parse, extract and (re-)build URL components. For unit tests, PhpUnit is used.

I look forward to your help!

If you notice bugs, have general questions or want to implement a feature, you are welcome to collaborate.

Roadmap

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub.

Symfony 4/5 Bundle

I also created a bundle for Symfony (with twig support and annotations).

Testing

./vendor/bin/phpunit

Do not be surprised about a short break of two seconds during the tests. A sleep(2) was built in to test for the validation of the timeout functionality.

See also


All versions of url-signature with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2 || ^8.0
league/uri-query-parser Version ^1.0
league/uri-parser Version ^1.4
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 dsentker/url-signature contains the following files

Loading the files please wait ....