Skip to content

Commit

Permalink
chg: [stream] Regular expressions are now defined in the configuratio…
Browse files Browse the repository at this point in the history
…n file.
  • Loading branch information
cedricbonhomme committed Jan 14, 2025
1 parent 429bb1e commit fc7423f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
15 changes: 15 additions & 0 deletions fedivuln/conf_sample.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

# ### Mastodon

# Connection to Mastodon
Expand All @@ -21,6 +23,19 @@
"on Vulnerability-Lookup:\n<LINK>\n\n#VulnerabilityLookup #Vulnerability #Cybersecurity #bot",
}

# Regular expression to match CVE, GHSA, and PySec IDs
vulnerability_patterns = re.compile(
r"\b(CVE-\d{4}-\d{4,})\b" # CVE pattern
r"|\b(GHSA-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4})\b" # GHSA pattern
r"|\b(PYSEC-\d{4}-\d{2,5})\b" # PYSEC pattern
r"|\b(GSD-\d{4}-\d{4,5})\b" # GSD pattern
r"|\b(wid-sec-w-\d{4}-\d{4})\b" # CERT-Bund pattern
r"|\b(cisco-sa-\d{8}-[a-zA-Z0-9]+)\b" # CISCO pattern
r"|\b(RHSA-\d{4}:\d{4})\b" # RedHat pattern
r"|\b(msrc_CVE-\d{4}-\d{4,})\b", # MSRC CVE pattern
re.IGNORECASE,
)


# ### Event stream

Expand Down
2 changes: 2 additions & 0 deletions fedivuln/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def load_config(path):
mastodon_usercred = conf.mastodon_usercred
templates = conf.templates

vulnerability_patterns = conf.vulnerability_patterns

# For PyVulnerabilityLookup
vulnerability_lookup_base_url = conf.vulnerability_lookup_base_url
vulnerability_auth_token = conf.vulnerability_auth_token
Expand Down
14 changes: 1 addition & 13 deletions fedivuln/stream.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import argparse
import json
import re
import sys
from datetime import datetime

Expand Down Expand Up @@ -28,17 +27,6 @@ def default(self, obj):
# Listener class for handling stream events
class VulnStreamListener(StreamListener):
def __init__(self, push_sighting: bool = False):
# Regular expression to match CVE, GHSA, and PySec IDs
self.vulnerability_pattern = re.compile(
r"\b(CVE-\d{4}-\d{4,})\b" # CVE pattern
r"|\b(GHSA-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4})\b" # GHSA pattern
r"|\b(PYSEC-\d{4}-\d{2,5})\b" # PYSEC pattern
r"|\b(GSD-\d{4}-\d{4,5})\b" # GSD pattern
r"|\b(wid-sec-w-\d{4}-\d{4})\b" # CERT-Bund pattern
r"|\b(cisco-sa-\d{8}-[a-zA-Z0-9]+)\b" # CISCO pattern
r"|\b(RHSA-\d{4}:\d{4})\b", # RedHat pattern
re.IGNORECASE,
)
self.push_sighting = push_sighting

# When a new status (post) is received
Expand All @@ -48,7 +36,7 @@ def on_update(self, status):
print("Edit of a previous status. Ignoring.")
return
content = status["content"]
matches = self.vulnerability_pattern.findall(
matches = config.vulnerability_patterns.findall(
content
) # Find all matches in the content
# Flatten the list of tuples to get only non-empty matched strings
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "FediVuln"
version = "0.6.4"
version = "0.7.0"
description = "A client to gather vulnerability-related information from the Fediverse."
authors = ["Cédric Bonhomme <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down

0 comments on commit fc7423f

Please sign in to comment.