From c17688e9f717c9249ad35039ff89776c903ccd0f Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Wed, 3 Dec 2025 14:51:47 +0100 Subject: [PATCH 1/2] relax printable checks --- paranoia.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/paranoia.py b/paranoia.py index 5ebca7c..331ffb0 100644 --- a/paranoia.py +++ b/paranoia.py @@ -2,7 +2,12 @@ from loguru import logger ENABLE_HARDENING = True - +WHITELISTED_NON_PRINTABLE_CHARS = { + "\n", # newline + "\r", # carriage return + "\t", # tab + "\xa0", # non-breaking space ( ) +} def panic(reason: str): if not ENABLE_HARDENING: @@ -17,8 +22,17 @@ def assert_printable(v: str): return if not isinstance(v, str): panic("not a string " + str(v)) - if not v.isprintable(): - panic("string contains non-printable characters") + for ch in v: + # check if printable + if ch.isprintable(): + continue + + # check if whitelisted non-printable + if ch in WHITELISTED_NON_PRINTABLE_CHARS: + continue + + # Anything else is rejected + panic(f"string contains non-printable character: (0x{ord(ch):04X})") # Check if number is valid int and not NaN From beced24a2930f3bb9d8da6d44f226158b94a20e9 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Wed, 3 Dec 2025 14:08:51 +0000 Subject: [PATCH 2/2] format --- paranoia.py | 1 + 1 file changed, 1 insertion(+) diff --git a/paranoia.py b/paranoia.py index 331ffb0..205debe 100644 --- a/paranoia.py +++ b/paranoia.py @@ -9,6 +9,7 @@ "\xa0", # non-breaking space ( ) } + def panic(reason: str): if not ENABLE_HARDENING: return