Skip to content

Commit 8c38f4c

Browse files
committed
📝 updated readme
1 parent 8400092 commit 8c38f4c

1 file changed

Lines changed: 31 additions & 25 deletions

File tree

README.md

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,63 @@
22
<p align="center">
33
<br><br>
44
<img src="https://leafphp.netlify.app/assets/img/leaf3-logo.png" height="100"/>
5-
<h1 align="center">Leaf Security Module</h1>
5+
<h1 align="center">Leaf Anchor CSRF [BETA]</h1>
66
<br><br>
77
</p>
88

99
# Leaf PHP
1010

11-
[![Latest Stable Version](https://poser.pugx.org/leafs/anchor/v/stable)](https://packagist.org/packages/leafs/anchor)
12-
[![Total Downloads](https://poser.pugx.org/leafs/anchor/downloads)](https://packagist.org/packages/leafs/anchor)
13-
[![License](https://poser.pugx.org/leafs/anchor/license)](https://packagist.org/packages/leafs/anchor)
11+
[![Latest Stable Version](https://poser.pugx.org/leafs/csrf/v/stable)](https://packagist.org/packages/leafs/csrf)
12+
[![Total Downloads](https://poser.pugx.org/leafs/csrf/downloads)](https://packagist.org/packages/leafs/csrf)
13+
[![License](https://poser.pugx.org/leafs/csrf/license)](https://packagist.org/packages/leafs/csrf)
1414

15-
This package contains leaf's utils for deep sanitizing of data and basic security provided for your app data.
15+
> This is an experimental module. Please open an issue if you notice any bugs or malfunctions.
16+
17+
This package is leaf's implementation of CSRF default protection with leaf anchor. It comes separated from leaf anchor because it is not needed in every project you may build.
1618

1719
## Installation
1820

19-
You can easily install Leaf using [Composer](https://getcomposer.org/).
21+
You can easily install Leaf CSRF using [Composer](https://getcomposer.org/).
2022

2123
```bash
22-
composer require leafs/anchor
24+
composer require leafs/csrf
2325
```
2426

2527
## Basic Usage
2628

27-
After [installing](#installation) anchor, create an _index.php_ file.
29+
After installing leaf CSRF, leaf automatically loads the CSRF package for you, so you don't need to do anything unless you want to configure the CSRF module to match your application requirements.
30+
31+
### Using CSRF outside of leaf
2832

29-
### Base XSS protection
33+
Most leaf modules can be used outside of leaf. This module is one of these global modules. If you decide to use the CSRF module outside of leaf, you will need to manually initialize the package.
3034

3135
```php
32-
<?php
33-
require __DIR__ . "vendor/autoload.php";
36+
Leaf\Anchor\CSRF::init();
37+
```
3438

35-
$data = $_POST["data"];
36-
$data = Leaf\Anchor::sanitize($data);
39+
This function generates a token with a secret and a random hash and saves that in a session. If no session exists, the CSRF module will create a session for your app and save the token in that session,
3740

38-
echo $data;
39-
```
41+
### Config
4042

41-
This also works on arrays
43+
Just like every other leaf module, this module also allows you to customize it to behave in any way you want it to behave. Also, since this module is built on the Anchor module, the config object is shared with Anchor. To set any configuration, simply call the `config` method.
4244

43-
```php
44-
<?php
45-
require __DIR__ . "vendor/autoload.php";
45+
**Available config:**
4646

47-
$data = Leaf\Anchor::sanitize($_POST);
47+
- **SECRET_KEY** - This is the key with which the token is saved and used in your leaf app. If this is not specified, leaf uses the name `_token` as done in other frameworks like Laravel.
4848

49-
echo $data["input"];
50-
```
49+
- **SECRET** - This is the secret key used to encrypt the token. Leaf also has a default secret key set for you. Note that the secret key is attached to a set of unique numbers that not even leaf knows.
5150

52-
You may quickly test this using the built-in PHP server:
51+
- **EXCEPT** - This is an array of routes that you want to exclude from the CSRF protection.
5352

54-
```bash
55-
php -S localhost:8000
53+
- **METHODS** - This is an array of HTTP methods to apply CSRF protection to. By default, leaf uses `["POST", "PUT", "PATCH", "DELETE"]`
54+
55+
```php
56+
use Leaf\Anchor\CSRF;
57+
58+
CSRF::config([
59+
"METHODS" => ["GET"],
60+
"EXCEPT" => ["/"],
61+
]);
5662
```
5763

5864
Built with ❤ by [**Mychi Darko**](https://mychi.netlify.app)

0 commit comments

Comments
 (0)