If you are interested in building your own Web Application Firewall (WAF) by leveraging the public APIs of the Shieldon library, you can create a system similar to Shieldon Firewall.
Here's an example demonstrating how Shieldon operates, providing guidance for manual Shieldon implementation on your web application.
Below is a diagram illustrating the Shieldon instance lifecycle. You don’t need to comprehend everything right now, but as you aim to customize your own components, CAPTCHA modules, and more, it will serve as a useful reference.
$kernel = new \Shieldon\Firewall\Kernel();
In this example, SQLite is used as the data driver.
$dbLocation = APPPATH . 'cache/shieldon.sqlite3';
$pdoInstance = new \PDO('sqlite:' . $dbLocation);
$kernel->setDriver(
new \Shieldon\Firewall\Driver\SqliteDriver($pdoInstance)
);
Shieldon components are rule sets for permanently allowing or denying sessions.
In this example, the TrustedBot component is loaded to allow popular search engines, thereby preventing their bots from entering the checking process - subsequent components and filters.
$kernel->setComponent(
new \Shieldon\Firewall\Component\TrustedBot()
);
If you are only using one Shieldon kernel instance on your web application, you can ignore this setting. The channel simply acts as the prefix for the names of the data tables.
$kernel->setChannel('web_project');
This setting allows only 10 sessions to view the current page. The default expiration time is 300 seconds.
$kernel->limitSession(10, 300);
You can set a Captcha service, for example, Google reCAPTCHA.
$kernel->setCaptcha(
new \Shieldon\Firewall\Captcha\Recaptcha([
'key' => '6LfkOaUUAAAAAH-AlTz3hRQ25SK8kZKb2hDRSwz9',
'secret' => '6LfkOaUUAAAAAJddZ6k-1j4hZC1rOqYZ9gLm0WQh',
])
);
$result = $kernel->run();
if ($result !== $kernel::RESPONSE_ALLOW) {
if ($kernel->captchaResponse()) {
// Unban current session.
$kernel->unban();
}
$response = $kernel->respond();
if ($response->getStatusCode() !== 200) {
$httpResolver = new \Shieldon\Firewall\HttpResolver();
$httpResolver($response);
}
}
And that's all.