Forum : Markdown durci (caractères de contrôle, ReDoS), aperçu réservé à creer_sujet

- markdown_sur : \x00 et caractères de contrôle retirés avant le rendu, marqueur de code
  inconnu laissé tel quel (plus d'IndexError) ; TITRE sans retour arrière, GRAS/ITALIQUE
  en classes sans chevauchement, lignes coupées à 2000 caractères.
- Forum._texte refuse les caractères de contrôle (sauf \n, \r, \t).
- /apercu-md exige le droit creer_sujet (403 sinon).
- Tests : caractères de contrôle, entrées pièges chronométrées, droits de l'aperçu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
Théo GastineletClaude Opus 5.5 a révisé 2026-11-06 00:46:32 +01:00
1 Parent c0d43e4e59
révision b8c221b63e
4 fichiers modifiés
+44 -6

Aucun fichier ne correspond à votre recherche

+24
Voir le fichier
@@ -37,6 +37,28 @@ class TestMarkdown(unittest.TestCase):
self.assertIn("<ol><li>a</li><li>b</li></ol>", h)
self.assertIn("<code>**pas gras**</code>", markdown_sur.rendu("`**pas gras**`"))
def test_caracteres_de_controle(self):
h = markdown_sur.rendu("a \x005\x00 `c` \x000\x00 b\x07")
self.assertNotIn("\x00", h)
self.assertIn("<code>c</code>", h)
self.assertEqual(markdown_sur._en_ligne("\x009\x00"), "\x009\x00") # marqueur inconnu : pas d'IndexError
f = base.Forum()
u = f.fixer_proprietaire("theo", "Théo")
for titre, corps in (("t\x00", "c"), ("t", "a\x005\x00")):
with self.assertRaises(Invalide):
f.creer_sujet(u, titre, corps)
f.creer_sujet(u, "t", "ligne\r\nsuite\ttab") # retours à la ligne et tabulations restent permis
def test_entrees_pieges_rapides(self):
import time
for piege in ("# " + " " * 20000 + "x", "#" * 3 + " " + "#" * 20000 + " x", "**" + "a " * 20000,
"*a" * 20000, "_a " * 20000, "| " * 20000 + "\n|" + "-|" * 20000, "[" * 20000 + "](" * 20000):
debut = time.perf_counter()
markdown_sur.rendu(piege)
self.assertLess(time.perf_counter() - debut, 1.0, piege[:20])
self.assertIn("<h2>Titre</h2>", markdown_sur.rendu("# Titre ## "))
self.assertNotIn("<h2>", markdown_sur.rendu("# ###"))
def test_tableaux(self):
h = markdown_sur.rendu("| Station | Tmin | Note |\n| --- | ---: | :-: |\n| Gêve | -4,2 | **gel** |\n| <i>x</i> | 1 |")
self.assertIn("<table>", h)
@@ -136,6 +158,8 @@ class TestPublier(base.BaseHTTP):
self.assertNotIn("<script>", b.decode())
self.assertIn("<td>1</td><td>2</td>", b.decode())
self.assertEqual(self.post("/apercu-md", "a1", {"corps": "x"}, origine=False)[0], 403)
self.assertEqual(self.post("/apercu-md", "m1", {"corps": "x"})[0], 403) # sans droit creer_sujet
self.assertEqual(self.post("/apercu-md", None, {"corps": "x"})[0], 403)
st, _, b = self.post("/publier", "a1", {"titre": "Sans corps", "corps": " ", "action": "publier"})
self.assertEqual(st, 400)
self.assertIn("value='Sans corps'", b.decode()) # rien n'est perdu