fix(cloud): unify ingest auth errors (anti-enumeration) + guard snapshot write
This commit is contained in:
parent
57cfc64548
commit
185629a4c4
1 changed files with 4 additions and 4 deletions
|
|
@ -36,13 +36,13 @@ final class IngestController
|
|||
return Response::json(['error' => 'unauthorized'], 401);
|
||||
}
|
||||
if (!Hmac::verify($secret, $nonce, $ts, $req->body(), $sig)) {
|
||||
return Response::json(['error' => 'bad_signature'], 401);
|
||||
return Response::json(['error' => 'unauthorized'], 401);
|
||||
}
|
||||
if (abs($now - (int)(float)$ts) > $this->cfg->timestampWindow()) {
|
||||
return Response::json(['error' => 'stale_timestamp'], 401);
|
||||
return Response::json(['error' => 'unauthorized'], 401);
|
||||
}
|
||||
if ($this->nonces->seen($nonce)) {
|
||||
return Response::json(['error' => 'replay'], 401);
|
||||
return Response::json(['error' => 'unauthorized'], 401);
|
||||
}
|
||||
$this->nonces->remember($nonce, $now + $this->cfg->nonceTtl());
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ final class IngestController
|
|||
$img = ImageProcessor::reencode((string)$b64);
|
||||
if (!$img['ok']) continue;
|
||||
$path = rtrim($this->cfg->snapshotDir(), '/\\') . '/' . $img['uuid'] . '.jpg';
|
||||
file_put_contents($path, $img['bytes']);
|
||||
if (file_put_contents($path, $img['bytes']) === false) continue;
|
||||
$this->snapshots->add($eventId, $img['uuid'], $img['hash']);
|
||||
}
|
||||
return Response::json(['event_id' => $eventId], 201);
|
||||
|
|
|
|||
Loading…
Reference in a new issue