Skip to content

Commit

Permalink
prevent log forging, fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbui committed Jul 20, 2019
1 parent 1e9a6c3 commit f3b8cdd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## 1.0.1 - 2019-07-20
- prevent log forging, fix #1

## 1.0.0 - 2019-07-20
Breaking change:
- add more specific init method for each framework
Expand Down
9 changes: 6 additions & 3 deletions json_logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ def format(self, record):
return JSON_SERIALIZER(json_log_object)


def _sanitize_log_msg(record):
return record.getMessage().replace('\n', '_').replace('\r', '_').replace('\t', '_')


class JSONLogFormatter(logging.Formatter):
"""
Formatter for non-web application log
Expand Down Expand Up @@ -266,9 +270,8 @@ def format(self, record):
"level": record.levelname,
"line_no": record.lineno,
"module": record.module,
"msg": record.getMessage(),
"msg": _sanitize_log_msg(record),
}

if hasattr(record, 'props'):
json_log_object.update(record.props)

Expand Down Expand Up @@ -312,7 +315,7 @@ def format(self, record):
"module": record.module,
"line_no": record.lineno,
"correlation_id": _request_util.get_correlation_id(),
"msg": record.getMessage()
"msg": _sanitize_log_msg(record)
}

if hasattr(record, 'props'):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="json-logging",
version='1.0.0',
version='1.0.1',
packages=find_packages(exclude=['contrib', 'docs', 'tests*', 'example', 'dist', 'build']),
license='Apache License 2.0',
description="JSON Python Logging",
Expand Down

0 comments on commit f3b8cdd

Please sign in to comment.