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.

14.9 KB
Raw Blame
{
  "_format": "Shared matching contract. The canonical copy lives in the security hub repository at test-vectors/access-rules.json. The PostHog Django repository keeps a copy at products/security/backend/tests/fixtures/access-rules.json; change both together. Each case's expect string has one letter per surface in the order signup, app, ai_gateway, email_code, signup_risk: B = blocked, A = allowed (email_code: code required), E = exempt (email_code: code skipped; signup_risk: Radar skipped). Rules are already normalized. The optional deciding map names the rule that must decide a surface. The optional destinations list names the external systems a rule on its own belongs in (cloudflare, contour, workos), and a rule without the list belongs in none. It answers eligibility, not outcome: a stronger rule on the same target can still hold a listed rule back, so a range that is blocked is not also challenged for that same range, and an address that is blocked is not also allowed. A block on a posthog.com address or domain belongs in no destination, whatever its scope. Overlapping ranges are not resolved here, so a blocked /24 inside a challenged /16 reaches both lists.",
  "suites": [
    {
      "name": "blocks and per-email exemptions",
      "now": "2026-09-17T12:00:00Z",
      "rules": [
        {"id": "01920000-0000-7000-8000-000000000001", "targetType": "email_root", "targetValue": "[email protected]", "effect": "block", "scope": "all_access", "expiresAt": null, "destinations": []},
        {"id": "01920000-0000-7000-8000-000000000002", "targetType": "email_domain", "targetValue": "throwaway.example", "effect": "block", "scope": "all_access", "expiresAt": null, "destinations": ["workos"]},
        {"id": "01920000-0000-7000-8000-000000000003", "targetType": "email_domain", "targetValue": "mailinator.com", "effect": "block", "scope": "signup", "expiresAt": null, "destinations": ["workos"]},
        {"id": "01920000-0000-7000-8000-000000000004", "targetType": "organization_id", "targetValue": "1111aaaa-1111-4111-8111-11111111aaaa", "effect": "block", "scope": "ai_gateway", "expiresAt": null},
        {"id": "01920000-0000-7000-8000-000000000005", "targetType": "email_root", "targetValue": "[email protected]", "effect": "block", "scope": "ai_gateway", "expiresAt": null},
        {"id": "01920000-0000-7000-8000-000000000006", "targetType": "ip", "targetValue": "93.184.216.0/24", "effect": "block", "scope": "all_access", "expiresAt": null, "destinations": ["cloudflare", "contour"]},
        {"id": "01920000-0000-7000-8000-000000000007", "targetType": "user_uuid", "targetValue": "2222abcd-2222-4222-8222-22222222abcd", "effect": "block", "scope": "all_access", "expiresAt": null},
        {"id": "01920000-0000-7000-8000-000000000008", "targetType": "ip", "targetValue": "203.0.113.0/24", "effect": "block", "scope": "all_access", "expiresAt": "2026-09-01T00:00:00Z", "destinations": ["cloudflare", "contour"]},
        {"id": "01920000-0000-7000-8000-000000000009", "targetType": "email_domain", "targetValue": "posthog.com", "effect": "block", "scope": "all_access", "expiresAt": null, "destinations": []},
        {"id": "01920000-0000-7000-8000-000000000010", "targetType": "user_uuid", "targetValue": "3333abcd-3333-4333-8333-33333333abcd", "effect": "block", "scope": "all_access", "expiresAt": null},
        {"id": "01920000-0000-7000-8000-000000000011", "targetType": "email", "targetValue": "[email protected]", "effect": "exempt", "scope": "email_code", "expiresAt": null, "destinations": []},
        {"id": "01920000-0000-7000-8000-000000000012", "targetType": "email", "targetValue": "[email protected]", "effect": "exempt", "scope": "email_code", "expiresAt": null},
        {"id": "01920000-0000-7000-8000-000000000013", "targetType": "everyone", "targetValue": "", "effect": "exempt", "scope": "email_code", "expiresAt": "2026-09-10T00:00:00Z"},
        {"id": "01920000-0000-7000-8000-000000000014", "targetType": "team_id", "targetValue": "42", "effect": "block", "scope": "ai_gateway", "expiresAt": null},
        {"id": "01920000-0000-7000-8000-000000000015", "targetType": "email", "targetValue": "[email protected]", "effect": "block", "scope": "future_scope", "expiresAt": null},
        {"id": "01920000-0000-7000-8000-000000000016", "targetType": "email", "targetValue": "[email protected]", "effect": "limit", "scope": "all_access", "expiresAt": null},
        {"id": "01920000-0000-7000-8000-000000000017", "targetType": "email", "targetValue": "[email protected]", "effect": "exempt", "scope": "all_access", "expiresAt": null},
        {"id": "01920000-0000-7000-8000-000000000018", "targetType": "ip", "targetValue": "198.18.0.0/24", "effect": "challenge", "scope": "all_access", "expiresAt": null, "destinations": ["cloudflare"]},
        {"id": "01920000-0000-7000-8000-000000000019", "targetType": "email", "targetValue": "[email protected]", "effect": "exempt", "scope": "signup_risk", "expiresAt": null, "destinations": ["workos"]},
        {"id": "01920000-0000-7000-8000-000000000020", "targetType": "email_domain", "targetValue": "partner.example", "effect": "exempt", "scope": "signup_risk", "expiresAt": null, "destinations": ["workos"]},
        {"id": "01920000-0000-7000-8000-000000000021", "targetType": "email", "targetValue": "[email protected]", "effect": "block", "scope": "all_access", "expiresAt": null, "destinations": ["workos"]},
        {"id": "01920000-0000-7000-8000-000000000022", "targetType": "email", "targetValue": "[email protected]", "effect": "exempt", "scope": "signup_risk", "expiresAt": null, "destinations": ["workos"]}
      ],
      "cases": [
        {"name": "alias of an email root", "subject": {"email": "[email protected]"}, "expect": "BBBAA"},
        {"name": "upper-case alias of an email root", "subject": {"email": "[email protected]"}, "expect": "BBBAA"},
        {"name": "email root with spaces", "subject": {"email": " [email protected] "}, "expect": "BBBAA"},
        {"name": "dots matter outside gmail", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "different domain", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "cyrillic lookalike", "subject": {"email": "fа[email protected]"}, "expect": "AAAAA"},
        {"name": "member of a blocked organization", "subject": {"email": "[email protected]", "organizationIds": ["1111aaaa-1111-4111-8111-11111111aaaa"]}, "expect": "AABAA"},
        {"name": "member of a bystander organization", "subject": {"email": "[email protected]", "organizationIds": ["4444aaaa-4444-4444-8444-44444444aaaa"]}, "expect": "AAAAA"},
        {"name": "blocked organization by id", "subject": {"organizationIds": ["1111AAAA-1111-4111-8111-11111111AAAA"]}, "expect": "AABAA"},
        {"name": "bystander organization by id", "subject": {"organizationIds": ["4444aaaa-4444-4444-8444-44444444aaaa"]}, "expect": "AAAAA"},
        {"name": "blocked user by email and uuid", "subject": {"email": "[email protected]", "userUuid": "2222abcd-2222-4222-8222-22222222abcd"}, "expect": "BBBAA"},
        {"name": "blocked user by upper-case uuid", "subject": {"userUuid": "2222ABCD-2222-4222-8222-22222222ABCD"}, "expect": "BBBAA"},
        {"name": "gmail root through googlemail", "subject": {"email": "[email protected]"}, "expect": "AABAA"},
        {"name": "different gmail mailbox", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "subdomain of a blocked domain", "subject": {"email": "[email protected]"}, "expect": "BBBAA"},
        {"name": "blocked domain on its own", "subject": {"domain": "throwaway.example"}, "expect": "BBBAA"},
        {"name": "blocked domain inside another domain", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "shared suffix only", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "unrelated domain", "subject": {"domain": "example.com"}, "expect": "AAAAA"},
        {"name": "signup-only domain", "subject": {"email": "[email protected]"}, "expect": "BAAAA"},
        {"name": "first address of a blocked range", "subject": {"ip": "93.184.216.0"}, "expect": "BBBAA"},
        {"name": "last address of a blocked range", "subject": {"ip": "93.184.216.255"}, "expect": "BBBAA"},
        {"name": "mapped address in a blocked range", "subject": {"ip": "::ffff:93.184.216.34"}, "expect": "BBBAA"},
        {"name": "address after the range", "subject": {"ip": "93.184.217.0"}, "expect": "AAAAA"},
        {"name": "address before the range", "subject": {"ip": "93.184.215.255"}, "expect": "AAAAA"},
        {"name": "mapped address outside the range", "subject": {"ip": "::ffff:93.184.217.1"}, "expect": "AAAAA"},
        {"name": "loopback", "subject": {"ip": "127.0.0.1"}, "expect": "AAAAA"},
        {"name": "address in an expired rule's range", "subject": {"ip": "203.0.113.5"}, "expect": "AAAAA"},
        {"name": "unreadable address", "subject": {"ip": "not-an-ip"}, "expect": "AAAAA"},
        {"name": "empty subject", "subject": {}, "expect": "AAAAA"},
        {"name": "clean email from a blocked range", "subject": {"email": "[email protected]", "ip": "93.184.216.1"}, "expect": "BBBAA"},
        {"name": "oldest matching rule decides", "subject": {"email": "[email protected]", "ip": "93.184.216.1"}, "expect": "BBBAA", "deciding": {"signup": "01920000-0000-7000-8000-000000000001", "ai_gateway": "01920000-0000-7000-8000-000000000001"}},
        {"name": "posthog.com account with matching blocks and an exemption", "subject": {"email": "[email protected]", "userUuid": "3333abcd-3333-4333-8333-33333333abcd"}, "expect": "AAAEA"},
        {"name": "posthog.com alias", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "posthog.com subdomain", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "posthog.com account on a blocked range", "subject": {"email": "[email protected]", "ip": "93.184.216.10"}, "expect": "AAAEA"},
        {"name": "exempt email", "subject": {"email": "[email protected]"}, "expect": "AAAEA"},
        {"name": "exempt email in mixed case", "subject": {"email": "[email protected]"}, "expect": "AAAEA"},
        {"name": "alias of an exempt email", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "unknown type, scope and effect match nothing", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "challenged range is not blocked in Django", "subject": {"ip": "198.18.0.9"}, "expect": "AAAAA"},
        {"name": "signup risk exemption by email", "subject": {"email": "[email protected]"}, "expect": "AAAAE"},
        {"name": "signup risk exemption by domain covers subdomains", "subject": {"email": "[email protected]"}, "expect": "AAAAE"},
        {"name": "a signup risk exemption does not lift a block on the same address", "subject": {"email": "[email protected]"}, "expect": "BBBAE", "deciding": {"app": "01920000-0000-7000-8000-000000000021", "signup_risk": "01920000-0000-7000-8000-000000000022"}}
      ]
    },
    {
      "name": "global MFA bypass",
      "now": "2026-09-17T12:00:00Z",
      "rules": [
        {"id": "01920000-0000-7000-8000-000000000101", "targetType": "everyone", "targetValue": "", "effect": "exempt", "scope": "email_code", "expiresAt": "2026-09-20T00:00:00Z"}
      ],
      "cases": [
        {"name": "any email", "subject": {"email": "[email protected]"}, "expect": "AAAEA"},
        {"name": "empty subject", "subject": {}, "expect": "AAAEA"},
        {"name": "posthog.com account", "subject": {"email": "[email protected]"}, "expect": "AAAEA"}
      ]
    },
    {
      "name": "email patterns",
      "now": "2026-09-17T12:00:00Z",
      "rules": [
        {"id": "01920000-0000-7000-8000-000000000201", "targetType": "email_pattern", "targetValue": "farm_acct_*@*", "effect": "block", "scope": "ai_gateway", "expiresAt": null},
        {"id": "01920000-0000-7000-8000-000000000202", "targetType": "email_pattern", "targetValue": "abuser*@example.com", "effect": "block", "scope": "all_access", "expiresAt": null},
        {"id": "01920000-0000-7000-8000-000000000203", "targetType": "email_pattern", "targetValue": "farm.bot+*@example.org", "effect": "block", "scope": "signup", "expiresAt": null},
        {"id": "01920000-0000-7000-8000-000000000204", "targetType": "email_pattern", "targetValue": "dotted.victim*@gmail.com", "effect": "block", "scope": "all_access", "expiresAt": null},
        {"id": "01920000-0000-7000-8000-000000000205", "targetType": "email_pattern", "targetValue": "bot?[1]*@*.example.net", "effect": "block", "scope": "all_access", "expiresAt": null}
      ],
      "cases": [
        {"name": "wildcard domain", "subject": {"email": "[email protected]"}, "expect": "AABAA", "deciding": {"ai_gateway": "01920000-0000-7000-8000-000000000201"}},
        {"name": "matching ignores case", "subject": {"email": " [email protected] "}, "expect": "AABAA"},
        {"name": "a star can match nothing", "subject": {"email": "[email protected]"}, "expect": "BBBAA"},
        {"name": "a star can match a +suffix", "subject": {"email": "[email protected]"}, "expect": "BBBAA"},
        {"name": "an underscore matches only itself", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "the pattern covers the start of the address", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "the pattern covers the end of the address", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "a literal domain does not cover subdomains", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "a dot and a plus match only themselves", "subject": {"email": "[email protected]"}, "expect": "BAAAA"},
        {"name": "a dot is not a single-character wildcard", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "a plus is not a repeat", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "the full address is matched, not the email root", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "the dotted address matches", "subject": {"email": "[email protected]"}, "expect": "BBBAA"},
        {"name": "question mark and brackets match only themselves", "subject": {"email": "bot?[1][email protected]"}, "expect": "BBBAA"},
        {"name": "question mark is not a single-character wildcard", "subject": {"email": "botx[1][email protected]"}, "expect": "AAAAA"},
        {"name": "brackets are not a character class", "subject": {"email": "[email protected]"}, "expect": "AAAAA"},
        {"name": "a domain alone matches no pattern", "subject": {"domain": "example.com"}, "expect": "AAAAA"},
        {"name": "a posthog.com account is never blocked", "subject": {"email": "[email protected]"}, "expect": "AAAAA"}
      ]
    }
  ]
}