fix(cloud): unify ingest auth errors (anti-enumeration) + guard snapshot write

This commit is contained in:
유창욱 2026-07-12 00:07:42 +09:00
parent 57cfc64548
commit 185629a4c4

View file

@ -36,13 +36,13 @@ final class IngestController
return Response::json(['error' => 'unauthorized'], 401); return Response::json(['error' => 'unauthorized'], 401);
} }
if (!Hmac::verify($secret, $nonce, $ts, $req->body(), $sig)) { 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()) { 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)) { 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()); $this->nonces->remember($nonce, $now + $this->cfg->nonceTtl());
@ -54,7 +54,7 @@ final class IngestController
$img = ImageProcessor::reencode((string)$b64); $img = ImageProcessor::reencode((string)$b64);
if (!$img['ok']) continue; if (!$img['ok']) continue;
$path = rtrim($this->cfg->snapshotDir(), '/\\') . '/' . $img['uuid'] . '.jpg'; $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']); $this->snapshots->add($eventId, $img['uuid'], $img['hash']);
} }
return Response::json(['event_id' => $eventId], 201); return Response::json(['event_id' => $eventId], 201);