Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Security Laravel Package

artisanpack-ui/security

Core Laravel security toolkit for ArtisanPack UI: sanitization, escaping (Laminas Escaper), KSES filtering, validation rules, security/CSP middleware, CSP builder with nonce & reporting, rate limiting, audit/scan commands, and testing helpers.

View on GitHub
Deep Wiki
Context7

ArtisanPack UI Security

Latest Version on Packagist

The core Laravel security toolkit in the ArtisanPack UI ecosystem. Focused on input sanitization, output escaping, KSES filtering, security headers, XSS protection, basic rate limiting, and Content Security Policy.

Security 2.0 — core-only. Authentication, 2FA, RBAC, file uploads, analytics, and compliance have moved to dedicated sibling packages. See UPGRADE.md for migrating from 1.x.

What's in this package

  • SanitizationsanitizeEmail, sanitizeUrl, sanitizeText, sanitizeInt, sanitizeArray, …
  • EscapingescHtml, escAttr, escUrl, escJs, escCss (Laminas Escaper backed)
  • KSES filteringkses() WordPress-style allowed-tag filtering
  • Validation rulesNoHtml, SecureUrl
  • Middlewarecsp, security.headers, xss.protection, api.security, api.rate_limit
  • Content Security Policy — nonce generator, policy builder, presets, violation reporting endpoint, CSP dashboard Livewire component (optional — requires livewire/livewire), Artisan commands (csp:test, csp:stats, csp:prune, security:generate-csp)
  • Security audit commandssecurity:audit, security:scan, security:baseline, security:benchmark, security:check-config, security:test-headers, security:scan-deps
  • Testing infrastructure — OWASP scanner, configuration scanner, penetration testing helpers, performance benchmarks, report generators

What's NOT in this package (sibling packages)

Capability Package
Authentication, 2FA, password complexity, breach checking, account lockout, advanced sessions artisanpack-ui/security-auth
WebAuthn / FIDO2, SSO (SAML/OIDC), social auth, biometrics, device fingerprinting artisanpack-ui/security-advanced-auth
Roles + permissions (Blade directives, Gate integration, Artisan commands) artisanpack-ui/rbac
Secure uploads, malware scanning (ClamAV / VirusTotal), upload rate limiting artisanpack-ui/secure-uploads
Security event logging, anomaly detection, threat intel, SIEM export, dashboards artisanpack-ui/security-analytics
GDPR / CCPA / LGPD — consent, DSR, DPIA, data minimization, retention artisanpack-ui/compliance

Installation

composer require artisanpack-ui/security

Publish the config:

php artisan vendor:publish --tag=security-config

Quick Start

use ArtisanPackUI\Security\Facades\Security;

$cleanEmail = Security::sanitizeEmail($userEmail);
echo Security::escHtml($userContent);

Or use the global helpers:

$cleanEmail = sanitizeEmail($userEmail);
echo escHtml($userContent);

Middleware

Route::middleware(['csp', 'security.headers', 'xss.protection'])->group(function () {
    // ...
});

Route::middleware('api.rate_limit:api')->group(function () {
    // ...
});

CSP nonces in Blade

<script @csp_nonce>
    // ...
</script>

Hooks

The package fires a small set of artisanpack-ui/hooks filters and actions so host apps can extend sanitization, escaping, KSES, and CSP handling without subclassing. Register subscribers with addFilter() / addAction().

Hook Type When it fires Payload
ap.security.sanitizedInput filter Wraps the return of every Security::sanitize* method (email, url, filename, password, int, date, datetime, float, array, text). sanitizeArray fires text per element before firing array on the whole result. (mixed $value, string $type, mixed $original)$type is the sanitizer name (email, url, filename, password, int, date, datetime, float, array, text)
ap.security.escapedOutput filter Wraps the return of every Security::esc* method (string $value, string $context, string $original)$context is one of html, attr, url, js, css
ap.security.ksesAllowedTags filter At the start of Security::kses() only when the caller uses the default $config = 1; a non-empty return overrides htmLawed's element whitelist for that call. Explicit non-default $config bypasses this hook so caller intent isn't silently overridden. (array $allowedTags) — lowercase element names, e.g. ['a', 'p', 'strong']
ap.security.csp.directives filter Inside CspPolicyService::getPolicy() before the header is serialized; the mutated array is what gets serialized (array<string, array<string>|bool> $directives, Illuminate\Http\Request $request)
ap.security.csp.violationHandled action At the end of CspViolationHandler::handle() when a violation was stored (csp.reporting.storeViolations = true) (ArtisanPackUI\Security\Models\CspViolationReport $report)

Security note. ap.security.sanitizedInput and ap.security.escapedOutput subscribers receive the already sanitized/escaped value and can return anything — including the untouched original — which effectively lets them weaken the guarantees this package provides. Only register callbacks you fully trust, and prefer narrowing (further sanitization) over broadening. The same applies to ap.security.ksesAllowedTags: a subscriber that returns a permissive tag list expands the attack surface of every kses() call in the app.

Example:

// Force every escaped URL through your own allowlist before it's emitted.
addFilter( 'ap.security.escapedOutput', function ( string $value, string $context, string $original ): string {
    if ( $context !== 'url' ) {
        return $value;
    }

    return app( UrlAllowlist::class )->passes( $original ) ? $value : '#blocked';
} );

// Ship every stored CSP violation into your own alerting queue.
addAction( 'ap.security.csp.violationHandled', function ( CspViolationReport $report ): void {
    SecurityAlerts::dispatch( $report );
} );

Documentation

Requirements

  • PHP 8.2+
  • Laravel 10 / 11 / 12 / 13 (Laravel 13 requires PHP 8.3+)

Sibling packages

Package Scope
artisanpack-ui/security-full Meta-package — pulls in the full security suite (all six packages below) in a single require
artisanpack-ui/rbac Roles, permissions, hierarchy, Blade directives, Gate integration
artisanpack-ui/security-auth 2FA, password complexity, account lockout, sessions
artisanpack-ui/security-advanced-auth WebAuthn, SSO, social login, biometric, device fingerprinting
artisanpack-ui/secure-uploads File validation, malware scanning, signed-URL serving
artisanpack-ui/security-analytics Event logging, anomaly detection, SIEM, dashboards
artisanpack-ui/compliance GDPR / CCPA / LGPD consent, data subject rights, DPIA, retention, monitoring

License

MIT — see LICENSE.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views