AdminErrorHandler silently fails if the log message contains newlines
|Reported by:||russellm||Owned by:||marw85|
|Cc:||glencoates, iacobcatalin@…||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
If you have loggers configured with an django.utils.log.AdminEmailHandler, and you log a message that has a newline in it, the log message is handled by the logger, but is silently discarded.
For example if you sent the following:
logger.error('This is a\n test message')
The log message will be correctly written to any text-based log handlers or console log handlers, but the AdminEmailHandler silently fails.
This is because the subject of an email can't contain newlines.
Given that the AdminEmailHandler is intended as a mechanism for reporting serious errors, it's pretty bad that it can fail silently due to the contents of the message it's reporting. The "subject" of the log email should be cleansed of newlines before the call to mail_admins is made.
This cleansing could also be performed in the mail utilities themselves. However, I'm not convinced this is the right place; the general mail tools have "fail_silently" as an option, so it would be possible to handle this error in a better way. Failing is not an option during logging, so we should make sure that the messages to be sent are appropriately cleansed.
Change History (11)
Changed 3 years ago by elbarto
comment:4 Changed 3 years ago by marw85
- Needs tests set
- Owner changed from elbarto to marw85
- Status changed from new to assigned