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.
Solutions to common issues when using the ArtisanPack Security package.
Problem: Package artisanpackui/security not found
Solution:
composer.json has the correct repository configuredcomposer clear-cache
composer update
Problem: Config file not found at config/artisanpack/security.php
Solution:
php artisan vendor:publish --provider="ArtisanPackUI\Security\SecurityServiceProvider" --tag="config"
If already published but missing, check:
php artisan vendor:publish --provider="ArtisanPackUI\Security\SecurityServiceProvider" --tag="config" --force
Problem: Migration errors when running php artisan migrate
Solution:
php artisan migrate:status
# Reset and re-run (DEVELOPMENT ONLY)
php artisan migrate:fresh
# Or publish migrations to customize
php artisan vendor:publish --provider="ArtisanPackUI\Security\SecurityServiceProvider" --tag="migrations"
Problem: Valid credentials are rejected
Possible Causes & Solutions:
// Verify password hash
$user = User::where('email', 'test@example.com')->first();
var_dump(Hash::check('password', $user->password));
php artisan user:unlock test@example.com
// Clear rate limiting
RateLimiter::clear('login:' . request()->ip());
Check config/auth.php has correct guard configuration.
Problem: User sees account locked message but shouldn't be locked
Solution:
php artisan security:check-user user@example.com
php artisan user:unlock user@example.com
// config/artisanpack/security.php
'lockout' => [
'threshold' => 5, // Increase if too sensitive
'duration_minutes' => 30,
],
Problem: OAuth redirect returns error
Solutions:
# .env
GOOGLE_CALLBACK_URL=https://yourapp.com/auth/google/callback
php artisan tinker
>>> config('services.google')
Ensure HTTPS in production (required by most providers)
Clear config cache:
php artisan config:clear
Problem: SAML authentication fails
Solutions:
# Check certificate validity
openssl x509 -in /path/to/cert.pem -text -noout
Check SAML metadata matches IDP configuration
Enable SAML debugging:
'saml' => [
'debug' => true,
],
Problem: 2FA setup shows broken image
Solutions:
composer require bacon/bacon-qr-code
php -m | grep -E 'gd|imagick'
Problem: Valid TOTP codes are rejected
Solutions:
# Check server time
date
# Sync with NTP
sudo ntpdate -s time.nist.gov
'totp' => [
'window' => 2, // Allow codes from adjacent periods
],
// Verify stored secret
$user->two_factor_secret // Should be base32 encoded
Problem: User has no recovery codes left
Solution:
# Regenerate recovery codes
php artisan 2fa:regenerate-recovery user@example.com --show
Or programmatically:
use ArtisanPackUI\Security\Facades\TwoFactor;
$codes = TwoFactor::regenerateRecoveryCodes($user);
Problem: Users required to set up 2FA when they shouldn't be
Solution:
Check enforcement configuration:
'enforcement' => [
'mode' => 'optional', // Not 'required'
'required_roles' => ['admin'], // Check user's role
],
Problem: Users logged out unexpectedly
Solutions:
// config/session.php
'lifetime' => 120, // Minutes
// config/artisanpack/security.php
'timeouts' => [
'idle_minutes' => 30,
'absolute_minutes' => 480,
'extend_on_activity' => true,
],
Ensure AJAX requests include session cookies
Check session driver:
SESSION_DRIVER=database # More reliable than file
Problem: Legitimate users getting logged out with "Session invalid" errors
Solutions:
'binding' => [
'ip_address' => [
'strictness' => 'none', // Or 'subnet'
],
],
Ensure X-Forwarded-For header is trusted:
// In TrustProxies middleware
protected $proxies = '*';
'user_agent' => [
'strictness' => 'browser_only', // Not 'exact'
],
Problem: Users constantly logging out other devices
Solution:
Increase concurrent session limit:
'concurrent_sessions' => [
'max_sessions' => 10, // Increase from default
],
Problem: API requests return 401 Unauthorized
Solutions:
curl -H "Authorization: Bearer YOUR_TOKEN_HERE" https://api.example.com/user
$token = PersonalAccessToken::findToken('your-token');
$token->expires_at; // Check expiration
Route::middleware('token.ability:read')->get('/posts', ...);
Problem: Token can access routes it shouldn't
Solutions:
Route::middleware(['auth:sanctum', 'token.ability:write'])->...
$token = $user->createApiToken('name', ['read']); // Only read ability
Problem: User has new role but old permissions
Solution:
Clear the RBAC cache:
php artisan security:clear-cache --roles
Or programmatically:
use ArtisanPackUI\Security\Facades\RBAC;
RBAC::clearCache();
Problem: $user->hasPermission('something') always returns false
Solutions:
php artisan permission:list
php artisan role:list --with-permissions
$user->roles->pluck('name');
Problem: Super admin still denied access
Solution:
Verify super admin role is configured:
'rbac' => [
'super_admin_role' => 'super-admin', // Check this matches
],
And user has this exact role:
$user->hasRole('super-admin'); // Must match exactly
Problem: Console shows CSP violations, functionality broken
Solutions:
<script nonce="{{ cspNonce() }}">
// Your code
</script>
'directives' => [
'script-src' => ["'self'", "'nonce'", 'https://cdn.example.com'],
],
'csp' => [
'report_only' => true,
],
Problem: Google Analytics, Stripe, etc. not working
Solution:
Add required sources. See CSP Framework Guide for common configurations.
Example for Google Analytics:
'script-src' => [
"'self'", "'nonce'",
'https://www.google-analytics.com',
'https://www.googletagmanager.com',
],
Problem: Livewire components fail with CSP enabled
Solution:
Ensure nonces are applied to Livewire scripts:
// Livewire v3 handles this automatically with nonces
// For v2, you may need:
'script-src' => ["'self'", "'nonce'", "'unsafe-eval'"], // unsafe-eval for Alpine
Problem: Every file upload fails validation
Solutions:
'allowedMimeTypes' => [
'image/jpeg', 'image/png', // Ensure your types are here
],
'maxFileSize' => 10 * 1024 * 1024, // 10MB
; php.ini
upload_max_filesize = 10M
post_max_size = 10M
Problem: Clean files flagged as malware
Solutions:
'malwareScanning' => [
'async' => true,
'quarantinePath' => storage_path('app/quarantine'),
],
php artisan files:scan-quarantine --list
php artisan files:scan-quarantine --release=file_id
Problem: File download URLs return 403
Solutions:
'serving' => [
'signedUrlExpiration' => 60, // Increase if needed
],
Verify route is configured correctly
Check file exists in storage
Problem: Pages load slowly after adding security middleware
Solutions:
'rbac' => [
'cache' => true,
'cache_ttl' => 3600,
],
'logging' => [
'events' => [
'authentication' => true,
'authorization' => false, // Disable verbose logging
],
],
'malwareScanning' => [
'async' => true,
],
Problem: Memory exhaustion with security features
Solutions:
'metrics' => [
'retention_days' => 30, // Reduce from 90
],
php artisan security:metrics-cleanup --days=30
php artisan compliance:cleanup
SESSION_DRIVER=redis
CACHE_DRIVER=redis
Problem: Errors after package upgrade
Solutions:
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan security:clear-cache --all
php artisan migrate
cp config/artisanpack/security.php config/artisanpack/security.php.bak
php artisan vendor:publish --tag="config" --force
For development only:
// config/artisanpack/security.php
'debug' => env('SECURITY_DEBUG', false),
SECURITY_DEBUG=true
tail -f storage/logs/security.log
php artisan security:check-config
php artisan security:audit --check=config
// Temporarily disable middleware
Route::withoutMiddleware(['csp', 'security.headers'])->group(...);
If you can't resolve an issue:
How can I help you explore Laravel packages today?