File tree Expand file tree Collapse file tree
python_jobs/src/hbnmigration/utility_functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -140,9 +140,9 @@ def initialize_logging(
140140 return logging .getLogger (name )
141141
142142
143- def safe_record_for_log (record : str ) -> str :
143+ def safe_record_for_log (record : object ) -> str :
144144 r"""
145- Sanitize a string for safe inclusion in log output.
145+ Sanitize a value for safe inclusion in log output.
146146
147147 Mitigates CRLF log injection attacks by removing characters that could
148148 be used to forge log entries, evade log analysis, or exploit log viewers.
@@ -161,15 +161,17 @@ def safe_record_for_log(record: str) -> str:
161161 Parameters
162162 ----------
163163 record
164- The untrusted string to sanitize before logging.
164+ The untrusted value to sanitize before logging.
165165
166166 Returns
167167 -------
168168 str
169- A sanitized copy of the string with dangerous characters removed.
169+ A sanitized copy of the value with dangerous characters removed.
170170
171171 """
172- result = _ANSI_RE .sub ("" , record )
172+ text = str (record )
173+ text = text .replace ("\r " , "" ).replace ("\n " , "" )
174+ result = _ANSI_RE .sub ("" , text )
173175 return "" .join (
174176 ch
175177 for ch in result
You can’t perform that action at this time.
0 commit comments