Correggi bug di sicurezza e integrita' dei dati
I due piu' gravi potevano causare perdita di dati silenziosa. AppServiceProvider chiamava key:generate --force a ogni richiesta quando APP_KEY risultava vuota. Poiche' nome e cognome dei proclamatori sono cifrati con quella chiave, ogni riga scritta sotto una chiave poi sostituita diventava irrecuperabile. La chiave e' ora risolta una sola volta all'avvio del container e il provider solleva un'eccezione se manca, invece di rigenerarla. importTerritoryPdfFolder() caricava i PDF, costruiva l'elenco dei file e poi lo scartava senza mai accodare il job: nessun errore, nessun territorio aggiornato, e i file restavano su disco a crescita illimitata perche' la pulizia viveva solo nel finally del job mai eseguito. Sicurezza: - i permessi non venivano riapplicati alle richieste /livewire/update, per cui un permesso revocato restava attivo fino al reload della pagina - host header injection: nginx passava l'Host del client come X-Forwarded-Host e Laravel si fidava di tutti i proxy, abbastanza per far generare a route() link verso domini arbitrari, inclusi i PDF pubblici che contengono un codice di accesso valido - lo schema forwarded e' ora deciso dal server e non dall'header del client - campagna_id in Rientra e' #[Locked]: era derivato lato server ma manipolabile dal client, permettendo di conteggiare un rientro su una campagna arbitraria - sortField del registro passava non validato a orderBy(), con 500 su colonna inesistente - SESSION_SECURE_COOKIE ora vale true fuori da local - limiti su dimensione e numero di voci negli import ZIP Integrita' e prestazioni: - il default di assignment_link_ttl_hours era rimasto 24 dopo la conversione da ore a mesi: i link PDF pubblici duravano due anni invece di uno mese - il seeder usava syncPermissions(), che a un secondo giro azzerava i permessi personalizzati dei ruoli; ora e' additivo - pdftoppm senza timeout poteva bloccare il worker indefinitamente - nomi file deterministici nell'import: "1 A" e "1-A" scrivevano sullo stesso PDF, sovrascrivendosi - Setting::flushCache() dopo le cancellazioni massive, che non emettono eventi e lasciavano la cache puntata a una riga inesistente - riga settings creata dal seeder, per evitare due singleton concorrenti - rimosse due migrazioni ridondanti che rompevano migrate:rollback - indici su assigned_at, (attivo, deleted_at) e deleted_at - risolti gli N+1 negli elenchi territori e proclamatori Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Livewire\Assegnazioni;
|
||||
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Component;
|
||||
use App\Models\Assegnazione;
|
||||
use App\Models\Campagna;
|
||||
@@ -11,7 +12,14 @@ class Rientra extends Component
|
||||
public Assegnazione $assegnazione;
|
||||
public string $returned_at = '';
|
||||
public bool $showCampaignPrompt = false;
|
||||
|
||||
// Derived server-side by checkCampaign() and never bound in the view.
|
||||
// Without #[Locked] the client can inject an arbitrary campaign id into
|
||||
// the update payload and have the assignment counted toward a campaign it
|
||||
// has no date overlap with (or hit an FK violation with a bogus id).
|
||||
#[Locked]
|
||||
public ?int $campagna_id = null;
|
||||
|
||||
public bool $counted_in_campaign = false;
|
||||
|
||||
public function mount(Assegnazione $assegnazione)
|
||||
@@ -62,6 +70,12 @@ class Rientra extends Component
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
// mount() rejects an already-returned assignment, but the component
|
||||
// state persists across requests — two open tabs would both submit and
|
||||
// the second would overwrite returned_at/returned_by and log a
|
||||
// duplicate activity entry. Re-check against the current row.
|
||||
abort_if($this->assegnazione->fresh()?->returned_at !== null, 409, 'Assegnazione già rientrata.');
|
||||
|
||||
$returnDate = \Carbon\Carbon::parse($this->returned_at);
|
||||
|
||||
$this->assegnazione->update([
|
||||
|
||||
@@ -68,7 +68,12 @@ class ProclamatoreIndex extends Component
|
||||
|
||||
public function render()
|
||||
{
|
||||
$query = Proclamatore::query();
|
||||
// withCount rather than letting the view call
|
||||
// ->assegnazioni()->aperte()->count() per row, which issued one
|
||||
// COUNT(*) per displayed proclamatore on every render.
|
||||
$query = Proclamatore::query()->withCount([
|
||||
'assegnazioni as assegnazioni_aperte_count' => fn ($q) => $q->whereNull('returned_at'),
|
||||
]);
|
||||
|
||||
if ($this->search !== '') {
|
||||
// In-memory filter because nome/cognome are encrypted
|
||||
|
||||
@@ -54,8 +54,26 @@ class Registro extends Component
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Columns that may be sorted on.
|
||||
*
|
||||
* $sortField reaches orderBy() directly, and it is a public Livewire
|
||||
* property, so the client controls it. Laravel's grammar prevents SQL
|
||||
* injection, but an unknown column still raises "Column not found" and
|
||||
* returns a 500 — trivially triggerable from the browser console.
|
||||
*/
|
||||
private const SORTABLE_FIELDS = [
|
||||
'territorio_numero',
|
||||
'assigned_at',
|
||||
'returned_at',
|
||||
];
|
||||
|
||||
public function sortBy(string $field)
|
||||
{
|
||||
if (! in_array($field, self::SORTABLE_FIELDS, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->sortField === $field) {
|
||||
$this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc';
|
||||
} else {
|
||||
@@ -179,13 +197,19 @@ class Registro extends Component
|
||||
$query->whereHas('territorio', fn($q) => $q->where('tipologia_id', $this->filtroTipologia));
|
||||
}
|
||||
|
||||
if ($this->sortField === 'territorio_numero') {
|
||||
$dir = $this->sortDirection === 'asc' ? 'ASC' : 'DESC';
|
||||
// Re-check here too: sortBy() guards the action, but the property can
|
||||
// also be set directly in a Livewire update payload.
|
||||
$sortField = in_array($this->sortField, self::SORTABLE_FIELDS, true)
|
||||
? $this->sortField
|
||||
: 'territorio_numero';
|
||||
$dir = $this->sortDirection === 'asc' ? 'ASC' : 'DESC';
|
||||
|
||||
if ($sortField === 'territorio_numero') {
|
||||
$query->orderByRaw(
|
||||
"CAST((SELECT numero FROM territori WHERE territori.id = assegnazioni.territorio_id) AS UNSIGNED) $dir"
|
||||
);
|
||||
} else {
|
||||
$query->orderBy($this->sortField, $this->sortDirection);
|
||||
$query->orderBy($sortField, $dir);
|
||||
}
|
||||
|
||||
// In-memory search for encrypted proclamatore fields / territorio numero
|
||||
|
||||
@@ -72,6 +72,11 @@ class XmlExchange extends Component
|
||||
|
||||
$this->pdfFolder = [];
|
||||
|
||||
$this->dispatchPdfImport(
|
||||
$importId,
|
||||
$storedFiles,
|
||||
'Cartella ricevuta: ' . count($storedFiles) . ' PDF in coda.'
|
||||
);
|
||||
}
|
||||
|
||||
public function refreshPdfImportStatus(): void
|
||||
@@ -197,6 +202,12 @@ class XmlExchange extends Component
|
||||
AnnoTeocratico::query()->delete();
|
||||
Setting::query()->delete();
|
||||
|
||||
// The mass delete above fires no model events, so Setting's
|
||||
// memoized instance still points at the deleted row. Without this
|
||||
// the update() below would target a nonexistent id, match zero
|
||||
// rows, and silently leave the app with no settings at all.
|
||||
Setting::flushCache();
|
||||
|
||||
$settingsNode = $xml->settings;
|
||||
if ($settingsNode) {
|
||||
Setting::instance()->update([
|
||||
|
||||
@@ -123,7 +123,16 @@ class TerritorioIndex extends Component
|
||||
|
||||
public function render()
|
||||
{
|
||||
$query = Territorio::with(['zona', 'tipologia', 'assegnazioneCorrente.proclamatore']);
|
||||
// ultimaAssegnazione is eager-loaded because getGiorniGiacenzaAttribute()
|
||||
// and is_prioritario read it for every row — and this query fetches the
|
||||
// whole table (pagination happens in memory below), so lazy-loading it
|
||||
// meant one extra query per territory on every render.
|
||||
$query = Territorio::with([
|
||||
'zona',
|
||||
'tipologia',
|
||||
'assegnazioneCorrente.proclamatore',
|
||||
'ultimaAssegnazione',
|
||||
]);
|
||||
|
||||
if ($this->search) {
|
||||
$search = $this->search;
|
||||
|
||||
Reference in New Issue
Block a user