jeffersongoncalves / laravel-ccpa-audit-log
CCPA/CPRA audit log for Laravel: tamper-evident, hash-chained record of who viewed, changed, exported or deleted personal information.
Package info
github.com/jeffersongoncalves/laravel-ccpa-audit-log
pkg:composer/jeffersongoncalves/laravel-ccpa-audit-log
Requires
- php: ^8.2
- illuminate/console: ^12.0|^13.0
- illuminate/contracts: ^12.0|^13.0
- illuminate/database: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- jeffersongoncalves/laravel-ccpa: ^1.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- jeffersongoncalves/pest-plugin-database-migrations: ^1.0
- larastan/larastan: ^3.0
- laravel/pint: ^1.24
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The California Consumer Privacy Act, as amended by the CPRA, requires reasonable security procedures for personal information (Cal. Civ. Code §1798.100(e)) and makes businesses liable for breaches caused by failing to keep them (§1798.150). This package keeps an audit trail of who viewed, changed, exported or anonymized personal data, built on laravel-ccpa's #[PersonalData] declarations.
- Column names, never values: the log itself doesn't copy the data it protects.
- Append-only and hash-chained: each entry carries an HMAC of the previous one.
ccpa:audit-verifytells you if an entry was altered, removed from the middle or inserted. - Automatic where Eloquent can see it: changes to personal data columns, deletions, and every anonymization (consumer deletion request, retention).
This package gives you tooling. It does not make you compliant on its own.
Installation
composer require jeffersongoncalves/laravel-ccpa-audit-log
php artisan vendor:publish --tag="ccpa-audit-log-migrations"
php artisan migrate
Set CCPA_HASH_KEY (see laravel-ccpa). The chain falls back to APP_KEY, and rotating the key makes older entries fail verification.
Usage
Add the trait to the models that hold personal data:
use JeffersonGoncalves\CcpaAuditLog\Concerns\AuditsPersonalData; #[PersonalData('email', anonymize: AnonymizeStrategy::Hash)] class Customer extends Model implements HasPersonalData { use AuditsPersonalData; use InteractsWithPersonalData; }
- Updating a declared column logs
updatedwith the column names. Other columns are ignored. - Deleting the model logs
deleted. anonymizePersonalData(), called directly, by laravel-ccpa-requests or by laravel-ccpa-retention, logsanonymized. That save also logsupdatedfirst.
Eloquent can't tell when data is read, so log access where you show it:
$customer->auditAccess('Support ticket #42'); // all declared columns $customer->auditAccess('Billing', ['email']); CcpaAuditLog::record('exported', $customer, ['email'], 'Answer a request to know', ['ticket' => 42]);
The actor is the authenticated user unless you pass actor:. The IP address and user agent of the request are stored too (store_request). They are personal data, so they stay out of the hash chain and can be anonymized without breaking it.
Verifying
php artisan ccpa:audit-verify
// routes/console.php Schedule::command('ccpa:audit-verify')->daily();
The oldest entry you kept is trusted as the start of the chain, so deleting old entries from the start keeps the rest verifiable. A gap in the middle does not.
Testing
composer test
Changelog
See CHANGELOG.
License
The MIT License (MIT). See License File.
