Skip to content

Commit 8bb57e5

Browse files
committed
Updated readme slightly.
1 parent 1ec557f commit 8bb57e5

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@
33
This repository contains the firewall engine of Patchstack.
44
It can be implemented inside of other content management systems to provide firewall functionality.
55

6+
## Implementation ##
7+
Implementation is simple, and examples can be seen in `/tests/FirewallTest.php`
8+
9+
Example firewall rules can be seen in `/tests/data/Rules.json`
10+
11+
Example whitelist rules can be seen in `/tests/data/Whitelist.json`
12+
13+
```php
14+
use Patchstack\Processor;
15+
use Patchstack\Extensions\WordPress\Extension;
16+
17+
// Load the firewall rules, whitelist rules and settings from some place.
18+
$firewallRules = [];
19+
$whitelistRules = [];
20+
$settings = [];
21+
22+
// Setup the firewall rules processor.
23+
$firewall = new Processor(
24+
new Extension(),
25+
$firewallRules,
26+
$whitelistRules,
27+
$settings
28+
);
29+
30+
// And launch it. If a request was a hit with a firewall rule, it will automatically stop execution.
31+
$firewall->launch();
32+
```
33+
634
## Functionality ##
735
This firewall engine can parse and understand JSON based firewall rules. These JSON based firewall rules allow you to match against parameters, match against multiple conditions being true, apply mutations (e.g., JSON decode or base64 decode) to payloads and compare against output of PHP functions.
836

src/Processor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function launch($mustExit = true)
132132
return true;
133133
}
134134

135-
// Determine if we have a valid configuration password.
135+
// Determine if we have a valid configuration passed.
136136
if (!is_array($this->firewallRules) || !is_array($this->whitelistRules)) {
137137
return true;
138138
}
@@ -158,10 +158,10 @@ public function launch($mustExit = true)
158158
continue;
159159
}
160160

161-
// Transform rule object to array, then execute the firewall rule.
161+
// Execute the firewall rule.
162162
$rule_hit = $this->executeFirewall($rule['rules']);
163163

164-
// If the payload did not match the rule, continue.
164+
// If the payload did not match the rule, continue on to the next rule.
165165
if (!$rule_hit) {
166166
continue;
167167
}

0 commit comments

Comments
 (0)