Skip to content

Commit 54fc2dd

Browse files
fix: Correct default email format and improve User-Agent validation (#182) (#187)
This commit addresses two issues identified in CodeQL security scanning: 1. Fixed invalid default email address format: Changed from 'noreply.aletheia-probe.org' to 'noreply@aletheia-probe.org' (missing '@' symbol) 2. Replaced substring matching with exact User-Agent format validation in tests to avoid triggering incomplete URL sanitization warnings The original CodeQL alert was a false positive (the code wasn't validating URLs for security purposes), but the investigation revealed a real bug in the default email format. The improved test assertions now verify the exact expected User-Agent format, which is more robust and avoids security scanner warnings. Co-authored-by: florath-ai-assistant[bot] <Andreas.Florath@telekom.de>
1 parent 42332cb commit 54fc2dd

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/aletheia_probe/article_retraction_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def to_dict(self) -> dict[str, Any]:
5757
class ArticleRetractionChecker:
5858
"""Checks individual articles (by DOI) for retraction status using multiple sources."""
5959

60-
def __init__(self, email: str = "noreply.aletheia-probe.org"):
60+
def __init__(self, email: str = "noreply@aletheia-probe.org"):
6161
"""
6262
Initialize the article retraction checker.
6363

tests/unit/test_article_retraction_checker.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,22 @@ def test_init_default_email(self):
9494
"""Test ArticleRetractionChecker initialization with default email."""
9595
checker = ArticleRetractionChecker()
9696

97-
assert checker.email == "noreply.aletheia-probe.org"
97+
assert checker.email == "noreply@aletheia-probe.org"
9898
assert checker.crossref_base_url == "https://api.crossref.org"
9999
assert "User-Agent" in checker.headers
100-
assert "AletheiaProbe" in checker.headers["User-Agent"]
101-
assert "noreply.aletheia-probe.org" in checker.headers["User-Agent"]
100+
# Verify exact User-Agent format instead of substring matching
101+
expected_user_agent = "AletheiaProbe/1.0 (mailto:noreply@aletheia-probe.org)"
102+
assert checker.headers["User-Agent"] == expected_user_agent
102103

103104
def test_init_custom_email(self):
104105
"""Test ArticleRetractionChecker initialization with custom email."""
105106
custom_email = "test@example.com"
106107
checker = ArticleRetractionChecker(email=custom_email)
107108

108109
assert checker.email == custom_email
109-
assert custom_email in checker.headers["User-Agent"]
110+
# Verify exact User-Agent format instead of substring matching
111+
expected_user_agent = f"AletheiaProbe/1.0 (mailto:{custom_email})"
112+
assert checker.headers["User-Agent"] == expected_user_agent
110113

111114

112115
class TestArticleRetractionCheckerDOIValidation:

0 commit comments

Comments
 (0)