Repository navigation
Replies: 2 comments
|
Not built in, but // Exporter
ExportColumn::make('id')->formatStateUsing(fn ($state) => encrypt($state)),
// Importer
ImportColumn::make('id')->castStateUsing(function ($state) {
try {
return decrypt($state);
} catch (DecryptException) {
throw new RowImportFailedException('The ID was changed.');
}
}), |
|
While Laravel’s default Depending on whether you need tamper detection (users can see the ID but cannot modify it) or full obfuscation (users cannot see the underlying integer ID), here are the two standard approaches in Filament: Option A: Signed Checksum / HMAC (Tamper-Proof ID)If the ID does not need to be secret, only protected from modification, append a truncated HMAC signature derived from // In your Exporter:
ExportColumn::make("id")
->label("Record Token")
->formatStateUsing(function ($state): string {
$hash = substr(hash_hmac("sha256", (string) $state, config("app.key")), 0, 8);
return "{$state}:{$hash}";
}),
// In your Importer:
ImportColumn::make("id")
->label("Record Token")
->castStateUsing(function ($state): int {
if (! str_contains($state, ":")) {
throw new RowImportFailedException("Invalid or missing record signature.");
}
[$id, $signature] = explode(":", $state, 2);
$expected = substr(hash_hmac("sha256", (string) $id, config("app.key")), 0, 8);
if (! hash_equals($expected, $signature)) {
throw new RowImportFailedException("Record ID was modified or tampered with.");
}
return (int) $id;
}),Option B: Deterministic Obfuscation via
|
Uh oh!
There was an error while loading. Please reload this page.
Package
Panel builder
Package Version
v4
How can we help you?
All reactions