Skip to content

Commit

Permalink
8.6.3
Browse files Browse the repository at this point in the history
- Add an error message instead of raising an exception when an aggregate report timespan is greater than 24 hours
  • Loading branch information
seanthegeek committed Oct 11, 2023
1 parent 0eaba07 commit 1655b84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

8.6.3
-----

- Add an error message instead of raising an exception when an aggregate report timespan is greater than 24 hours

8.6.2
-----

Expand Down
10 changes: 5 additions & 5 deletions parsedmarc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from parsedmarc.utils import parse_email
from parsedmarc.utils import timestamp_to_human, human_timestamp_to_datetime

__version__ = "8.6.2"
__version__ = "8.6.3"

logger.debug("parsedmarc v{0}".format(__version__))

Expand Down Expand Up @@ -219,6 +219,7 @@ def parse_aggregate_report_xml(xml, ip_db_path=None, offline=False,
errors = []
# Parse XML and recover from errors
try:
xml.split("?>")
xmltodict.parse(xml)["feedback"]
except Exception as e:
errors.append("Invalid XML: {0}".format(e.__str__()))
Expand Down Expand Up @@ -273,10 +274,9 @@ def parse_aggregate_report_xml(xml, ip_db_path=None, offline=False,
"").replace(">", "").split("@")[0]
new_report_metadata["report_id"] = report_id
date_range = report["report_metadata"]["date_range"]
if (int(date_range["end"]) - int(date_range["begin"]) > 2*86400):
raise InvalidAggregateReport("The begin and end fields span too \
many hours, should be max 24 hours \
according to RFC 7489 section 7.2")
if int(date_range["end"]) - int(date_range["begin"]) > 2*86400:
_error = "Timespan > 24 hours - RFC 7489 section 7.2"
errors.append(_error)
date_range["begin"] = timestamp_to_human(date_range["begin"])
date_range["end"] = timestamp_to_human(date_range["end"])
new_report_metadata["begin_date"] = date_range["begin"]
Expand Down

1 comment on commit 1655b84

@PHPGangsta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

why has it been changed from Exception to an Error Message?

Because of the Exception, the invalid report has not been imported to ElasticSearch, which was the desired outcome. Now because it's only an Error Message it's imported into ElasticSearch again, and the graphs are broken again. If those invalid reports get imported into Elasticsearch, and you search for the last 14 days, you also get data points from 20 or 30 or 40 days ago, which makes the graph look wrong/broken. Reports with invalid date ranges should not be imported to ElasticSearch.

Please sign in to comment.