Masquer toutes les erreurs : 404 doux, API blindée, aucune fuite PHP

- /api/bugs/ et tout chemin inconnu sous /api/ : 404 JSON propre
- 403/404 Apache : ErrorDocument vers page.php, sans page Apache brute
- fichiers internes (inc/, corps de pages, db.php, init.php...) : 404
- erreurs PHP : display_errors off, handlers exception/fatal, réponses
  JSON ou HTML discrètes, journalisation locale gitignorée
This commit is contained in:
BlackAngelTV committed 2026-09-16 11:40:43 +02:00
1 parent 3b3127bb34
commit 82168e2678
6 files changed
+196

No files matched your search

+18
View File
@@ -62,6 +62,24 @@ if (preg_match('/^paquets\/(\d+)$/', $route, $m)) {
$is404 = $pageFile === null || !is_file($pageFile);
/* Erreurs Apache « douces » : les 403/404 déroutés ici via ErrorDocument
* (voir .htaccess) rendent la page 404 du site — jamais de page Apache
* brute, jamais de détail technique. */
if (in_array((int) ($_GET['__e'] ?? 0), [403, 404], true)) {
$pageFile = null;
$is404 = true;
header('Access-Control-Allow-Origin: *');
header('Cache-Control: no-store');
/* Chemins API : réponse JSON (jamais de HTML ni de détail technique). */
$reqPath = (string) (parse_url((string) ($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH) ?: '/');
if (str_starts_with($reqPath, '/api')) {
http_response_code(404);
header('Content-Type: application/json; charset=utf-8');
header('X-Content-Type-Options: nosniff');
exit(json_encode(['ok' => false, 'error' => 'Ressource introuvable.'], JSON_UNESCAPED_UNICODE));
}
}
/* Paquets : une seule lecture DB + cache Gitea pour toute la page
(le corps ET la nav déroulante les consomment). */
$packages = fws_site_packages();