fix(security, core): Auth-Pflicht für Ingest-APIs, 500er-Ursachen beheben, Agenten-Workflow
Sicherheit
- install_db.php war ohne Authentifizierung erreichbar und setzte bei jedem
Aufruf das Admin-Passwort auf einen fest im Code stehenden Wert zurück.
Jetzt Auth-Pflicht; ein Konto wird nur bei leerer Benutzertabelle angelegt.
- Stored XSS im Bugtracker-Detail-Modal: Titel, Beschreibung, Fehlermeldung,
Stacktrace und Kommentare gingen ungefiltert durch innerHTML.
- report.php, projects.php und das Veröffentlichen von Releases verlangen jetzt
zwingend ein Token. Publish war zuvor völlig ungeschützt.
- CSRF-Token in allen Formularen, Session-Regenerierung nach Login,
Drosselung fehlgeschlagener Anmeldeversuche.
- Zugangsdaten aus der Versionskontrolle entfernt (Serverdaten.txt,
config.php, .htpasswd, deploy_config.json). Historie enthält sie weiterhin,
Rotation erforderlich (siehe docs/UPGRADE.md).
- Token-Validierung nur noch über SHA-256-Hash; expires_at wird ausgewertet.
Behobene 500er
- Audit::log() war in index.php weder eingebunden noch importiert. Jeder
Klick auf "Aktivierung freigeben" endete in einem Fatal Error.
- Derselbe benannte PDO-Platzhalter mehrfach je Statement (:id in
revokeToken/deleteToken, :q siebenfach in der Volltextsuche). Bei
EMULATE_PREPARES=false ist das nicht zulässig und warf HY093.
- Migration 005 nutzte dynamisches SQL, dessen Semikolons in String-Literalen
vom alten explode(';')-Installer als Statement-Ende gelesen wurden. Sie
schlug still fehl, wodurch push_id/target_agent/tags dauerhaft fehlten.
- Monitor-Umbenennung ohne Transaktion, verschachtelte Transaktionen im
RateLimiter.
Funktionale Korrekturen
- Der Watchdog-Evaluator fehlte vollständig: Monitor-Zustände änderten sich nur
beim Eintreffen eines Heartbeats, ein ausgefallenes System blieb dauerhaft
"up". Erster Lauf auf dem Produktivsystem: 7 von 10 Monitoren waren
tatsächlich seit über einem Tag nicht erreichbar.
- Das Feld "os" fehlte im Monitor-Dialog, wurde aber gespeichert und löschte
damit bei jedem Speichern das Betriebssystem.
- Der Resolve-Dialog existierte im HTML nicht; der Button war funktionslos.
- Versionsvergleich erfolgte lexikografisch, wodurch 1.9.0 als neuer galt
als 1.10.0.
- Schreiboperationen meldeten Erfolg auch für nicht existierende IDs.
- Post/Redirect/Get gegen doppelte Einträge beim Neuladen.
Neue Struktur
- src/bootstrap.php mit PSR-4-Autoloader ersetzt die require-Ketten.
- Core: Config, Http, Csrf, ApiAuth, Logger, Migrator, ErrorReporter.
- Migrator mit zeichenweisem SQL-Parser, dc_migrations und Baseline-Verfahren,
damit bestehende Installationen keine Beispieldaten zurückbekommen.
Agenten-Workflow
- Claim/Lease: Items werden exklusiv übernommen, damit nicht zwei Agenten am
selben Problem arbeiten. action=next holt und reserviert in einem Zug.
- Idempotenz über client_ref, Deduplizierung auch für Feature Requests,
Erkennung von Regressionen, automatische Eskalation des Schweregrads.
- Strukturierter Code-Kontext (repo_url, commit_sha, file_path, line_no).
- Delta-Abfragen über updated_since, Pagination, Bulk-Update.
- Beim Veröffentlichen eines Releases schließen sich Items mit passendem
resolved_in_build selbst.
- Ausgehende Webhooks mit HMAC-Signatur, /api/health, /api/openapi.json.
- Unbehandelte Fehler meldet die Plattform in ihren eigenen Bugtracker.
WebUI
- Serverseitige Filterung mit Pagination statt Rendern aller Datensätze.
- Migrations-Schranke, Evaluator-Warnung, Übersicht aktiver Agenten.
Zeitstempel liegen in der Datenbank durchgängig in UTC und werden für die
Anzeige in die App-Zeitzone umgerechnet.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
a21536f495
commit
e7fbc85db4
@@ -1,97 +1,194 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* UpdateService API
|
||||
*
|
||||
* GET /api/updateservice/v1/check?product=myapp&version=1.0.0&channel=prod
|
||||
* GET /api/updateservice/v1/latest?product=myapp&channel=prod
|
||||
* GET /api/updateservice/v1/releases?product=myapp
|
||||
* POST /api/updateservice/v1/publish (Scope updateservice:publish)
|
||||
*
|
||||
* SICHERHEITSAENDERUNG: Das Veroeffentlichen eines Releases war vollstaendig
|
||||
* ungeschuetzt. Jeder konnte download_url und sha256_hash eines bestehenden
|
||||
* Releases ueberschreiben und damit allen Clients ein beliebiges Paket
|
||||
* unterschieben. Publish verlangt jetzt ein Token mit "updateservice:publish".
|
||||
*
|
||||
* Die Lese-Endpunkte bleiben ohne Token erreichbar, damit bereits ausgerollte
|
||||
* Client-Anwendungen weiter nach Updates suchen koennen. Sie liefern nur
|
||||
* Release-Metadaten, die ueber die Download-URL ohnehin oeffentlich sind.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
require_once __DIR__ . '/../../../../src/Core/Db.php';
|
||||
require_once __DIR__ . '/../../../../src/Modules/UpdateService/UpdateManager.php';
|
||||
require_once __DIR__ . '/../../../../src/bootstrap.php';
|
||||
|
||||
use Deploymentcenter\Core\ApiAuth;
|
||||
use Deploymentcenter\Core\Db;
|
||||
use Deploymentcenter\Core\Http;
|
||||
use Deploymentcenter\Modules\License\RateLimiter;
|
||||
use Deploymentcenter\Modules\UpdateService\UpdateManager;
|
||||
use Deploymentcenter\Modules\UpdateService\Version;
|
||||
|
||||
function sendResponse(array $data, int $statusCode = 200): void {
|
||||
http_response_code($statusCode);
|
||||
echo json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
exit;
|
||||
Http::beginJson(['GET', 'POST', 'OPTIONS'], true);
|
||||
|
||||
$db = Db::init();
|
||||
|
||||
$limiter = new RateLimiter($db, 240, 60, 'updateservice');
|
||||
if (!$limiter->check(Http::clientIp())) {
|
||||
Http::fail(429, 'rate_limited', 'Zu viele Anfragen.');
|
||||
}
|
||||
|
||||
try {
|
||||
$config = require __DIR__ . '/../../../../config/config.php';
|
||||
$pdo = Db::init($config);
|
||||
$manager = new UpdateManager($db);
|
||||
$action = resolveUpdateAction();
|
||||
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
|
||||
$method = strtoupper($_SERVER['REQUEST_METHOD'] ?? 'GET');
|
||||
switch ($action) {
|
||||
|
||||
$updateMgr = new UpdateManager($pdo);
|
||||
|
||||
// Read JSON body for POST requests if available
|
||||
$inputData = [];
|
||||
if ($method === 'POST') {
|
||||
$raw = file_get_contents('php://input');
|
||||
if (!empty($raw)) {
|
||||
$inputData = json_decode($raw, true) ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
$action = $_REQUEST['action'] ?? $inputData['action'] ?? '';
|
||||
|
||||
// Action: Publish Release (from Packager CLI)
|
||||
if ($action === 'publish_release' && $method === 'POST') {
|
||||
$product = $inputData['product_slug'] ?? $_POST['product_slug'] ?? '';
|
||||
$version = $inputData['version'] ?? $_POST['version'] ?? '';
|
||||
$channel = $inputData['channel'] ?? $_POST['channel'] ?? 'prod';
|
||||
$url = $inputData['download_url'] ?? $_POST['download_url'] ?? '';
|
||||
$hash = $inputData['sha256_hash'] ?? $_POST['sha256_hash'] ?? null;
|
||||
$gitCommit = $inputData['git_commit'] ?? $_POST['git_commit'] ?? null;
|
||||
$sizeBytes = (int)($inputData['size_bytes'] ?? $_POST['size_bytes'] ?? 0);
|
||||
$notes = $inputData['release_notes'] ?? $_POST['release_notes'] ?? null;
|
||||
$isCritical= !empty($inputData['is_critical']) || !empty($_POST['is_critical']);
|
||||
|
||||
if (empty($product) || empty($version) || empty($url)) {
|
||||
sendResponse(['error' => 'Bad Request', 'message' => 'Missing required fields: product_slug, version, download_url'], 400);
|
||||
case 'check':
|
||||
$product = Http::str('product') ?? Http::str('product_slug');
|
||||
if ($product === null) {
|
||||
Http::fail(400, 'missing_product', 'Der Parameter "product" wird benoetigt.');
|
||||
}
|
||||
|
||||
$ok = $updateMgr->addRelease($product, $version, $channel, $notes, $url, $hash, $gitCommit, $sizeBytes, null, $isCritical);
|
||||
if ($ok) {
|
||||
sendResponse(['status' => 'success', 'message' => "Release v{$version} published for {$product} ({$channel})."]);
|
||||
} else {
|
||||
sendResponse(['error' => 'Database Error', 'message' => 'Failed to store release.'], 500);
|
||||
}
|
||||
}
|
||||
$current = Http::str('version') ?? Http::str('current_version') ?? '0.0.0';
|
||||
$channel = Http::str('channel') ?? 'prod';
|
||||
|
||||
if (str_ends_with($uri, '/check') && ($method === 'GET' || $method === 'POST')) {
|
||||
$product = $_REQUEST['product'] ?? $_REQUEST['product_slug'] ?? '';
|
||||
$version = $_REQUEST['version'] ?? $_REQUEST['current_version'] ?? '0.0.0';
|
||||
$channel = $_REQUEST['channel'] ?? 'prod';
|
||||
$latest = $manager->checkUpdate($product, $current, $channel);
|
||||
|
||||
if (empty($product)) {
|
||||
sendResponse(['error' => 'Bad Request', 'message' => 'Parameter "product" is required.'], 400);
|
||||
}
|
||||
|
||||
$latest = $updateMgr->checkUpdate($product, $version, $channel);
|
||||
if ($latest) {
|
||||
sendResponse([
|
||||
'update_available' => true,
|
||||
'latest_release' => $latest
|
||||
]);
|
||||
} else {
|
||||
sendResponse([
|
||||
if ($latest === null) {
|
||||
$installed = $manager->latestRelease($product, $channel);
|
||||
Http::ok([
|
||||
'update_available' => false,
|
||||
'message' => 'Application is up to date.'
|
||||
'current_version' => $current,
|
||||
'latest_version' => $installed !== null ? $installed['version'] : $current,
|
||||
'message' => 'Anwendung ist aktuell.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (str_ends_with($uri, '/releases') && $method === 'GET') {
|
||||
$product = $_GET['product'] ?? null;
|
||||
$channel = $_GET['channel'] ?? null;
|
||||
$releases = $updateMgr->getReleases($product, $channel);
|
||||
sendResponse(['count' => count($releases), 'releases' => $releases]);
|
||||
}
|
||||
Http::ok([
|
||||
'update_available' => true,
|
||||
'current_version' => $current,
|
||||
'latest_version' => $latest['version'],
|
||||
'is_critical' => (bool)$latest['is_critical'],
|
||||
'latest_release' => $latest,
|
||||
]);
|
||||
|
||||
sendResponse(['error' => 'Not Found', 'message' => 'Endpoint not found'], 404);
|
||||
case 'latest':
|
||||
$product = Http::str('product') ?? Http::str('product_slug');
|
||||
if ($product === null) {
|
||||
Http::fail(400, 'missing_product', 'Der Parameter "product" wird benoetigt.');
|
||||
}
|
||||
|
||||
} catch (Throwable $t) {
|
||||
sendResponse(['error' => 'Server Error', 'message' => $t->getMessage()], 500);
|
||||
$release = $manager->latestRelease($product, Http::str('channel') ?? 'prod');
|
||||
if ($release === null) {
|
||||
Http::fail(404, 'no_release', sprintf('Fuer "%s" ist kein Release hinterlegt.', $product));
|
||||
}
|
||||
|
||||
Http::ok(['release' => $release]);
|
||||
|
||||
case 'releases':
|
||||
$releases = $manager->getReleases(
|
||||
Http::str('product') ?? Http::str('product_slug'),
|
||||
Http::str('channel'),
|
||||
Http::int('limit', 200)
|
||||
);
|
||||
Http::ok(['count' => count($releases), 'releases' => $releases]);
|
||||
|
||||
case 'publish':
|
||||
if (Http::method() !== 'POST') {
|
||||
Http::fail(405, 'method_not_allowed', 'Das Veroeffentlichen erwartet POST.');
|
||||
}
|
||||
|
||||
$context = ApiAuth::requireScope($db, 'updateservice:publish');
|
||||
|
||||
$product = Http::str('product_slug') ?? Http::str('product');
|
||||
$version = Http::str('version');
|
||||
$url = Http::str('download_url');
|
||||
|
||||
$missing = [];
|
||||
if ($product === null) { $missing[] = 'product_slug'; }
|
||||
if ($version === null) { $missing[] = 'version'; }
|
||||
if ($url === null) { $missing[] = 'download_url'; }
|
||||
|
||||
if ($missing !== []) {
|
||||
Http::fail(400, 'missing_fields', 'Pflichtfelder fehlen: ' . implode(', ', $missing), null, [
|
||||
'missing' => $missing,
|
||||
]);
|
||||
}
|
||||
|
||||
ApiAuth::enforceProject($context, $product);
|
||||
|
||||
// Eine Version ohne Ziffern wuerde beim Vergleich als 0.0.0 gelten und
|
||||
// die Rangfolge aller Releases dieses Produkts durcheinanderbringen.
|
||||
if (preg_match('/^v?\d+(\.\d+)*([-+].*)?$/i', $version) !== 1) {
|
||||
Http::fail(400, 'invalid_version', sprintf(
|
||||
'Version "%s" ist nicht interpretierbar. Erwartet wird eine Form wie 1.4.3, v1.4.3 oder 1.4.3-beta.1.',
|
||||
$version
|
||||
));
|
||||
}
|
||||
|
||||
$hash = Http::str('sha256_hash');
|
||||
if ($hash !== null && preg_match('/^[0-9a-f]{64}$/i', $hash) !== 1) {
|
||||
Http::fail(400, 'invalid_hash', 'sha256_hash muss 64 Hexadezimalzeichen enthalten.');
|
||||
}
|
||||
|
||||
$result = $manager->addRelease(
|
||||
$product,
|
||||
$version,
|
||||
Http::str('channel') ?? 'prod',
|
||||
Http::str('release_notes'),
|
||||
$url,
|
||||
$hash,
|
||||
Http::str('git_commit'),
|
||||
Http::int('size_bytes', 0),
|
||||
null,
|
||||
filter_var(Http::input('is_critical', false), FILTER_VALIDATE_BOOLEAN),
|
||||
$context['actor']
|
||||
);
|
||||
|
||||
Http::ok([
|
||||
'release_id' => $result['id'],
|
||||
'created' => $result['created'],
|
||||
'auto_resolved' => $result['auto_resolved'],
|
||||
'message' => sprintf(
|
||||
'Release %s (%s) fuer "%s" %s.%s',
|
||||
$version,
|
||||
Http::str('channel') ?? 'prod',
|
||||
$product,
|
||||
$result['created'] ? 'veroeffentlicht' : 'aktualisiert',
|
||||
$result['auto_resolved'] > 0
|
||||
? sprintf(' %d Bugtracker-Item(s) automatisch geschlossen.', $result['auto_resolved'])
|
||||
: ''
|
||||
),
|
||||
], $result['created'] ? 201 : 200);
|
||||
|
||||
default:
|
||||
Http::fail(404, 'unknown_action', 'Endpunkt nicht gefunden.', null, [
|
||||
'available' => ['check', 'latest', 'releases', 'publish'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bestimmt die Aktion aus dem Pfadsegment oder ?action=.
|
||||
* Feste Liste statt Teilstring-Suche.
|
||||
*/
|
||||
function resolveUpdateAction(): string
|
||||
{
|
||||
$explicit = Http::str('action');
|
||||
if ($explicit !== null) {
|
||||
// Altes Feld hiess publish_release
|
||||
return $explicit === 'publish_release' ? 'publish' : strtolower($explicit);
|
||||
}
|
||||
|
||||
$segments = array_values(array_filter(
|
||||
explode('/', trim(Http::path(), '/')),
|
||||
static fn(string $s): bool => $s !== ''
|
||||
));
|
||||
|
||||
$last = strtolower((string)end($segments));
|
||||
|
||||
return match ($last) {
|
||||
'check', 'latest', 'releases', 'publish' => $last,
|
||||
'publish_release' => 'publish',
|
||||
default => 'check',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user