From 960cee4be4a0548d81477b608631973d9ac9001a Mon Sep 17 00:00:00 2001 From: Eddy Date: Mon, 6 Jul 2026 15:24:42 +0200 Subject: [PATCH] Bericht-API: SSO-Migration auf awlauth (JWT -> awl_sso-Cookie) - _inc.php: api_authenticate() nutzt awlauth_require(bericht,read) inkl. same-origin-CSRF; CORS (Access-Control-Allow-Origin:*) entfernt (mit Cookies unzulaessig + bei same-origin ueberfluessig). - auth.php: Login ueber awlauth_login/issue -> HttpOnly-Cookie awl_sso, kein Token mehr im Body. - photo.php/pdf.php: GET-Binaer ueber awlauth_verify (kein CSRF, da auch per window.location/ geladen); Bearer/jwt-Query-Auth entfernt. - shipments.php: unveraendert (nutzt api_authenticate -> awlauth_require). - neu: logout.php (Single-Logout), verify.php (sliding session). - _jwt.php geloescht (JWT vollstaendig abgeloest). [deploy] --- api/_inc.php | 51 +++++++++------------------------- api/_jwt.php | 74 -------------------------------------------------- api/auth.php | 54 +++++++++--------------------------- api/logout.php | 12 ++++++++ api/pdf.php | 40 ++++++++------------------- api/photo.php | 47 ++++++++------------------------ api/verify.php | 25 +++++++++++++++++ 7 files changed, 87 insertions(+), 216 deletions(-) delete mode 100644 api/_jwt.php create mode 100644 api/logout.php create mode 100644 api/verify.php diff --git a/api/_inc.php b/api/_inc.php index a8a84c6..3d68999 100644 --- a/api/_inc.php +++ b/api/_inc.php @@ -1,10 +1,9 @@ fetch((int) $payload['sub']) <= 0) { - api_fail('User nicht gefunden', 401); - } - if (empty($u->statut)) { - api_fail('User deaktiviert', 401); - } - $u->loadRights(); - $user = $u; - - if (!$user->hasRight('bericht', 'read')) { - api_fail('Keine Bericht-Rechte', 403); + if (!dol_include_once('/awlauth/lib/awlauth.lib.php') || !function_exists('awlauth_require')) { + api_fail('SSO-Modul (awlauth) nicht verfügbar', 500); } + $user = awlauth_require('bericht', 'read'); // CSRF + 401/403 + exit inklusive return $user; } diff --git a/api/_jwt.php b/api/_jwt.php deleted file mode 100644 index 142fcd7..0000000 --- a/api/_jwt.php +++ /dev/null @@ -1,74 +0,0 @@ - 'HS256', 'typ' => 'JWT'); - $h = bericht_b64url_encode(json_encode($header)); - $p = bericht_b64url_encode(json_encode($payload)); - $sig = hash_hmac('sha256', $h.'.'.$p, bericht_jwt_secret(), true); - return $h.'.'.$p.'.'.bericht_b64url_encode($sig); -} - -function bericht_jwt_decode($token) -{ - $parts = explode('.', $token); - if (count($parts) !== 3) return null; - list($h, $p, $s) = $parts; - $expected = bericht_b64url_encode(hash_hmac('sha256', $h.'.'.$p, bericht_jwt_secret(), true)); - if (!hash_equals($expected, $s)) return null; - $payload = json_decode(bericht_b64url_decode($p), true); - if (!is_array($payload)) return null; - if (isset($payload['exp']) && $payload['exp'] < time()) return null; - return $payload; -} - -/** - * Liest und validiert das Authorization: Bearer Header. - * @return array|null decoded payload - */ -function bericht_jwt_from_request() -{ - $hdr = ''; - if (isset($_SERVER['HTTP_AUTHORIZATION'])) { - $hdr = $_SERVER['HTTP_AUTHORIZATION']; - } elseif (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) { - $hdr = $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; - } elseif (function_exists('apache_request_headers')) { - $h = apache_request_headers(); - if (isset($h['Authorization'])) $hdr = $h['Authorization']; - } - $token = ''; - if ($hdr && stripos($hdr, 'bearer ') === 0) { - $token = trim(substr($hdr, 7)); - } elseif (!empty($_GET['jwt'])) { - // Fallback: JWT als Query-Param (fuer , ,