user/path value check: add support for no-unicode

This commit is contained in:
Peter Bieringer
2026-04-22 20:09:12 +02:00
parent 5a6bae0a2c
commit 2be334922a
4 changed files with 31 additions and 7 deletions

View File

@@ -163,8 +163,21 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
# Format checks
self._validate_user_value = configuration.get("server", "validate_user_value")
self._validate_path_value = configuration.get("server", "validate_path_value")
logger.info("validate user value: %r", self._validate_user_value)
logger.info("validate path value: %r", self._validate_path_value)
if not self._storage._filesystem_root_folder_supports_unicode:
if self._validate_user_value not in ["strict", "no-unicode"]:
self._validate_user_value = "no-unicode"
if self._validate_path_value not in ["strict", "no-unicode"]:
self._validate_path_value = "no-unicode"
if not self._storage._filesystem_root_folder_supports_problematic_chars or not self._storage._filesystem_root_folder_supports_trailing_whitespace:
if self._validate_user_value not in ["strict"]:
self._validate_user_value = "strict"
if self._validate_path_value not in ["strict"]:
self._validate_path_value = "strict"
logger.notice("validate user value: %r (enforced by missing support of collection storage)", self._validate_user_value)
logger.notice("validate path value: %r (enforced by missing support of collection storage)", self._validate_path_value)
else:
logger.info("validate user value: %r", self._validate_user_value)
logger.info("validate path value: %r", self._validate_path_value)
# Profiling options
self._profiling = configuration.get("logging", "profiling")
self._profiling_per_request_min_duration = configuration.get("logging", "profiling_per_request_min_duration")

View File

@@ -124,23 +124,28 @@ class ApplicationBase:
validation_type: str,
) -> bool:
check_minimal = (validation_type == "minimal")
check_unicode = (validation_type == "unicodeletter")
logger.trace("_check_format investigate %r (validation_type=%r check_minimal=%s check_unicode=%s)", string, validation_type, check_minimal, check_unicode)
check_unicode_letter = (validation_type == "unicode-letter")
check_no_unicode = (validation_type == "no-unicode")
logger.trace("_check_format investigate %r (validation_type=%r check_minimal=%s check_unicode_letter=%s check_no_unicode=%s)", string, validation_type, check_minimal, check_unicode_letter, check_no_unicode)
for c in string:
if c <= chr(31) or (c >= chr(127) and c <= chr(159)):
# ASCII: control char
return False
if unicodedata.category(c)[0] == "C":
# https://unicodeplus.com/category
# Unicode: control
return False
if check_minimal:
if c in blacklist_minimal:
logger.trace("_check_format found %r", c)
return False
elif check_unicode:
elif check_unicode_letter:
if c not in whitelist_unicode:
if unicodedata.category(c)[0] != "L":
return False
elif check_no_unicode:
if ord(c) > 255:
return False
return True
def _check_user_format(self, user: str) -> bool: