Skip to content

Commit c036b46

Browse files
committed
security.txt expert: fixes, updates to current standards
1 parent ccbee1a commit c036b46

File tree

6 files changed

+40
-17
lines changed

6 files changed

+40
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
- Fix to avoid schema download if not configured #2530.
2828

2929
#### Experts
30+
- `intelmq.bots.experts.securitytxt`:
31+
- Added new bot (PR#2538 by Frank Westers and Sebastian Wagner)
3032

3133
#### Outputs
3234

docs/user/bots.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,7 +3528,10 @@ true.
35283528

35293529
### SecurityTXT <div id="intelmq.bots.experts.securitytxt.expert" />
35303530

3531-
SecurityTXT is an initiative to standardize how websites publish their abuse contact information. Currently it is a `draft RFC <https://datatracker.ietf.org/doc/html/draft-foudil-securitytxt-12>`_. See this draft RFC for more information on security.txt. This bot automatically looks for security.txt files on a URL or IP, retrieves the primary contact information out of it and adds this to the event.
3531+
SecurityTXT is an initiative to standardize how websites publish their abuse contact information.
3532+
It is standardized in [RFC 9116 "A File Format to Aid in Security Vulnerability Disclosure"](https://datatracker.ietf.org/doc/rfc9116/).
3533+
Refer to the linked document RFC for more information on `security.txt`.
3534+
This bot looks for `security.txt` files on a URL or IP, retrieves the primary contact information out of it and adds this to the event.
35323535

35333536
**Requirements**
35343537

@@ -3540,31 +3543,35 @@ pip3 install -r intelmq/bots/experts/securitytxt/REQUIREMENTS.txt
35403543

35413544
**Module:** `intelmq.bots.experts.securitytxt.expert`
35423545

3543-
**Parameters (also expects [cache parameters](#cache-parameters)):**
3546+
**Parameters**
35443547

35453548
**`url_field`**
35463549

3547-
The field in the event that contains the URL/IP on which to look for the the security.txt file.
3550+
The field in the event that contains the URL/IP on which to look for the the security.txt file. Default: `source.reverse_dns`
35483551

35493552
**`contact_field`**
35503553

3551-
The field in the event in which to put the found contact details
3554+
The field in the event in which to put the found contact details. Default: `source.abuse_contact`
35523555

3553-
**`only_email_address`**
3556+
**`only_email_address`** (bool)
35543557

35553558
Contact details can be web URLs or email addresses. When this value is set to True, it only selects email addresses as contact information.
3559+
Default: `true`
35563560

3557-
**`overwrite`**
3561+
**`overwrite`** (bool)
35583562

3559-
Boolean indicating whether to override existing data in contact_field
3563+
Boolean indicating whether to override existing data in contact_field.
3564+
Default: `true`
35603565

3561-
**`check_expired`**
3566+
**`check_expired`** (bool)
35623567

3563-
Boolean indicating whether to check if the security.txt has expired according to its own expiry date
3568+
Boolean indicating whether to check if the security.txt has expired according to its own expiry date.
3569+
Default: `false`
35643570

3565-
**`check_canonical`**
3571+
**`check_canonical`** (bool)
35663572

35673573
Boolean indicating whether to check if the url is contained in the list of canonical urls.
3574+
Default: `false`
35683575

35693576

35703577
---
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
# SPDX-FileCopyrightText: 2022 Frank Westers, 2024 Institute for Common Good Technology
2+
# SPDX-License-Identifier: AGPL-3.0-or-later
3+
14
wellknown-securitytxt

intelmq/bots/experts/securitytxt/expert.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
# SPDX-FileCopyrightText: 2022 Frank Westers, 2024 Institute for Common Good Technology
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
15
from typing import Optional
26

37
import requests
4-
from securitytxt import SecurityTXT
58

69
from intelmq.lib.bot import ExpertBot
10+
from intelmq.lib.exceptions import MissingDependencyError
11+
12+
try:
13+
from securitytxt import SecurityTXT
14+
except (ImportError, ModuleNotFoundError):
15+
SecurityTXT = None
716

817

918
class SecurityTXTExpertBot(ExpertBot):
@@ -27,8 +36,8 @@ class SecurityTXTExpertBot(ExpertBot):
2736
check_canonical: bool = False
2837

2938
def init(self):
30-
if not self.url_field or not self.contact_field:
31-
raise AttributeError("Not all required fields are set.")
39+
if SecurityTXT is None:
40+
raise MissingDependencyError('wellknown-securitytxt')
3241

3342
def process(self):
3443
event = self.receive_message()
@@ -38,9 +47,9 @@ def process(self):
3847
primary_contact = self.get_primary_contact(event.get(self.url_field))
3948
event.add(self.contact_field, primary_contact, overwrite=self.overwrite)
4049
except NotMeetsRequirementsError as e:
41-
self.logger.debug(str(e) + " Skipping event.")
50+
self.logger.debug("Skipping event (%s).", e)
4251
except ContactNotFoundError as e:
43-
self.logger.debug(f"No contact found. {str(e)} Continue.")
52+
self.logger.debug("No contact found: %s Continue.", e)
4453

4554
self.send_message(event)
4655
self.acknowledge_message()
@@ -101,4 +110,4 @@ class ContactNotFoundError(Exception):
101110
pass
102111

103112

104-
BOT = SecurityTXTExpertBot
113+
BOT = SecurityTXTExpertBot

intelmq/tests/bots/experts/securitytxt/REQUIREMENTS.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

intelmq/tests/bots/experts/securitytxt/test_expert.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# SPDX-FileCopyrightText: 2022 Frank Westers
2+
#
13
# SPDX-License-Identifier: AGPL-3.0-or-later
24

35
# -*- coding: utf-8 -*-
@@ -30,6 +32,7 @@
3032
"source.fqdn": "test.local"}
3133

3234
@requests_mock.Mocker()
35+
@test.skip_exotic()
3336
class TestSecurityTXTExpertBot(test.BotTestCase, unittest.TestCase):
3437
"""
3538
A TestCase for the SecurityTXT Expert Bot

0 commit comments

Comments
 (0)