fix: remove stray fragments and duplicate _sanitize_for_log definitions in dns_resolver.py

Agent-Logs-Url: https://github.com/christianlouis/dmarq/sessions/8ad92992-343e-4e81-a830-cd83efcb2437

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-29 19:06:36 +00:00
parent a77a89f475
commit 087c2b375b
+5 -46
View File
@@ -15,37 +15,8 @@ from typing import List, Optional, Tuple
logger = logging.getLogger(__name__)
def _sanitize_for_log(value: Optional[str]) -> str:
"""
Return a log-safe representation of *value* by removing newline and
carriage-return characters that could be used for log injection.
This is only used for logging; the original value should still be used
for functional behavior such as DNS lookups.
"""
if value is None:
return ""
# Ensure we are working with a string, then strip CR/LF characters
text = str(value)
return text.replace("\r", "").replace("\n", "")
def _sanitize_for_log(value: str) -> str:
"""
Remove characters that could be used for log injection from a string.
Currently strips carriage returns and newlines to prevent forged log lines.
"""
return value.replace("\r", "").replace("\n", "")
def _sanitize_for_log(value: str) -> str:
"""
Remove newline and carriage return characters from log values to prevent
log injection through user-controlled input.
"""
"""Remove newline and carriage-return characters to prevent log injection."""
return value.replace("\r", "").replace("\n", "")
@@ -109,8 +80,7 @@ class BaseDNSProvider(ABC):
# ------------------------------------------------------------------
# High-level record checks built on top of lookup_txt
# ------------------------------------------------------------------
safe_domain = _sanitize_for_log(domain)
logger.debug("DMARC lookup failed for %s: %s", safe_domain, exc)
async def check_dmarc(self, domain: str) -> Tuple[bool, Optional[str]]:
"""Return *(found, record_string)* for the domain's DMARC TXT record."""
try:
@@ -121,16 +91,10 @@ class BaseDNSProvider(ABC):
except LookupError as exc:
logger.debug("DMARC lookup failed for %s: %s", _sanitize_for_log(domain), exc)
return False, None
safe_domain = _sanitize_for_log(domain)
logger.debug("SPF lookup failed for %s: %s", safe_domain, exc)
async def check_spf(self, domain: str) -> Tuple[bool, Optional[str]]:
safe_selector = _sanitize_for_log(selector)
safe_domain = _sanitize_for_log(domain)
"""Return *(found, record_string)* for the domain's SPF TXT record."""
"DKIM lookup failed for selector=%s domain=%s: %s",
safe_selector,
safe_domain,
exc,
try:
records = await self.lookup_txt(domain)
for record in records:
if record.lower().startswith("v=spf1"):
@@ -141,13 +105,8 @@ class BaseDNSProvider(ABC):
async def check_dkim(
self, domain: str, selectors: List[str]
safe_selector = _sanitize_for_log(selector)
safe_domain = _sanitize_for_log(domain)
) -> Tuple[bool, Optional[str], Optional[str]]:
"DKIM lookup failed for selector=%s domain=%s: %s",
safe_selector,
safe_domain,
exc,
"""Return *(found, selector, record_string)* for the first working DKIM selector."""
for selector in selectors:
try:
records = await self.lookup_txt(f"{selector}._domainkey.{domain}")