Skip to content

Multi-driver adaptive security protection engine for brute-force detection, abuse prevention, and distributed IP blocking using MySQL, Redis, and MongoDB.

License

Notifications You must be signed in to change notification settings

Maatify/security-guard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

68 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Maatify Security Guard

PSR-compliant adaptive security engine for brute-force protection, abuse detection, security event tracking, high-level login-flow logic, and real-time blocking β€” powered by unified multi-driver architecture (MySQL, Redis, MongoDB).

Maatify.dev


Version PHP PHP Version

Build

Monthly Downloads Total Downloads

Stars License Status PHPStan Coverage

Changelog Security


πŸš€ Overview

Maatify Security Guard is a fully decoupled, high-performance, multi-driver security engine for:

  • Brute-force attack protection
  • Credential stuffing detection
  • IP reputation & abuse control
  • Distributed attack throttling
  • Audit-grade event tracking (Phase 4)
  • High-level login-flow decisions + auto-blocking (Phase 5)

The engine integrates seamlessly with:

  • Native PHP
  • Slim Framework
  • Laravel
  • Custom API Gateways
  • Microservices

All storage is abstracted via:

  • maatify/data-adapters β†’ Real MySQL / Redis / MongoDB
  • maatify/data-fakes β†’ Deterministic testing engine

The library guarantees:

βœ” Zero vendor lock βœ” Zero direct database clients βœ” Perfect testability βœ” Real–fake execution symmetry


πŸ“˜ Full technical documentation: ➑️ docs/README.full.md


πŸ†• What’s New (Phase 3, 4 & 5 Completed)

πŸ”₯ Phase 3 β€” Drivers Layer Completed

  • MySQLSecurityGuard
  • RedisSecurityGuard
  • MongoSecurityGuard

Each driver operates strictly through the unified AdapterInterface.


πŸ”₯ Phase 4 β€” Unified Event System Completed

  • SecurityEventDTO
  • EventFactory
  • Extensible Actions/Platforms
  • Null / Sync / PSR Logger Dispatchers
  • Automatic event emission from service

πŸ”₯ Phase 5 β€” High-Level Logic & Auto-Blocking Engine

Security Guard now includes built-in login-flow intelligence:

  • handleAttempt() API
  • Automatic blocking after threshold
  • Automatic reset on success
  • Remaining block time reporting
  • Runtime SecurityConfig
  • Dispatching event metadata for all decisions
  • Ready for future analytics layers

πŸ“¦ Installation

composer require maatify/security-guard

⚑ Quick Usage

1️⃣ Initialize the Service

$svc = new SecurityGuardService($adapter, $identifier);

2️⃣ High-Level Login Flow (Phase 5)

$result = $svc->handleAttempt($dto, success: false);

if ($result === null) {
    echo "Login successful β€” attempts reset.";
} elseif (is_int($result)) {
    echo "Failure count = {$result}";
} else {
    echo "User blocked β€” remaining {$result} seconds.";
}

3️⃣ Manual failed login attempt (legacy Phase 4 style)

$count = $svc->recordFailure($dto);

4️⃣ Attach an Event Dispatcher

$svc->setEventDispatcher(
    new SyncDispatcher([
        fn(SecurityEventDTO $e) => error_log("SECURITY EVENT: " . json_encode($e)),
    ])
);

4️⃣ Create a manual block

$svc->block(
    new SecurityBlockDTO(
        ip: '192.168.1.10',
        subject: 'user@example.com',
        type: BlockTypeEnum::MANUAL,
        expiresAt: time() + 3600,
        createdAt: time()
    )
);

6️⃣ Emit a custom security event

$event = SecurityEventFactory::custom(
    action: SecurityAction::custom('password_reset'),
    platform: SecurityPlatform::custom('api'),
    ip: '192.168.1.10',
    subject: 'user@example.com',
    context: ['method' => 'email']
);

$svc->handleEvent($event);

🧩 Key Features

βœ” Core Security Engine

  • Adaptive brute-force handling
  • Distributed blocking system
  • Manual & automatic block control

βœ” Unified DTO Layer

  • LoginAttemptDTO
  • SecurityBlockDTO
  • SecurityEventDTO

βœ” Unified Drivers (Phase 3)

  • MySQL
  • Redis
  • MongoDB

βœ” Event Pipeline (Phase 4)

  • Factory-based event normalization
  • Pluggable dispatchers
  • Extensible actions & platforms

βœ” High-Level Logic (Phase 5)

  • Auto-blocking
  • Success reset
  • Remaining block time
  • Config-driven thresholds
  • Decision-level event emission

βœ” Testing-Ready

  • Fake drivers through maatify/data-fakes
  • 100% deterministic behavior

🧱 Architecture

Application
   ↓
SecurityGuardService (Phase 5 logic)
   ↓
SecurityEventFactory β†’ Dispatchers
   ↓
SecurityGuard Drivers
   ↓
maatify/data-adapters | maatify/data-fakes

πŸ“„ Documentation

  • πŸ“˜ Full Documentation β€” docs/README.full.md
  • πŸ”¬ Examples β€” examples/Examples.md
  • 🧾 Changelog β€” CHANGELOG.md
  • πŸ” Security Policy β€” SECURITY.md

πŸ“š Development Roadmap & Phase Plan

βœ… Completed Phases

  • Phase 1 – Environment Setup
  • Phase 2 – Core Architecture & DTOs
  • Phase 3 – Driver Implementations (MySQL / Redis / MongoDB)
  • Phase 4 – Unified Event System + Dispatchers
  • Phase 5 – High-Level Logic & Auto-Blocking Engine

⏳ Upcoming

  • Phase 6 – Audit System
  • Phase 7–14 – Monitoring, Webhooks, SIEM

πŸ“… Roadmap (Updated)

Phase Description Status
1 Environment Setup βœ… Completed
2 Core Architecture & DTOs βœ… Completed
3 Driver Implementations βœ… Completed
4 Event System & Dispatchers βœ… Completed
5 High-Level Logic & Auto-Blocking Engine βœ… Completed
6 Audit System ⏳ Pending
7–14 Monitoring, Webhooks, SIEM ⏳ Pending

πŸ§ͺ Testing

composer test

πŸͺͺ License

MIT License Β© Maatify.dev


πŸ‘€ Author

Developed by Mohamed Abdulalim https://www.maatify.dev


Built with ❀️ by Maatify.dev

About

Multi-driver adaptive security protection engine for brute-force detection, abuse prevention, and distributed IP blocking using MySQL, Redis, and MongoDB.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages