Files
insights/.semgrep/rules/security/cross-org-bypass-user-organization.py
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

74 lines
2.1 KiB
Python

from rest_framework import serializers, viewsets
from rest_framework.permissions import BasePermission
# === SHOULD MATCH (ruleid) ===
# A: request.user.organization in has_permission
class BadPermission(BasePermission):
def has_permission(self, request, view):
# ruleid: cross-org-bypass-user-organization
org = request.user.organization
return True
# B: self.context["request"].user.organization in serializer
class BadSerializer(serializers.ModelSerializer):
def validate_name(self, name):
# ruleid: cross-org-bypass-user-organization
org = self.context["request"].user.organization
return name
# C: self.request.user.organization in viewset
class BadViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
def get_org(self):
# ruleid: cross-org-bypass-user-organization
return self.request.user.organization
# === SHOULD NOT MATCH (ok) ===
# Safe: get_organization_from_view
class GoodPermission(BasePermission):
def has_permission(self, request, view):
# ok: cross-org-bypass-user-organization
org = get_organization_from_view(view)
return True
# Safe: self.context["view"].organization
class GoodSerializer(serializers.ModelSerializer):
def create(self, validated_data):
# ok: cross-org-bypass-user-organization
org = self.context["view"].organization
return super().create(validated_data)
# Safe: self.organization in viewset
class GoodViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
def get_org(self):
# ok: cross-org-bypass-user-organization
return self.organization
# Safe: standalone view (not org-nested)
def saml_view(request):
# ok: cross-org-bypass-user-organization
org = request.user.organization
return org
# === KNOWN LIMITATION (todoruleid) ===
# Aliased variable — can't catch without taint mode
class AliasedPermission(BasePermission):
def has_permission(self, request, view):
user = request.user
# todoruleid: cross-org-bypass-user-organization
org = user.organization
return True