Download the PHP package redaelfillali/laravel-secure-model without Composer
On this page you can find all versions of the php package redaelfillali/laravel-secure-model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download redaelfillali/laravel-secure-model
More information about redaelfillali/laravel-secure-model
Files in redaelfillali/laravel-secure-model
Package laravel-secure-model
Short Description Eloquent base model with auto-sanitized getters and setters.
License MIT
Informations about the package laravel-secure-model
Laravel Secure Model
An Eloquent base model that automatically sanitizes specified attributes on get and set, protecting your application from XSS vulnerabilities out of the box.
Features
- Automatically purifies HTML on both read (
getAttribute) and write (setAttribute) - Powered by stevebauman/purify (HTMLPurifier wrapper)
- Zero-configuration: just list the attributes to sanitize
- Supports Laravel 9, 10, 11, 12, and 13
- Supports PHP 8.1, 8.2, 8.3, and 8.4
Requirements
| Dependency | Version |
|---|---|
| PHP | ^8.1 | ^8.2 | ^8.3 | ^8.4 |
| Laravel | ^9.0 | ^10.0 | ^11.0 | ^12.0 | ^13.0 |
| stevebauman/purify | ^6.3 |
Installation
The service provider is registered automatically via Laravel's package auto-discovery.
Optionally publish the Purify configuration to customise the HTML rules:
Usage
Extend SecureModel instead of the default Eloquent Model and declare the attributes you want automatically sanitized in the $sanitizeAttributes array:
That's it — any XSS payloads stored in or read from the listed attributes will be stripped automatically:
Attributes not listed in $sanitizeAttributes are left completely untouched, so only the fields you care about are affected.
How it works
SecureModel overrides two Eloquent methods:
| Method | Behaviour |
|---|---|
setAttribute($key, $value) |
Sanitizes the value before it is stored in the model's attribute bag |
getAttribute($key) |
Sanitizes the value when it is retrieved from the model |
Only attributes listed in $sanitizeAttributes and whose value is a string are passed through Purify::clean(). All other types (int, null, arrays …) are returned as-is.
Testing
Tests are written with Pest and use Orchestra Testbench for a full in-process Laravel environment.
License
The MIT License (MIT). See LICENSE for details.
All versions of laravel-secure-model with dependencies
illuminate/database Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^9.0|^10.0|^11.0|^12.0|^13.0
stevebauman/purify Version ^6.3