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): suppress high-volume introspection commands from exec audit (#65542)

Felipe Rosa de Almeidafe60a0c5496f
diff --git a/posthog/security/command_exec_audit.py b/posthog/security/command_exec_audit.py
index adb69016a6e7..c1b957d3a2f1 100644
--- a/posthog/security/command_exec_audit.py
+++ b/posthog/security/command_exec_audit.py
@@ -73,6 +73,14 @@ _CONTROL_CHARS[0x7F] = " "
# Characters that let one command string spawn or chain into another.
_SHELL_OPERATORS = frozenset(";|&$`<>\n")
+_VOLUME_SUPPRESSION_RULES: dict[str, Callable[[list[str]], bool]] = {
+ "uname": lambda tail: all(a.startswith("-") for a in tail),
+ "lsb_release": lambda tail: all(a.startswith("-") for a in tail),
+ "ldd": lambda tail: tail == ["--version"],
+ "file": lambda tail: bool(tail) and tail[0] == "-b",
+ "ldconfig": lambda tail: tail == ["-p"],
+}
+
# Context fields pulled from the query-tag ContextVar (set by middleware / Celery / Temporal).
# Identifiers only — deliberately no PII (e.g. user_email) and nothing that can leak secrets
# (http_referer / http_user_agent can carry tokens in query strings). Resolve a user/org from
@@ -122,6 +130,14 @@ def _redact_value(text: str) -> str:
return _BLOB_RE.sub(_REDACTED, text)
+def _is_volume_suppressed(command: Any, shell: bool) -> bool:
+ if shell or not isinstance(command, (list, tuple)) or not command:
+ return False
+ argv = [_to_text(token) for token in command]
+ predicate = _VOLUME_SUPPRESSION_RULES.get(os.path.basename(argv[0].strip()))
+ return predicate is not None and predicate(argv[1:])
+
+
def _scrub_args(tokens: Any) -> list[str]:
result: list[str] = []
redact_next = False
@@ -223,6 +239,8 @@ def _emit(
) -> None:
if _in_audit.get():
return
+ if _is_volume_suppressed(command, shell):
+ return
token = _in_audit.set(True)
try:
payload: dict[str, Any] = {"component": component, "sink": sink, "shell": bool(shell)}
diff --git a/posthog/security/test/test_command_exec_audit.py b/posthog/security/test/test_command_exec_audit.py
index ef876536fdae..4aa3e5c037b2 100644
--- a/posthog/security/test/test_command_exec_audit.py
+++ b/posthog/security/test/test_command_exec_audit.py
@@ -24,6 +24,7 @@ from posthog.models.utils import generate_random_token_personal
from posthog.security import command_exec_audit
from posthog.security.command_exec_audit import (
_REDACTED as _R,
+ _is_volume_suppressed,
_scrub_args,
_scrub_command_string,
_summarize_env,
@@ -115,6 +116,31 @@ class TestCommandExecAuditScrubbing(TestCase):
def test_summarize_env_empty(self) -> None:
self.assertEqual(_summarize_env(None), (None, 0))
+ @parameterized.expand(
+ [
+ # The high-volume introspection shapes we suppress to keep audit volume sane.
+ ("uname_flags", ["uname", "-rs"], False, True),
+ ("uname_single_flag", ["uname", "-p"], False, True),
+ ("lsb_release", ["lsb_release", "-a"], False, True),
+ ("ldd_version", ["ldd", "--version"], False, True),
+ ("file_brief", ["file", "-b", "/some/path"], False, True),
+ ("ldconfig_print", ["ldconfig", "-p"], False, True),
+ ("ldconfig_other_flag", ["ldconfig", "-v"], False, False),
+ # Absolute path still matches on basename.
+ ("absolute_path_uname", ["/usr/bin/uname", "-rs"], False, True),
+ # Anything that isn't the exact suppressed shape must fall through to a full audit entry.
+ ("uname_positional_arg", ["uname", "-a", "extra"], False, False),
+ ("ldd_on_a_binary", ["ldd", "/bin/ls"], False, False),
+ ("file_without_brief", ["file", "/some/path"], False, False),
+ ("unknown_binary", ["curl", "-s", "https://x"], False, False),
+ # shell=True can chain commands — never suppressed, even for a suppressed-looking program.
+ ("shell_string_uname", "uname -rs", True, False),
+ ("empty_command", [], False, False),
+ ]
+ )
+ def test_is_volume_suppressed(self, _name: str, command: Any, shell: bool, expected: bool) -> None:
+ self.assertEqual(_is_volume_suppressed(command, shell), expected)
+
class TestCommandExecAuditPatching(TestCase):
def setUp(self) -> None:
@@ -142,6 +168,20 @@ class TestCommandExecAuditPatching(TestCase):
self.assertTrue(entry["shell"])
self.assertNotIn("hunter2", entry["command"])
+ def test_volume_suppressed_command_is_not_logged(self) -> None:
+ # The high-volume introspection commands are dropped to keep audit volume sane.
+ with structlog.testing.capture_logs() as logs:
+ subprocess.run(["uname", "-rs"], check=False)
+ self.assertIsNone(self._find(logs, "subprocess.Popen"))
+
+ def test_non_suppressed_variant_is_still_logged(self) -> None:
+ # A positional operand on an otherwise suppressed program is not the suppressed shape — keep auditing.
+ with structlog.testing.capture_logs() as logs:
+ subprocess.run(["uname", "-a", "extra"], check=False)
+ entry = self._find(logs, "subprocess.Popen")
+ assert entry is not None
+ self.assertEqual(entry["command"], ["uname", "-a", "extra"])
+
def test_os_system_is_logged(self) -> None:
with structlog.testing.capture_logs() as logs:
os.system("true")