: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
rules:
- id: cross-org-bypass-user-organization
pattern-either:
# A: request.user.organization in permission has_permission methods
- patterns:
- pattern: $REQ.user.organization
- pattern-inside: |
def has_permission(self, $REQ, $VIEW):
...
# B: self.context["request"].user.organization (almost always wrong in serializers)
- pattern: self.context["request"].user.organization
# C: self.request.user.organization in viewsets with TeamAndOrgViewSetMixin
- patterns:
- pattern: self.request.user.organization
- pattern-inside: |
class $CLASS(..., TeamAndOrgViewSetMixin, ...):
...
message: >
Do not use `request.user.organization` to determine the current org in
org-scoped views. The user's "active" organization may differ from the
org in the URL, allowing cross-org access. Use
`get_organization_from_view(view)` in permission classes,
`self.context["view"].organization` in serializers, or
`self.organization` in viewsets with TeamAndOrgViewSetMixin.
severity: ERROR
languages: [python]
paths:
exclude:
- '**/test*/**'
- '**/.semgrep/**'