Skip to content

Commit

Permalink
updated validation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hardik-crest committed May 6, 2024
1 parent 315b560 commit 03e01e6
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/phantomcyber/dev-cicd-tools
rev: v1.16
rev: v1.18
hooks:
- id: org-hook
- id: package-app-dependencies
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
7 changes: 1 addition & 6 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Splunk SOAR SMTP
Copyright (c) 2016-2023 Splunk Inc.
Copyright (c) 2016-2024 Splunk Inc.

Third-party Software Attributions:

Expand All @@ -9,8 +9,3 @@ License: MIT
Copyright 2004-2017 Leonard Richardson
Copyright 2004-2019 Leonard Richardson
Copyright 2018 Isaac Muse

Library: requests
Version: 2.25.0
License: Apache 2.0
Kenneth Reitz
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Minimum Product Version: 6.1.1
This app provides the ability to send email using SMTP

[comment]: # " File: README.md"
[comment]: # " Copyright (c) 2016-2023 Splunk Inc."
[comment]: # " Copyright (c) 2016-2024 Splunk Inc."
[comment]: # ""
[comment]: # " Licensed under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)"
[comment]: # ""
Expand Down Expand Up @@ -307,7 +307,7 @@ Some points to note: <ul> <li>Only files present in the <b>vault</b> can be atta
#### Action Parameters
PARAMETER | REQUIRED | DESCRIPTION | TYPE | CONTAINS
--------- | -------- | ----------- | ---- | --------
**from** | optional | Sender Address, domain can not include 'phantom', 'splunk', or 'cisco' | string | `sender_email`
**from** | optional | Sender Address, domain can not include 'phantom', 'splunk', or 'cisco' | string | `email`
**to** | required | List of recipients email addresses | string | `email`
**cc** | optional | List of recipients email addresses to include on cc line | string | `email`
**bcc** | optional | List of recipients email addresses to include on bcc line | string | `email`
Expand All @@ -324,7 +324,7 @@ action_result.parameter.attachments | string | `vault id` | ab2b2ccfba08ea53
action_result.parameter.bcc | string | `email` | [email protected]
action_result.parameter.body | string | | Test body
action_result.parameter.cc | string | `email` | [email protected]
action_result.parameter.from | string | `sender_email` | [email protected]
action_result.parameter.from | string | `email` | [email protected]
action_result.parameter.headers | string | | {"Subject": "Test1", "To": "[email protected]"}
action_result.parameter.subject | string | | Test
action_result.parameter.to | string | `email` | [email protected]
Expand Down Expand Up @@ -367,7 +367,7 @@ If the <b>from</b> parameter is not provided, then the action will consider the
#### Action Parameters
PARAMETER | REQUIRED | DESCRIPTION | TYPE | CONTAINS
--------- | -------- | ----------- | ---- | --------
**from** | optional | Sender Address, domain can not include 'phantom', 'splunk', or 'cisco' | string | `sender_email`
**from** | optional | Sender Address, domain can not include 'phantom', 'splunk', or 'cisco' | string | `email`
**to** | required | List of recipients email addresses | string | `email`
**cc** | optional | List of recipients email addresses to include on cc line | string | `email`
**bcc** | optional | List of recipients email addresses to include on bcc line | string | `email`
Expand Down Expand Up @@ -404,7 +404,7 @@ action_result.parameter.content_id2 | string | |
action_result.parameter.content_id3 | string | |
action_result.parameter.content_id4 | string | |
action_result.parameter.content_id5 | string | |
action_result.parameter.from | string | `sender_email` | [email protected]
action_result.parameter.from | string | `email` | [email protected]
action_result.parameter.headers | string | | {"Subject": "Test1", "To": "[email protected]"}
action_result.parameter.html_body | string | | <html><h2>HTML heading</h2><body>HTML body.</body></html>
action_result.parameter.subject | string | | Test
Expand Down
2 changes: 1 addition & 1 deletion manual_readme_content.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[comment]: # " File: README.md"
[comment]: # " Copyright (c) 2016-2023 Splunk Inc."
[comment]: # " Copyright (c) 2016-2024 Splunk Inc."
[comment]: # ""
[comment]: # " Licensed under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)"
[comment]: # ""
Expand Down
1 change: 1 addition & 0 deletions release_notes/unreleased.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**Unreleased**
* Added restrictions for `splunk`, `phantom` and `cisco` domains for 'from' input in **send email** and **send htmlemail**
28 changes: 8 additions & 20 deletions smtp.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
"publisher": "Splunk",
"type": "email",
"main_module": "smtp_connector.py",
"app_version": "3.1.1",
"app_version": "3.2.0",
"utctime_updated": "2024-03-06T13:04:08.000000Z",
"package_name": "phantom_smtp",
"product_vendor": "Generic",
"product_name": "SMTP",
"product_version_regex": ".*",
"min_phantom_version": "6.1.1",
"min_phantom_version": "6.2.0",
"rest_handler": "request_handler.handle_request",
"license": "Copyright (c) 2016-2024 Splunk Inc.",
"logo": "logo_splunk.svg",
"logo_dark": "logo_splunk_dark.svg",
"python_version": "3",
"fips_compliant": true,
"latest_tested_versions": [
"smtp.gmail.com, smtp.office365.com September 26, 2023"
"smtp.gmail.com, smtp.office365.com May 6, 2024"
],
"configuration": {
"server": {
Expand Down Expand Up @@ -139,7 +139,7 @@
"data_type": "string",
"order": 0,
"contains": [
"sender_email"
"email"
],
"primary": true
},
Expand Down Expand Up @@ -253,7 +253,7 @@
"data_path": "action_result.parameter.from",
"data_type": "string",
"contains": [
"sender_email"
"email"
],
"example_values": [
"[email protected]"
Expand Down Expand Up @@ -409,7 +409,7 @@
"order": 0,
"primary": true,
"contains": [
"sender_email"
"email"
]
},
"to": {
Expand Down Expand Up @@ -614,7 +614,7 @@
"data_path": "action_result.parameter.from",
"data_type": "string",
"contains": [
"sender_email"
"email"
],
"example_values": [
"[email protected]"
Expand Down Expand Up @@ -701,10 +701,6 @@
],
"pip39_dependencies": {
"wheel": [
{
"module": "beautifulsoup4",
"input_file": "wheels/py3/beautifulsoup4-4.9.1-py3-none-any.whl"
},
{
"module": "bleach",
"input_file": "wheels/py3/bleach-6.0.0-py3-none-any.whl"
Expand All @@ -713,14 +709,6 @@
"module": "bleach_allowlist",
"input_file": "wheels/shared/bleach_allowlist-1.0.3-py2.py3-none-any.whl"
},
{
"module": "six",
"input_file": "wheels/shared/six-1.16.0-py2.py3-none-any.whl"
},
{
"module": "soupsieve",
"input_file": "wheels/py3/soupsieve-2.5-py3-none-any.whl"
},
{
"module": "tinycss2",
"input_file": "wheels/py3/tinycss2-1.1.1-py3-none-any.whl"
Expand All @@ -731,4 +719,4 @@
}
]
}
}
}
25 changes: 20 additions & 5 deletions smtp_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def initialize(self):
# action_result = self.add_action_result(ActionResult())

