Skip to content

Instantly share code, notes, and snippets.

@facundopadilla
Last active March 14, 2023 20:10
Show Gist options
  • Save facundopadilla/b2210cc2311fcc576431dc1226794882 to your computer and use it in GitHub Desktop.
Save facundopadilla/b2210cc2311fcc576431dc1226794882 to your computer and use it in GitHub Desktop.
Anti CLRF in Python - Logging module - Log injection
import logging
import sys
import anticrlf
formatter = anticrlf.LogFormatter(
"%(asctime)s - %(name)s - %(levelname)s: Line %(lineno)s | %(message)s" # replace it for another format
)
formatter.replacements["\n"] = "\\x0A" # OPTIONAL: \x0a is a equivalent of \n in bash
handler = logging.StreamHandler(sys.stdout) # another option: sys.stderr
handler.setFormatter(fmt=formatter)
logger = logging.getLogger("application") # replace the string for your application name or __name__
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
logger.info("works!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment