Created
December 27, 2021 11:54
-
-
Save ariebovenberg/dfd849ddc7a0dc7428a22b5b8a468134 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
logging.basicConfig(level=logging.INFO) | |
logger = logging.getLogger(__name__) | |
# basic usage | |
logger.info("hello world") | |
# basic formatting | |
context = { | |
"user": "bob", | |
"msg": "hello everybody", | |
} | |
logger.info("user '%(user)s' commented: '%(msg)s'.", context) | |
# classic log injection | |
context = { | |
"user": "bob", | |
"msg": "hello'.\nINFO:__main__:user 'alice' commented 'I like pineapple pizza", | |
} | |
logger.info("user '%(user)s' commented: '%(msg)s'.", context) | |
# f-string double formatting error | |
context = { | |
"user": "bob", | |
"msg": (msg := "%(foo)s"), | |
} | |
logger.info(f"user '%(user)s' commented: '{msg}'.", context) | |
# DoS attack | |
context = { | |
"user": "bob", | |
"msg": (msg := "%(user)999999s"), # add more nines at your own risk | |
} | |
logger.info(f"user '%(user)s' commented: '{msg}'.", context) | |
# secret leakage | |
context = { | |
"user": "bob", | |
"msg": (msg := "%(secret)s"), | |
"secret": "hunter2", | |
} | |
logger.info(f"user '%(user)s' commented: '{msg}'.", context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment