Download the PHP package flarex/flareshield without Composer
On this page you can find all versions of the php package flarex/flareshield. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download flarex/flareshield
More information about flarex/flareshield
Files in flarex/flareshield
Package flareshield
Short Description Laravel-native AI security framework — protects chatbots, agents, RAG pipelines and tool-calling workflows against prompt injection, jailbreaks, system prompt leakage, RAG injection and unsafe AI output.
License MIT
Homepage https://github.com/flarex/flareshield
Informations about the package flareshield
FlareShield
Laravel-native AI security framework for the LLM era. Defend chatbots, agents, RAG pipelines and tool-calling workflows against prompt injection, jailbreaks, system prompt leakage, RAG poisoning, malicious tool usage and unsafe AI output — with a single Composer install.
Table of Contents
- Why FlareShield
- Threat Model
- Installation
- Quick Start
- Middleware
- Guarding RAG Documents
- Guarding Tool Calls
- Output Validation
- Per-Agent Configuration
- Security Levels
- Events
- Extending FlareShield
- Testing
- Architecture
- License
Why FlareShield
LLM-powered features ship in days, but the threat surface of an AI system is fundamentally different from a traditional web app. FlareShield gives Laravel developers a defense-in-depth toolkit designed specifically for that gap:
- Layered detection — heuristic, encoded-payload, HTML/Markdown, hidden-instruction, multilingual and indirect-injection scanners.
- Risk-scored verdicts — every prompt receives a normalized 0–100 score with three verdicts:
pass,flag,block. - Laravel-native — Service Provider, Facade, middleware aliases, config publishing, events, container-driven extensibility.
- Production-ready — strict types, immutable value objects, PSR-3 logging, no third-party AI dependencies, fully testable.
- Pluggable — every scanner, validator, risk engine and tool policy is bound through the container and trivially overridable.
Threat Model
FlareShield is designed to mitigate the OWASP LLM Top 10 categories most relevant to application-layer code:
| Threat | Layer |
|---|---|
| LLM01 — Prompt Injection (direct) | scanPrompt, role-override + heuristic scanners |
| LLM01 — Prompt Injection (indirect) | sanitizeDocument, indirect-injection scanner, RAG fence |
| LLM02 — Insecure Output Handling | scanOutput, output validator (HTML/script/secret leak) |
| LLM06 — Sensitive Information Disclosure | system-prompt-leak scanner + secret detection in output |
| LLM07 — Insecure Plugin / Tool Design | authorizeTool, ToolPermissionPolicy |
| LLM08 — Excessive Agency | per-agent config + confirmation flag for high-impact tools |
| LLM09 — Overreliance | structured ScanResult you can act on |
FlareShield does not ship any AI model itself. It is a deterministic, auditable, framework-side guardrail — pair it with provider-side moderation (OpenAI Moderation, Llama Guard, AWS Bedrock Guardrails, etc.) for the strongest posture.
Installation
Publish the config (optional but recommended):
The package auto-registers via Laravel's package discovery
(FlareShieldServiceProvider) and exposes the FlareShield facade.
Requirements: PHP 8.2+, Laravel 11 / 12 / 13.
Quick Start
Need the structured result instead of an exception? Use scanPrompt /
scanOutput:
Middleware
Two middleware aliases are registered:
| Alias | Class | Purpose |
|---|---|---|
flareshield.prompt |
ProtectAiPrompt |
Validates inbound user prompt |
flareshield.output |
ProtectAiOutput |
Validates outbound JSON reply |
Parameters: {field}, {agent?}. Blocked prompts return 422 with a
structured JSON body. The full ScanResult is also stashed on the request
under flareshield.prompt_result so your controller can inspect it.
Guarding RAG Documents
Indirect prompt injection is the #1 RAG threat. Sanitize every retrieved chunk before injecting it into the model context:
guardDocument() will:
- Run all configured scanners against the chunk.
- Strip HTML comments, zero-width / control characters and tag-style hidden text.
- Quote suspicious imperative phrases so the model treats them as data.
- Truncate to a configured maximum length.
- Wrap the result in clearly labeled
<<<UNTRUSTED_DOCUMENT>>>fences. - Throw
RagInjectionExceptionwhen the chunk crosses the block threshold.
Guarding Tool Calls
Configure in config/flareshield.php under the tools key.
Output Validation
scanOutput() runs the configured output_validators. The default
OutputValidator flags:
- system-prompt echoes (
"system prompt:","initial instructions:") - API keys / tokens (AWS, GitHub, OpenAI, JWTs, PEM private keys)
- Markdown image links that look like exfiltration beacons
- raw
<script>/on*=HTML
Per-Agent Configuration
Every config key can be overridden per agent:
Security Levels
| Level | Flag ≥ | Block ≥ | Use case |
|---|---|---|---|
lenient |
60 | 90 | Local dev, demos |
balanced |
40 | 70 | Production default |
strict |
25 | 50 | Finance, health, internal admin bots |
enterprise |
20 | 45 | Strict + verbose telemetry |
Tune precisely in config('flareshield.thresholds').
Events
Available events: PromptScanned, OutputScanned, ThreatDetected, ToolCallBlocked.
Extending FlareShield
Write a custom scanner:
Then register it in config/flareshield.php:
Need a different scoring strategy? Bind your own RiskEngine:
Testing
The suite uses Orchestra Testbench and exercises scanners, the risk engine, the manager and the HTTP middleware end-to-end with realistic attack payloads.
Architecture
See docs/threat-model.md for deeper dives.
License
MIT © FlareX. See LICENSE.
All versions of flareshield with dependencies
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/pipeline Version ^11.0|^12.0|^13.0
illuminate/http Version ^11.0|^12.0|^13.0
illuminate/events Version ^11.0|^12.0|^13.0