kriosa-ai/kriosa-php

AI-Powered Web Application Middleware - Protect your apps from SQL injection, XSS, and 10+ attack vectors in 30 seconds

Maintainers

Package info

github.com/Kriosa-ai/kriosa-php

Homepage

Issues

Documentation

pkg:composer/kriosa-ai/kriosa-php

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

v1.0.1 2026-06-21 07:51 UTC

This package is auto-updated.

Last update: 2026-07-03 14:22:51 UTC


README

PHP Version License: MIT Version

Kriosa is an intelligent security middleware for PHP applications that acts as a smart layer between users and your application, detecting, filtering, and logging malicious activities before they reach your core code.

AI-powered Web Application Middleware built for developers and businesses. One file. Zero dependencies. Instant protection.

📋 Table of Contents

✨ Features

  • 🛡️ AI-Powered Threat Detection — Hybrid ML engine combining Random Forest and Neural Networks
  • 🔍 Comprehensive Attack Detection — SQL Injection, XSS, Path Traversal, Command Injection, Bot Detection, Rate Limiting
  • Local Fallback Protection — Pattern matching runs locally when API is unavailable
  • 🧠 Explainable AI — XAI dashboard shows exactly why a request was blocked with confidence scores
  • 🌍 Built for Africa — Optimized for African web infrastructure and threat landscape
  • 🚀 Framework Agnostic — Works with Laravel, WordPress, Symfony, and vanilla PHP
  • High Performance — Minimal overhead with ~5ms average response time
  • 📊 Real-time Analytics — Live threat scoring, confidence levels, and attack metrics
  • 🔒 Zero Dependencies — One file, drop-in protection

⚙️ How It Works

Kriosa uses a multi-layer security architecture to protect your application:

┌─────────────────────────────────────────────────────────────────┐
│                    Incoming Request                            │
└─────────────────────────┬───────────────────────────────────────┘
                          ▼
┌─────────────────────────────────────────────────────────────────┐
│              Layer 1: Local Pattern Matching                    │
│  • SQL Injection patterns                                      │
│  • XSS attack vectors                                          │
│  • Path traversal attempts                                     │
│  • Command injection                                           │
└─────────────────────────┬───────────────────────────────────────┘
                          ▼
                    [Matches?]
                    /        \
                   Yes        No
                    │          │
                    ▼          ▼
              ┌─────────┐  ┌─────────────────────────────────────┐
              │ BLOCKED │  │     Layer 2: AI Engine (API)       │
              └─────────┘  │  • Random Forest classification    │
                           │  • Neural Network analysis         │
                           │  • Confidence scoring              │
                           └──────────────┬──────────────────────┘
                                          ▼
                                   [API responds?]
                                   /             \
                                  Yes             No
                                   │               │
                                   ▼               ▼
                            ┌──────────┐   ┌─────────────────┐
                            │ AI       │   │ Layer 3:        │
                            │ Decision │   │ Fallback Logic  │
                            └──────────┘   └─────────────────┘
                                   │               │
                                   └───────┬───────┘
                                           ▼
                                   ┌───────────────┐
                                   │ ALLOW / BLOCK │
                                   └───────────────┘

Key Benefit: Even when the AI API is unavailable, the local pattern matching layer continues to block common attack vectors. Your application is never left completely unprotected.

📦 Installation

composer require kriosa-ai/kriosa-php

🚀 Quick Start

require 'vendor/autoload.php';

$kriosa = new Kriosa('sk_your_api_key');
$kriosa->protect();

One-Line Protection

kriosa_protect('sk_your_api_key');

🔧 Framework Integrations

Laravel Integration

// In app/Http/Middleware/KriosaMiddleware.php
<?php

namespace App\Http\Middleware;

use Closure;
use Kriosa;

class KriosaMiddleware
{
    public function handle($request, Closure $next)
    {
        $kriosa = new Kriosa(config('services.kriosa.key'));
        $kriosa->protect();
        
        return $next($request);
    }
}

Register the middleware:

// In app/Http/Kernel.php
protected $routeMiddleware = [
    // ...
    'kriosa' => \App\Http\Middleware\KriosaMiddleware::class,
];

Apply to routes:

Route::middleware(['kriosa'])->group(function () {
    Route::post('/upload', [UploadController::class, 'store']);
});

Vanilla PHP Integration

// At the top of your index.php or bootstrap file
require_once 'vendor/autoload.php';

$kriosa = new Kriosa('sk_your_api_key');
$kriosa->protect();

// Your application code continues here...

⚙️ Configuration

$kriosa = new Kriosa('sk_your_api_key', [
    'timeout'        => 5,           // API timeout in seconds
    'debug'          => false,       // Enable debug logging
    'fail_closed'    => false,       // Block requests if API unreachable
    'show_badge'     => true,        // Show "Protected by Kriosa" badge
    'badge_position' => 'bottom-right', // Badge position
    'trusted_ips'    => [],          // Array of IPs to always allow
    'blocked_ips'    => [],          // Array of IPs to always block
    'rate_limit'     => 100,         // Requests per minute
]);

🏭 Production Recommendations

Understanding fail_closed

The fail_closed setting determines what happens when the Kriosa API cannot be reached:

Setting Behavior
fail_closed: true Blocks requests when API is unreachable (security-first)
fail_closed: false Allows requests to proceed (availability-first)

Important: Even with fail_closed: false, the local pattern matching layer continues to block common attacks (SQLi, XSS, path traversal, command injection). Only advanced ML-based detection is affected by API unavailability.

Recommended Configurations by Use Case

Use Case fail_closed timeout Rationale
Public Routes false 3s Prioritize availability over security for public content
Authenticated Routes true 5s Protect sensitive user data and sessions
Admin Panels true 5s Maximum protection for critical areas
Payment/Checkout true 3s Financial transactions require security-first
API Endpoints true 2s APIs handle sensitive data and are common attack targets
Development false 10s Avoid blocking yourself while building

Production Example

// For authenticated routes (recommended)
$kriosa = new Kriosa('sk_your_key', [
    'fail_closed'  => true,
    'timeout'      => 5,
    'debug'        => false
]);

// For public routes
$kriosa = new Kriosa('sk_your_key', [
    'fail_closed'  => false,
    'timeout'      => 3,
    'debug'        => false
]);

Environment-Based Configuration

// Laravel example
$kriosa = new Kriosa(config('services.kriosa.key'), [
    'fail_closed' => app()->environment('production') ? true : false,
    'timeout'     => app()->environment('production') ? 5 : 10,
    'debug'       => app()->environment('local'),
]);

💬 What Developers Say

"The explainable dashboard is genuinely rare — telling me why a request was blocked with confidence scores and matched attack patterns is a lifesaver. Quick question on the config though... the fail_closed setting is the one thing people will get wrong, so I love that the docs now cover this properly."

Early Kriosa User

"One file. Zero dependencies. Instant protection. This is exactly what I needed for my Laravel apps. The local fallback means I don't have to worry about API downtime leaving me exposed."

Kriosa Beta Tester

🔑 Get Your API Key

  1. Sign up at kriosa.com
  2. Navigate to the API key section
  3. Copy your API key

📚 Documentation

Full documentation available at: kriosa.com/documentation.php

Quick Links

🆘 Support

📄 License

MIT License — see LICENSE for details.

🏆 Built with ❤️ in Cameroon 🇨🇲

Built by developers, for developers. Made in Africa, for the world.

⭐ Star us on GitHub — Your support helps us continue building better security tools for everyone.