: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(hogql): redact new-format github tokens from corpus dumps (#94398)
Raúl Negrón-Otero86f9ae5dd330
diff --git a/posthog/hogql/scripts/hog_corpus_diagnostic.py b/posthog/hogql/scripts/hog_corpus_diagnostic.pyindex 07efd0eb7a5f..df6994fc59f3 100644--- a/posthog/hogql/scripts/hog_corpus_diagnostic.py+++ b/posthog/hogql/scripts/hog_corpus_diagnostic.py@@ -99,7 +99,8 @@ _REDACTION_PASSES: list[tuple[str, str]] = [(r"\yeyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]+", "<jwt>"),(r"\y[sprk]k_(live|test)_[A-Za-z0-9]{10,}", "<stripe_key>"),(r"\y(AKIA|ASIA)[A-Z0-9]{16}\y", "<aws_key>"),- (r"\ygh[posru]_[A-Za-z0-9]{30,}", "<gh_token>"),+ # `.`/`_`/`-` in the class: a `ghs_` installation token is `ghs_<app id>_<jwt>`.+ (r"\ygh[posru]_[A-Za-z0-9._-]{30,}", "<gh_token>"),(r"\ygithub_pat_[A-Za-z0-9_]{20,}", "<gh_token>"),(r"\yxox[bpoars]-[A-Za-z0-9-]{10,}", "<slack_token>"),(r"([0-9a-fA-F]{1,4}:){3,7}[0-9a-fA-F]{1,4}", "<ipv6>"),diff --git a/posthog/hogql/scripts/log_corpus_diagnostic.py b/posthog/hogql/scripts/log_corpus_diagnostic.pyindex ce51f327301f..905fac0706d2 100644--- a/posthog/hogql/scripts/log_corpus_diagnostic.py+++ b/posthog/hogql/scripts/log_corpus_diagnostic.py@@ -103,7 +103,8 @@ _REDACTION_PASSES: list[tuple[str, str]] = [(r"\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]+", "<jwt>"),(r"\b[sprk]k_(live|test)_[A-Za-z0-9]{10,}", "<stripe_key>"),(r"\b(AKIA|ASIA)[A-Z0-9]{16}\b", "<aws_key>"),- (r"\bgh[posru]_[A-Za-z0-9]{30,}", "<gh_token>"),+ # `.`/`_`/`-` in the class: a `ghs_` installation token is `ghs_<app id>_<jwt>`.+ (r"\bgh[posru]_[A-Za-z0-9._-]{30,}", "<gh_token>"),(r"\bgithub_pat_[A-Za-z0-9_]{20,}", "<gh_token>"),(r"\bxox[bpoars]-[A-Za-z0-9-]{10,}", "<slack_token>"),# IPv6 — 4+ colon-separated hex groups, so `HH:MM:SS` timestampsdiff --git a/posthog/hogql/test/test_corpus_redaction.py b/posthog/hogql/test/test_corpus_redaction.pynew file mode 100644index 000000000000..47434403377e--- /dev/null+++ b/posthog/hogql/test/test_corpus_redaction.py@@ -0,0 +1,30 @@+import re++from django.test import SimpleTestCase++from parameterized import parameterized++from posthog.hogql.scripts.hog_corpus_diagnostic import _REDACTION_PASSES as HOG_PASSES+from posthog.hogql.scripts.log_corpus_diagnostic import _REDACTION_PASSES as LOG_PASSES++STATELESS_INSTALLATION_TOKEN = "ghs_1234567_header-with-hyphen.payload_with_underscore.signature-with-hyphen"+++def _to_python_dialect(pattern: str) -> str:+ # Postgres spells the word boundary `\y`; Python and re2 both spell it `\b`.+ return pattern.replace(r"\y", r"\b")+++def _redact(passes: list[tuple[str, str]], text: str) -> str:+ for pattern, replacement in passes:+ text = re.sub(_to_python_dialect(pattern), replacement, text)+ return text+++class TestCorpusRedaction(SimpleTestCase):+ @parameterized.expand([("log", LOG_PASSES), ("hog", HOG_PASSES)])+ def test_stateless_github_token_is_redacted(self, _name: str, passes: list[tuple[str, str]]) -> None:+ redacted = _redact(passes, f"select '{STATELESS_INSTALLATION_TOKEN}'")++ assert STATELESS_INSTALLATION_TOKEN not in redacted+ assert "<gh_token>" in redacted