From 7eae29eb2802f064bfcd05063127d06ec034a673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Gastinel?= <264859180+gastinelt@users.noreply.github.com> Date: Wed, 4 Nov 2026 17:01:35 +0100 Subject: [PATCH] =?UTF-8?q?forum=20:=20s=C3=A9parateur=20=C2=AB=20:=20?= =?UTF-8?q?=C2=BB=20entre=20port=C3=A9e=20et=20jeton=20de=20session=20(un?= =?UTF-8?q?=20jeton=20du=20panneau=20ne=20peut=20plus=20servir=20de=20jeto?= =?UTF-8?q?n=20du=20forum)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- forum/forum.py | 6 +++--- forum/tests/test_forum.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/forum/forum.py b/forum/forum.py index 1b81d9f..0bfffdd 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -51,7 +51,7 @@ class Forum: jeton = secrets.token_urlsafe(32) self.con.execute("DELETE FROM sessions WHERE expires_at < datetime('now')") self.con.execute("INSERT INTO sessions(id_hache, user_id, expires_at) VALUES (?, ?, datetime('now', ?))", - (self._hache(portee + jeton), user["id"], "+%d days" % jours)) + (self._hache(portee + ":" + jeton), user["id"], "+%d days" % jours)) self.con.commit() return jeton @@ -59,10 +59,10 @@ class Forum: if not jeton: return None return self.con.execute("SELECT u.* FROM sessions s JOIN users u ON u.id=s.user_id" - " WHERE s.id_hache=? AND s.expires_at > datetime('now')", (self._hache(portee + jeton),)).fetchone() + " WHERE s.id_hache=? AND s.expires_at > datetime('now')", (self._hache(portee + ":" + jeton),)).fetchone() def fermer_session(self, jeton, portee=""): - self.con.execute("DELETE FROM sessions WHERE id_hache=?", (self._hache(portee + (jeton or "")),)) + self.con.execute("DELETE FROM sessions WHERE id_hache=?", (self._hache(portee + ":" + (jeton or "")),)) self.con.commit() def noter_etat(self, etat, verifier): diff --git a/forum/tests/test_forum.py b/forum/tests/test_forum.py index e29b8e8..fda03ec 100644 --- a/forum/tests/test_forum.py +++ b/forum/tests/test_forum.py @@ -391,7 +391,7 @@ class TestConnexionGastinel(BaseHTTP): u = self.f.con.execute("SELECT * FROM users WHERE hub_id='g-42'").fetchone() self.assertEqual(u["display_name"], "Lucie") stocke = self.f.con.execute("SELECT id_hache FROM sessions WHERE user_id=?", (u["id"],)).fetchone()[0] - self.assertEqual(stocke, hashlib.sha256(jeton.encode()).hexdigest()) # seul le haché est en base + self.assertEqual(stocke, hashlib.sha256((":" + jeton).encode()).hexdigest()) # seul le haché est en base b = self.req("/", cookie="forum_session=" + jeton)[2].decode() self.assertIn("Lucie", b) self.assertIn("action='/deconnexion'", b)