Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
Co-authored-by: Aditya Tripathi <aditya@climactic.co>
This commit is contained in:
Andras Bacsai
2026-11-06 14:25:02 +01:00
committed by GitHub
co-authored by Claude Opus 5.5 peaklabs-dev Aditya Tripathi
parent b7dc2e435b
commit 033f0c84da
581 changed files with 58626 additions and 2456 deletions
+16 -13
View File
@@ -7,6 +7,7 @@ use App\Models\PrivateKey;
use App\Support\ValidationPatterns;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use OpenApi\Attributes as OA;
class SecurityController extends Controller
@@ -208,21 +209,16 @@ class SecurityController extends Controller
$request->offsetSet('description', 'Created by Coolify via API');
}
// A key that is not PEM text can be sent base64 encoded. Other text is validated as it is.
$isPrivateKeyString = str_starts_with($request->private_key, '-----BEGIN');
if (! $isPrivateKeyString) {
try {
$base64PrivateKey = base64_decode($request->private_key);
$request->offsetSet('private_key', $base64PrivateKey);
} catch (\Exception $e) {
return response()->json([
'message' => 'Invalid private key.',
], 422);
}
$base64PrivateKey = $isPrivateKeyString ? false : base64_decode($request->private_key, true);
if ($base64PrivateKey !== false) {
$request->offsetSet('private_key', $base64PrivateKey);
}
$isPrivateKeyValid = PrivateKey::validatePrivateKey($request->private_key);
if (! $isPrivateKeyValid) {
$privateKeyError = PrivateKey::validationError($request->private_key);
if ($privateKeyError) {
return response()->json([
'message' => 'Invalid private key.',
'message' => $privateKeyError,
], 422);
}
$fingerPrint = PrivateKey::generateFingerprint($request->private_key);
@@ -352,7 +348,14 @@ class SecurityController extends Controller
], 404);
}
$this->authorize('update', $foundKey);
$foundKey->update($request->only($allowedFields));
try {
$foundKey->update($request->only($allowedFields));
} catch (ValidationException $e) {
return response()->json([
'message' => $e->getMessage(),
'errors' => $e->errors(),
], 422);
}
auditLog('api.private_key.updated', [
'team_id' => $teamId,