Skip to content

Commit

Permalink
Merge pull request #110 from cisagov/improvement/full-entity-names-in…
Browse files Browse the repository at this point in the history
…-emails

Include entity name in emails
  • Loading branch information
dav3r authored Apr 24, 2024
2 parents 3099204 + 86dec57 commit 8a80b70
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 68 deletions.
12 changes: 9 additions & 3 deletions cyhy/mailer/CyhyMessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CyhyMessage(ReportMessage):

Subject = "{{acronym}} - Cyber Hygiene Report - {{report_date}} Results"

TextBody = """Greetings {{acronym}},
TextBody = """Greetings {{name}} ({{acronym}}),
The Cyber Hygiene scan results are attached for your review. Same password as before. (If this is your first report and you have yet to receive a password, please let us know.)
Expand Down Expand Up @@ -57,7 +57,7 @@ class CyhyMessage(ReportMessage):
HtmlBody = """<html>
<head></head>
<body>
<p>Greetings {{acronym}},</p>
<p>Greetings {{name}} ({{acronym}}),</p>
<p>The Cyber Hygiene scan results are attached for your review. Same password as before. (If this is your first report and you have yet to receive a password, please let us know.)</p>
Expand Down Expand Up @@ -91,6 +91,7 @@ def __init__(
to_addrs,
pdf_filename,
entity_acronym,
entity_name,
report_date,
tech_pocs,
from_addr=Message.DefaultFrom,
Expand All @@ -113,6 +114,10 @@ def __init__(
The acronym used by the entity corresponding to the CYHY
report attachment.
entity_name : str
The name of the entity corresponding to the CYHY report
attachment.
report_date : str
The date corresponding to the CYHY report attachment. We
have been using dates of the form December 12, 2017.
Expand Down Expand Up @@ -140,8 +145,9 @@ def __init__(
# This is the data mustache will use to render the templates
mustache_data = {
"acronym": entity_acronym,
"report_date": report_date,
"has_tech_pocs": len(tech_pocs) != 0,
"name": entity_name,
"report_date": report_date,
"tech_pocs": tech_pocs,
}

Expand Down
10 changes: 8 additions & 2 deletions cyhy/mailer/CyhyNotificationMessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CyhyNotificationMessage(ReportMessage):

Subject = "{{acronym}} - Cyber Hygiene Alert - {{report_date}}"

TextBody = """Greetings {{acronym}},
TextBody = """Greetings {{name}} ({{acronym}}),
Cyber Hygiene scans of your host(s) conducted in the past day have detected one or more of the following:
* New critical, high, and/or known exploited vulnerabilities
Expand Down Expand Up @@ -58,7 +58,7 @@ class CyhyNotificationMessage(ReportMessage):
HtmlBody = """<html>
<head></head>
<body>
<p>Greetings {{acronym}},</p>
<p>Greetings {{name}} ({{acronym}}),</p>
<p>Cyber Hygiene scans of your host(s) conducted in the past day have detected one or more of the following:
<ul>
Expand Down Expand Up @@ -94,6 +94,7 @@ def __init__(
to_addrs,
pdf_filename,
entity_acronym,
entity_name,
is_federal,
report_date,
from_addr=Message.DefaultFrom,
Expand All @@ -116,6 +117,10 @@ def __init__(
The acronym used by the entity corresponding to the CYHY
notification attachment.
entity_name : str
The name of the entity corresponding to the CYHY notification
attachment.
is_federal : bool
True if the entity is Federal, otherwise False.
Expand All @@ -139,6 +144,7 @@ def __init__(
mustache_data = {
"acronym": entity_acronym,
"is_federal": is_federal,
"name": entity_name,
"report_date": report_date,
}

Expand Down
15 changes: 12 additions & 3 deletions cyhy/mailer/HttpsMessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class HttpsMessage(ReportMessage):

Subject = "{{acronym}} - HTTPS Report - {{report_date}} Results"

TextBody = """Greetings {{acronym}},
TextBody = """Greetings {{name}} ({{acronym}}),
Attached is your latest HTTPS Report.
Expand Down Expand Up @@ -65,7 +65,7 @@ class HttpsMessage(ReportMessage):
<head></head>
<body>
<div style=""font-size:14.5"">
<p>Greetings {{acronym}},</p>
<p>Greetings {{name}} ({{acronym}}),</p>
<p>Attached is your latest HTTPS Report.</p>
<p>This report is intended to assist your agency in complying with OMB <a href="https://https.cio.gov">M-15-13</a> and CISA <a href="https://cyber.dhs.gov/bod/18-01/">Binding Operational Directive 18-01</a>.</p>
<p>This report includes all second-level .gov domains your agency owns and many known subdomains. Subdomains are gleaned from Cyber Hygiene scans, the General Services Administration's <a href="https://analytics.usa.gov/">Digital Analytics Program</a>, <a href=https://censys.io>Censys.io</a>, and data from the <a href="http://eotarchive.cdlib.org/">End of Term Web Archive</a>. The data in this report comes from a <b>scan that took place on {{report_date}}.</b></p>
Expand Down Expand Up @@ -98,6 +98,7 @@ def __init__(
to_addrs,
pdf_filename,
entity_acronym,
entity_name,
report_date,
from_addr=Message.DefaultFrom,
cc_addrs=Message.DefaultCc,
Expand All @@ -119,6 +120,10 @@ def __init__(
The acronym used by the entity corresponding to the
Trustworthy Email report attachment.
entity_name : str
The name of the entity corresponding to the Trustworthy Email
report attachment.
report_date : str
The date corresponding to the Trustworthy Email report
attachment. We have been using dates of the form December
Expand All @@ -137,7 +142,11 @@ def __init__(
"""
# This is the data mustache will use to render the templates
mustache_data = {"acronym": entity_acronym, "report_date": report_date}
mustache_data = {
"acronym": entity_acronym,
"name": entity_name,
"report_date": report_date,
}

# Render the templates
subject = chevron.render(HttpsMessage.Subject, mustache_data)
Expand Down
15 changes: 12 additions & 3 deletions cyhy/mailer/TmailMessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TmailMessage(ReportMessage):

Subject = "{{acronym}} - Trustworthy Email Report - {{report_date}} Results"

TextBody = """Greetings {{acronym}},
TextBody = """Greetings {{name}} ({{acronym}}),
Attached is your Trustworthy Email Report. This report presents your organization's support of SPF and DMARC, two email authentication standards, as published at your .gov domains. The data in this report comes from a scan that took place on {{report_date}}.
Expand Down Expand Up @@ -63,7 +63,7 @@ class TmailMessage(ReportMessage):
<head></head>
<body>
<div style=""font-size:14.5"">
<p>Greetings {{acronym}},</p>
<p>Greetings {{name}} ({{acronym}}),</p>
<p>Attached is your <b>Trustworthy Email Report</b>. This report presents your organization's support of SPF and DMARC, two email authentication standards, as published at your .gov domains. The data in this report comes from a <b>scan that took place on {{report_date}}.</b></p>
<p><a href="https://cyber.dhs.gov/bod/18-01/">CISA Binding Operational Directive 18-01</a> requires your agency to take certain actions relevant to the data in this report:</p>
<ul>
Expand Down Expand Up @@ -96,6 +96,7 @@ def __init__(
to_addrs,
pdf_filename,
entity_acronym,
entity_name,
report_date,
from_addr=Message.DefaultFrom,
cc_addrs=Message.DefaultCc,
Expand All @@ -117,6 +118,10 @@ def __init__(
The acronym used by the entity corresponding to the
Trustworthy Email report attachment.
entity_name : str
The name of the entity corresponding to the Trustworthy Email
report attachment.
report_date : str
The date corresponding to the Trustworthy Email report
attachment. We have been using dates of the form December
Expand All @@ -135,7 +140,11 @@ def __init__(
"""
# This is the data mustache will use to render the templates
mustache_data = {"acronym": entity_acronym, "report_date": report_date}
mustache_data = {
"acronym": entity_acronym,
"name": entity_name,
"report_date": report_date,
}

# Render the templates
subject = chevron.render(TmailMessage.Subject, mustache_data)
Expand Down
2 changes: 1 addition & 1 deletion cyhy/mailer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""This package contains the cyhy-mailer code."""

__version__ = "1.7.0"
__version__ = "1.7.1"
18 changes: 16 additions & 2 deletions cyhy/mailer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def get_requests_raw(db, query, batch_size=None):
"agency.contacts.name": True,
"agency.contacts.type": True,
"agency.location.state": True,
"agency.name": True,
"agency.type": True,
}

Expand Down Expand Up @@ -445,6 +446,7 @@ def send_bod_reports(
for request in bod_requests:
id = request["_id"]
acronym = request["agency"]["acronym"]
entity_name = request["agency"]["name"]

to_emails = get_emails_from_request(request)
# to_emails should contain at least one email
Expand Down Expand Up @@ -495,7 +497,11 @@ def send_bod_reports(

# Construct the Tmail message to send
message = TmailMessage(
to_emails, tmail_attachment_filename, acronym, report_date
to_emails,
tmail_attachment_filename,
acronym,
entity_name,
report_date,
)

try:
Expand Down Expand Up @@ -551,7 +557,11 @@ def send_bod_reports(

# Construct the HTTPS message to send
message = HttpsMessage(
to_emails, https_attachment_filename, acronym, report_date
to_emails,
https_attachment_filename,
acronym,
entity_name,
report_date,
)

try:
Expand Down Expand Up @@ -786,6 +796,7 @@ def send_cyhy_reports(
for request in cyhy_requests:
id = request["_id"]
acronym = request["agency"]["acronym"]
entity_name = request["agency"]["name"]
technical_pocs = [
contact
for contact in request["agency"]["contacts"]
Expand Down Expand Up @@ -871,6 +882,7 @@ def send_cyhy_reports(
to_emails,
cyhy_attachment_filename,
acronym,
entity_name,
report_date,
technical_pocs,
bcc_addrs=bcc_addrs,
Expand Down Expand Up @@ -1016,6 +1028,7 @@ def send_cyhy_notifications(
for request in cyhy_requests:
id = request["_id"]
acronym = request["agency"]["acronym"]
entity_name = request["agency"]["name"]
is_federal = id in fed_orgs

to_emails = get_emails_from_request(request)
Expand Down Expand Up @@ -1093,6 +1106,7 @@ def send_cyhy_notifications(
to_emails,
cyhy_notification_attachment_filename,
acronym,
entity_name,
is_federal,
notification_date,
bcc_addrs=bcc_addrs,
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ secrets:

services:
mailer:
image: cisagov/cyhy-mailer:1.7.0
image: cisagov/cyhy-mailer:1.7.1
secrets:
- source: database_creds
target: database_creds.yml
Expand Down
Loading

0 comments on commit 8a80b70

Please sign in to comment.