self.set_validator('email', self._validate_email)
self.set_validator('sender_email', self._validate_sender_email)

return phantom.APP_SUCCESS

Expand Down Expand Up @@ -233,20 +232,26 @@ def _validate_integer(self, action_result, parameter, key, allow_zero=False):

return phantom.APP_SUCCESS, parameter

def _validate_sender_email(self, input_data):
def _validate_sender_email(self, action_result, input_data):
# SMTP only supports a single email as the sender
if ',' in input_data or ';' in input_data:
return False
return action_result.set_status(
phantom.APP_ERROR,
"SMTP only supports a single email for the 'from' field, please enter email in valid format."
)

# sender emails also have additional restriction
# to not include splunk related terms in the domain name
restricted_domains = ["splunk", "cisco", "phantom"]
domain = input_data.split("@")[-1]

if any(restricted_domain in domain for restricted_domain in restricted_domains):
return False
return action_result.set_status(
phantom.APP_ERROR,
"The domain provided in email is restricted, please use a different email."
)

return self._validate_email(input_data)
return action_result.set_status(phantom.APP_SUCCESS)

def _validate_email(self, input_data):
# validations are always tricky things, making it 100% foolproof, will take a
Expand Down Expand Up @@ -818,6 +823,11 @@ def _send_email(self, param, action_result):
sender_address = config.get('sender_address', config.get(phantom.APP_JSON_USERNAME))
email_from = param.get(SMTP_JSON_FROM, sender_address)

# validate sender email
ret_val = self._validate_sender_email(action_result, email_from)
if phantom.is_fail(ret_val):
return action_result.get_status()

encoding = config.get(SMTP_ENCODING, False)
smtputf8 = config.get(SMTP_ALLOW_SMTPUTF8, False)
body = param[SMTP_JSON_BODY]
Expand Down Expand Up @@ -1039,6 +1049,11 @@ def _handle_send_htmlemail(self, param): # noqa: C901
sender_address = config.get('sender_address', config.get(phantom.APP_JSON_USERNAME))
email_from = param.get(SMTP_JSON_FROM, sender_address)

# validate sender email
ret_val = self._validate_sender_email(action_result, email_from)
if phantom.is_fail(ret_val):
return action_result.get_status()

email_to = param['to']
email_cc = param.get('cc')
email_bcc = param.get('bcc')
Expand Down
Binary file removed wheels/py3/beautifulsoup4-4.9.1-py3-none-any.whl
Binary file not shown.
Binary file removed wheels/py3/soupsieve-2.5-py3-none-any.whl
Binary file not shown.
Binary file removed wheels/shared/six-1.16.0-py2.py3-none-any.whl
Binary file not shown.

0 comments on commit 03e01e6

Please sign in to comment.