Download the PHP package enlivenapp/flight-csrf without Composer

On this page you can find all versions of the php package enlivenapp/flight-csrf. 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 flight-csrf

Latest Release License PHP Version Monthly Downloads Total Downloads GitHub Issues Contributions Welcome

flight-csrf

CSRF protection middleware and helpers for FlightPHP.

Requirements

Installation

Setup

After installing, register the plugin to load the helper functions and scaffold default config:

Call this early in your bootstrap, before defining routes. register() does two things: it requires the helper file that defines csrf_field() and csrf_token(), and it writes default config keys into app/config/config.php if they're missing.

If you'd rather set things up yourself, skip register() and do the following instead:

  1. Require vendor/enlivenapp/flight-csrf/src/Helpers/csrf_helper.php from your bootstrap.
  2. Add the config block manually (see Configuration below).

Usage

Forms

Call csrf_field() to output a hidden input in any HTML form. The token is generated and stored in the session automatically.

AJAX requests

Call csrf_token() to get the raw token value. The common pattern is to embed it in a meta tag and read it from JavaScript.

The middleware accepts the token from either the _csrf_token POST field or the X-CSRF-TOKEN request header. The POST field is checked first.

Protecting routes

Apply CsrfMiddleware to any route or route group that needs protection:

When validation fails the middleware halts the request with a 403 response. The body is {"error":"CSRF token validation failed."} as JSON.

Configuration

Config lives under the enlivenapp.flight-csrf key. Defaults are in src/Config/Config.php. Override them in your app config, and values are merged on top of the defaults.

Key Default Description
field_name _csrf_token Name of the hidden form field
session_key _csrf_token Session key used to store the token
protected_methods ['POST','PUT','PATCH','DELETE'] HTTP methods that trigger validation
exclude_routes [] Request paths to skip (exact URI match, no query string)
token_lifetime 7200 Seconds from creation before the token expires. 0 disables time-based expiry. Expired tokens fail validation (403) and rotate on the next csrf_token() or csrf_field() call.

Overriding defaults

When Plugin::register() runs for the first time, it writes token_lifetime and exclude_routes into your config file so you can edit them in place. You can add any other key to the same block.

License

MIT


All versions of flight-csrf with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
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 enlivenapp/flight-csrf contains the following files

Loading the files please wait ...