Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(security): raise the host guard logger so its detection lines ship (#121842)

Tom Piccirello759a6955cb99
diff --git a/posthog/settings/logs.py b/posthog/settings/logs.py
index 08d28290beda..0a8e40456781 100644
--- a/posthog/settings/logs.py
+++ b/posthog/settings/logs.py
@@ -180,6 +180,9 @@ LOGGING: dict[str, Any] = {
},
"posthog.auth.mfa": {"level": "INFO", "handlers": ["console"], "propagate": False},
"posthog.security.command_exec_audit": {"level": "INFO", "handlers": ["console"], "propagate": False},
+ # Same clamp: the host guards log a matched out-of-band interaction domain at INFO,
+ # while the refusal beside it logs at WARNING, so the gap is invisible without this.
+ "posthog.security.url_validation": {"level": "INFO", "handlers": ["console"], "propagate": False},
# The posthoganalytics SDK claims the "posthog" logger name and clamps it to WARNING
# at client init, so the source-registry prewarm's INFO lifecycle logs need an
# explicit level to be visible.
diff --git a/posthog/test/repo_invariants/test_oob_detection_log_level.py b/posthog/test/repo_invariants/test_oob_detection_log_level.py
new file mode 100644
index 000000000000..aa5891514e01
--- /dev/null
+++ b/posthog/test/repo_invariants/test_oob_detection_log_level.py
@@ -0,0 +1,57 @@
+"""Every out-of-band detection line must survive the `posthog` logger clamp.
+
+The posthoganalytics SDK claims the `posthog` logger name and clamps it to WARNING when it
+builds its client, so every logger under `posthog.` inherits that level. The guards log a match
+at INFO, which that clamp swallows: the refusal next to it still prints, so the gap is invisible
+until someone checks production and finds the matches missing.
+
+A guard under `products.` sits outside the clamp and needs no entry.
+"""
+
+import logging
+from pathlib import Path
+
+from django.conf import settings
+
+REPO_ROOT = Path(__file__).parents[3]
+DETECTION_EVENT = "security.oob_domain_seen"
+SCANNED_ROOTS = ("posthog", "products", "ee", "common")
+CLAMPED_PREFIX = "posthog."
+SKIPPED_PARTS = ("node_modules", "__pycache__", "migrations")
+VISIBLE_LEVELS = {logging.getLevelName(level) for level in (logging.DEBUG, logging.INFO)}
+
+
+def _is_test(path: Path) -> bool:
+ return path.name.startswith("test_") or path.name.endswith("_test.py") or "tests" in path.parts
+
+
+def clamped_emitters() -> list[str]:
+ """Logger names under `posthog.` that emit the detection event.
+
+ Each guard calls `structlog.get_logger(__name__)`, so the module path is the logger name.
+ """
+ found: set[str] = set()
+ for root in SCANNED_ROOTS:
+ for path in (REPO_ROOT / root).rglob("*.py"):
+ if any(part in SKIPPED_PARTS for part in path.parts) or _is_test(path):
+ continue
+ if DETECTION_EVENT not in path.read_text(errors="ignore"):
+ continue
+ name = ".".join(path.relative_to(REPO_ROOT).with_suffix("").parts)
+ if name.startswith(CLAMPED_PREFIX):
+ found.add(name)
+ return sorted(found)
+
+
+def test_every_clamped_detection_logger_can_emit_info() -> None:
+ configured = settings.LOGGING["loggers"]
+ missing = [name for name in clamped_emitters() if configured.get(name, {}).get("level") not in VISIBLE_LEVELS]
+ assert not missing, (
+ "These loggers emit "
+ f"{DETECTION_EVENT} at INFO but sit under the clamped `posthog` logger, so the line never "
+ "reaches production:\n"
+ + "\n".join(f" {name}" for name in missing)
+ + "\n\nGive each one an explicit entry in posthog/settings/logs.py, next to the others that "
+ 'work around the same clamp:\n "<logger>": {"level": "INFO", "handlers": ["console"], '
+ '"propagate": False},'
+ )