: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
feat(toolbar): add resource-level access control (#69730)
Reece Jones4f6e54b4640e
diff --git a/common/storybook/.storybook/app-context.ts b/common/storybook/.storybook/app-context.tsindex 947be181c034..6df627095334 100644--- a/common/storybook/.storybook/app-context.ts+++ b/common/storybook/.storybook/app-context.ts@@ -90,6 +90,7 @@ export const getStorybookAppContext = (): AppContext => ({activity_log: 'viewer',customer_analytics: 'manager',llm_analytics: 'manager',+ toolbar: 'viewer',error_tracking: 'manager',metrics: 'manager',},diff --git a/ee/api/rbac/test/test_access_control.py b/ee/api/rbac/test/test_access_control.pyindex 29723f2d335e..9b25a8b866a7 100644--- a/ee/api/rbac/test/test_access_control.py+++ b/ee/api/rbac/test/test_access_control.py@@ -188,6 +188,17 @@ class TestAccessControlMinimumLevelValidation(BaseAccessControlTest):assert res.status_code == status.HTTP_400_BAD_REQUEST, f"Failed for level {level}: {res.json()}"assert "cannot be set above the maximum 'viewer'" in res.json()["detail"]+ def test_toolbar_access_level_cannot_be_above_viewer(self):+ self._org_membership(OrganizationMembership.Level.ADMIN)++ for level in ["editor", "manager"]:+ res = self.client.put(+ "/api/projects/@current/resource_access_controls",+ {"resource": "toolbar", "access_level": level},+ )+ assert res.status_code == status.HTTP_400_BAD_REQUEST, f"Failed for level {level}: {res.json()}"+ assert "cannot be set above the maximum 'viewer'" in res.json()["detail"]+def test_activity_log_access_restricted_for_users_without_access(self):"""Test that users without access to activity_log cannot access activity log endpoints"""self._org_membership(OrganizationMembership.Level.ADMIN)diff --git a/frontend/bin/check-toolbar-graph.mjs b/frontend/bin/check-toolbar-graph.mjsindex 8c2e5b9c9bed..811637e02ad8 100644--- a/frontend/bin/check-toolbar-graph.mjs+++ b/frontend/bin/check-toolbar-graph.mjs@@ -41,7 +41,7 @@ const FORBIDDEN_PACKAGES = [// Ratchet policy: when an edge is cut, lower the budget to lock it in; raise it only as a// conscious, reviewed decision in the PR that needs it. There is headroom for churn, but any// reintroduced leak jumps the graph back toward ~100 MiB and fails loudly.-const TOTAL_INPUT_BYTES_BUDGET = 14_450_000+const TOTAL_INPUT_BYTES_BUDGET = 14_460_000function fail(message) {console.error(`\n❌ ${message}`)diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 908789d84b6a..8e90d2f54e40 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6935,9 +6935,9 @@ snapshots:scenes-app-settings-authentication-domains--one-unverified-domain--light:hash: v1.k794b7964.b1ae6dbc8feb673159fcc13f4a8fd5ee856c63ad1204e839a1b55ef70d109c81.W5sqRIJDHcdkKlYg4ghfwpbKS2FmlQKF_N-1C83h9Mgscenes-app-settings-environment--settings-environment-access-control--dark:- hash: v1.k794b7964.8d73f87a3b30d6050d0cce96ae5b5a1f1d04ca4ed20ea6d33128799b4e866086.Q4BdkuCspveuLWJL6wvil-f3Bdqqh0b7yray2lve2Wo+ hash: v1.k794b7964.f0c837b6c5d1c5314f2ba768e843900490a282acafbabcc3dda9d6c23a936985.1tSvgzXNssLetAF7ZfGyEoY_whaDHGIzvuImLTGmOkAscenes-app-settings-environment--settings-environment-access-control--light:- hash: v1.k794b7964.0f820d1e3e3fd1883c6b16086b9918b7d39217a42c1f6a26c042e26ef6aad588.JVSCnRYcyC6Qxj82Z6inZJeAQ6uGNY8WQoabzYvC9VE+ hash: v1.k794b7964.8e6e03e733477128947f48a00c106621bd89b31c6c3e7e5a7c22220bcd413a59.2gfPtWtNG5V5f9FcZoBY5YIDO0WXU2Q6ovz0BxC4NXkscenes-app-settings-environment--settings-environment-autocapture--dark:hash: v1.k794b7964.2183cf0082a1556d6df553572df4ab3813c96288a8b9a80e669c005908230c3e.-ybX8d6KyxaSa-yJDVccZm2CkK8Fl8qLSbw9jGhSIx4scenes-app-settings-environment--settings-environment-autocapture--light:diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/ScopeIcon.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/ScopeIcon.tsxindex 59d77d8d0058..b097b2f5d10a 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/ScopeIcon.tsx+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/ScopeIcon.tsx@@ -23,6 +23,7 @@ import {IconRocket,IconSpotlight,IconToggle,+ IconToolbar,IconTrends,IconWarning,} from '@posthog/icons'@@ -89,6 +90,8 @@ export function ScopeIcon(props: { scope: APIScopeObject }): JSX.Element | nullreturn <IconPieChart />case 'tracing':return <IconListTree />+ case 'toolbar':+ return <IconToolbar />default:return null}diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/accessControlsLogic.ts b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/accessControlsLogic.tsindex e51362727d4f..8a4b31f85375 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/accessControlsLogic.ts+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/accessControlsLogic.ts@@ -397,6 +397,7 @@ export interface accessControlsLogicActions {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -532,6 +533,7 @@ export interface accessControlsLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -671,6 +673,7 @@ export interface accessControlsLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -783,6 +786,7 @@ export interface accessControlsLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/groupedAccessControlRuleModalLogic.ts b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/groupedAccessControlRuleModalLogic.tsindex 5fe17c727d40..cc07ff8cb083 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/groupedAccessControlRuleModalLogic.ts+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/groupedAccessControlRuleModalLogic.ts@@ -118,6 +118,7 @@ export interface groupedAccessControlRuleModalLogicValues {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -234,6 +235,7 @@ export interface groupedAccessControlRuleModalLogicValues {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -342,6 +344,7 @@ export interface groupedAccessControlRuleModalLogicValues {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -463,6 +466,7 @@ export interface groupedAccessControlRuleModalLogicValues {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -584,6 +588,7 @@ export interface groupedAccessControlRuleModalLogicActions {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -712,6 +717,7 @@ export interface groupedAccessControlRuleModalLogicActions {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -820,6 +826,7 @@ export interface groupedAccessControlRuleModalLogicActions {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -967,6 +974,7 @@ export interface groupedAccessControlRuleModalLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -1077,6 +1085,7 @@ export interface groupedAccessControlRuleModalLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -1186,6 +1195,7 @@ export interface groupedAccessControlRuleModalLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -1295,6 +1305,7 @@ export interface groupedAccessControlRuleModalLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -1405,6 +1416,7 @@ export interface groupedAccessControlRuleModalLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -1514,6 +1526,7 @@ export interface groupedAccessControlRuleModalLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -1634,6 +1647,7 @@ export interface groupedAccessControlRuleModalLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -1743,6 +1757,7 @@ export interface groupedAccessControlRuleModalLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/accessControlLogic.ts b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/accessControlLogic.tsindex e48ad3bc520d..ae9e068e7aca 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/accessControlLogic.ts+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/accessControlLogic.ts@@ -394,6 +394,7 @@ export interface accessControlLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -606,6 +607,7 @@ export interface accessControlLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'@@ -715,6 +717,7 @@ export interface accessControlLogicMeta {| 'tagger'| 'task'| 'ticket'+ | 'toolbar'| 'tracing'| 'uploaded_media'| 'usage_metric'diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/resourcesAccessControlLogic.ts b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/resourcesAccessControlLogic.tsindex 3353abe1f092..d46de141c9c9 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/resourcesAccessControlLogic.ts+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/resourcesAccessControlLogic.ts@@ -187,6 +187,7 @@ export const resourcesAccessControlLogic = kea<resourcesAccessControlLogicType>(AccessControlResourceType.ErrorTracking,AccessControlResourceType.Survey,AccessControlResourceType.WebAnalytics,+ AccessControlResourceType.Toolbar,AccessControlResourceType.Workflow,AccessControlResourceType.Tracing,]diff --git a/frontend/src/lib/components/IframedToolbarBrowser/IframedToolbarBrowser.tsx b/frontend/src/lib/components/IframedToolbarBrowser/IframedToolbarBrowser.tsxindex 5ee7dfcb490f..7237dc137c71 100644--- a/frontend/src/lib/components/IframedToolbarBrowser/IframedToolbarBrowser.tsx+++ b/frontend/src/lib/components/IframedToolbarBrowser/IframedToolbarBrowser.tsx@@ -4,7 +4,9 @@ import useResizeObserver from 'use-resize-observer'import { LemonBanner, Spinner } from '@posthog/lemon-ui'-import { ToolbarUserIntent } from '~/types'+import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'++import { AccessControlLevel, AccessControlResourceType, ToolbarUserIntent } from '~/types'import { appEditorUrl } from '../AuthorizedUrlList/authorizedUrlListLogic'import { UserIntentVerb, iframedToolbarBrowserLogic } from './iframedToolbarBrowserLogic'@@ -49,6 +51,19 @@ export function IframedToolbarBrowser({setIframeWidth(iframeWidth ?? null)}, [iframeWidth, setIframeWidth])+ const toolbarAccessDisabledReason = getAccessControlDisabledReason(+ AccessControlResourceType.Toolbar,+ AccessControlLevel.Viewer+ )++ if (toolbarAccessDisabledReason) {+ return (+ <div className="relative flex-1 w-full h-full flex items-center justify-center p-4">+ <LemonBanner type="error">{toolbarAccessDisabledReason}</LemonBanner>+ </div>+ )+ }+return browserUrl ? (<div className="relative flex-1 w-full h-full"><IframeErrorOverlay userIntent={userIntent} />diff --git a/frontend/src/lib/scopes.tsx b/frontend/src/lib/scopes.tsxindex 006e93e2d46c..70243338de32 100644--- a/frontend/src/lib/scopes.tsx+++ b/frontend/src/lib/scopes.tsx@@ -190,6 +190,7 @@ export const API_SCOPES: APIScope[] = [},{ key: 'tagger', objectName: 'Tagger', objectPlural: 'taggers' },{ key: 'ticket', objectName: 'Ticket', objectPlural: 'tickets' },+ { key: 'toolbar', objectName: 'Toolbar', objectPlural: 'toolbar' },{ key: 'tracing', objectName: 'Tracing', objectPlural: 'tracing' },{ key: 'field_note', objectName: 'Field note', objectPlural: 'field notes' },{ key: 'uploaded_media', objectName: 'Uploaded media', objectPlural: 'uploaded media' },diff --git a/frontend/src/lib/utils/accessControlUtils.ts b/frontend/src/lib/utils/accessControlUtils.tsindex 1e5feec3f35b..217ed8a0abf8 100644--- a/frontend/src/lib/utils/accessControlUtils.ts+++ b/frontend/src/lib/utils/accessControlUtils.ts@@ -43,7 +43,7 @@ export const getMinimumAccessLevel = (resource: APIScopeObject): AccessControlLe* @returns The maximum access level required, or null if no maximum is set*/export const getMaximumAccessLevel = (resource: APIScopeObject): AccessControlLevel | null => {- if (resource === AccessControlResourceType.ActivityLog) {+ if (resource === AccessControlResourceType.ActivityLog || resource === AccessControlResourceType.Toolbar) {return AccessControlLevel.Viewer}return null@@ -80,6 +80,8 @@ export const pluralizeResource = (resource: APIScopeObject): string => {return 'metrics'} else if (resource === AccessControlResourceType.Tracing) {return 'tracing'+ } else if (resource === AccessControlResourceType.Toolbar) {+ return 'toolbar'} else if (resource === AccessControlResourceType.Workflow) {return 'workflows'}@@ -98,7 +100,7 @@ export const orderedAccessLevels = (resourceType: AccessControlResourceType): Acif (resourceType === AccessControlResourceType.Project || resourceType === AccessControlResourceType.Organization) {return [AccessControlLevel.None, AccessControlLevel.Member, AccessControlLevel.Admin]}- if (resourceType === AccessControlResourceType.ActivityLog) {+ if (resourceType === AccessControlResourceType.ActivityLog || resourceType === AccessControlResourceType.Toolbar) {return [AccessControlLevel.None, AccessControlLevel.Viewer]}return [AccessControlLevel.None, AccessControlLevel.Viewer, AccessControlLevel.Editor, AccessControlLevel.Manager]diff --git a/frontend/src/scenes/heatmaps/components/HeatmapsBrowser.tsx b/frontend/src/scenes/heatmaps/components/HeatmapsBrowser.tsxindex fd3240fe834b..2ceab6910269 100644--- a/frontend/src/scenes/heatmaps/components/HeatmapsBrowser.tsx+++ b/frontend/src/scenes/heatmaps/components/HeatmapsBrowser.tsx@@ -102,6 +102,11 @@ function UrlSearchHeader({ iframeRef }: { iframeRef?: React.MutableRefObject<HTMconst placeholderUrl = browserUrlSearchOptions?.[0] ?? 'https://your-website.com/pricing'+ const toolbarAccessDisabledReason = getAccessControlDisabledReason(+ AccessControlResourceType.Toolbar,+ AccessControlLevel.Viewer+ )+return (<><div className="flex-none md:flex justify-between items-end gap-2 w-full">@@ -168,7 +173,7 @@ function UrlSearchHeader({ iframeRef }: { iframeRef?: React.MutableRefObject<HTMdisabledReason={!displayUrl && !dataUrl && !hasValidReplayIframeData? 'Select a URL first'- : undefined+ : toolbarAccessDisabledReason}size="small"data-attr="heatmaps-open-in-toolbar"diff --git a/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapScene.tsx b/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapScene.tsxindex 9ad9313336e5..299142304b03 100644--- a/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapScene.tsx+++ b/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapScene.tsx@@ -12,6 +12,7 @@ import { MAX_HEATMAP_HEIGHT } from 'lib/components/heatmaps/heatmapDataLogic'import { LemonBanner } from 'lib/lemon-ui/LemonBanner/LemonBanner'import { LemonButton } from 'lib/lemon-ui/LemonButton'import { LoadingBar } from 'lib/lemon-ui/LoadingBar'+import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'import { FilterPanel } from 'scenes/heatmaps/components/FilterPanel'import { HeatmapHeader } from 'scenes/heatmaps/components/HeatmapHeader'import { urls } from 'scenes/urls'@@ -19,6 +20,7 @@ import { urls } from 'scenes/urls'import { SceneContent } from '~/layout/scenes/components/SceneContent'import { SceneDivider } from '~/layout/scenes/components/SceneDivider'import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'+import { AccessControlLevel, AccessControlResourceType } from '~/types'import { heatmapLogic } from './heatmapLogic'@@ -55,6 +57,11 @@ export function HeatmapScene({ id }: { id: string }): JSX.Element {setContainerWidth,} = useActions(logic)+ const toolbarAccessDisabledReason = getAccessControlDisabledReason(+ AccessControlResourceType.Toolbar,+ AccessControlLevel.Viewer+ )+const measureRef = useRef<HTMLDivElement | null>(null)useEffect(() => {const measure = (): void => {@@ -134,7 +141,7 @@ export function HeatmapScene({ id }: { id: string }): JSX.Element {: undefined,targetBlank: true,'data-attr': 'heatmaps-open-in-toolbar',- disabledReason: !displayUrl ? 'Select a URL first' : undefined,+ disabledReason: !displayUrl ? 'Select a URL first' : toolbarAccessDisabledReason,}}>You can also open your website using the toolbar and verify results there (useful for auth-protecteddiff --git a/frontend/src/scenes/persons/PersonScene.tsx b/frontend/src/scenes/persons/PersonScene.tsxindex c5f9d5c52f53..ea69de2e4b93 100644--- a/frontend/src/scenes/persons/PersonScene.tsx+++ b/frontend/src/scenes/persons/PersonScene.tsx@@ -18,6 +18,7 @@ import { LemonTabs } from 'lib/lemon-ui/LemonTabs'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'import { SpinnerOverlay } from 'lib/lemon-ui/Spinner/Spinner'import { Tooltip } from 'lib/lemon-ui/Tooltip'+import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'import { copyToClipboard } from 'lib/utils/copyToClipboard'import { isMobile } from 'lib/utils/dom'import { pluralize } from 'lib/utils/strings'@@ -39,7 +40,14 @@ import { SceneDivider } from '~/layout/scenes/components/SceneDivider'import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'import { Query } from '~/queries/Query/Query'import { ProductIntentContext, ProductKey } from '~/queries/schema/schema-general'-import { ActivityScope, PersonType, PersonsTabType, PropertyDefinitionType } from '~/types'+import {+ AccessControlLevel,+ AccessControlResourceType,+ ActivityScope,+ PersonType,+ PersonsTabType,+ PropertyDefinitionType,+} from '~/types'import { ComposeTicketButton } from 'products/conversations/frontend/components/ComposeTicket'import { FeedbackButton } from 'products/customer_analytics/frontend/components/FeedbackButton'@@ -137,6 +145,11 @@ interface LaunchToolbarButtonProps {function LaunchToolbarButton({ distinctId }: LaunchToolbarButtonProps): JSX.Element {const { currentTeam } = useValues(teamLogic)+ const toolbarAccessDisabledReason = getAccessControlDisabledReason(+ AccessControlResourceType.Toolbar,+ AccessControlLevel.Viewer+ )+const handleLaunchToolbar = async (targetUrl: string): Promise<void> => {if (!currentTeam?.app_urls?.length) {lemonToast.error('No authorized URLs configured. Please add a URL in Toolbar settings.')@@ -173,6 +186,7 @@ function LaunchToolbarButton({ distinctId }: LaunchToolbarButtonProps): JSX.Elem}))}placeholder="Launch toolbar with this user's feature flags"onChange={(value) => value && handleLaunchToolbar(value)}+ disabledReason={toolbarAccessDisabledReason}/>)}diff --git a/frontend/src/scenes/sceneTypes.ts b/frontend/src/scenes/sceneTypes.tsindex 1b3604eb47c8..62bf8466c94e 100644--- a/frontend/src/scenes/sceneTypes.ts+++ b/frontend/src/scenes/sceneTypes.ts@@ -338,6 +338,9 @@ export const sceneToAccessControlResourceType: Partial<Record<Scene, AccessContr// Revenue analytics[Scene.RevenueAnalytics]: AccessControlResourceType.RevenueAnalytics,+ // Toolbar+ [Scene.ToolbarLaunch]: AccessControlResourceType.Toolbar,+// Web Analytics[Scene.WebAnalytics]: AccessControlResourceType.WebAnalytics,[Scene.WebAnalyticsPageReports]: AccessControlResourceType.WebAnalytics,diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex 30d8489d35ac..98006e962f95 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -307,6 +307,7 @@ export enum AccessControlResourceType {ActivityLog = 'activity_log',ErrorTracking = 'error_tracking',Tracing = 'tracing',+ Toolbar = 'toolbar',}interface UserBaseType {@@ -5769,6 +5770,7 @@ export const API_SCOPE_OBJECTS = ['tagger','ticket','task',+ 'toolbar','tracing','field_note','uploaded_media',diff --git a/posthog/api/test/test_toolbar_oauth_endpoint_auth.py b/posthog/api/test/test_toolbar_oauth_endpoint_auth.pyindex 45934a414506..bab06b7762ab 100644--- a/posthog/api/test/test_toolbar_oauth_endpoint_auth.py+++ b/posthog/api/test/test_toolbar_oauth_endpoint_auth.py@@ -21,12 +21,18 @@ from posthog.constants import AvailableFeaturefrom posthog.models.oauth import OAuthAccessToken, OAuthApplicationfrom posthog.models.organization import OrganizationMembershipfrom posthog.models.personal_api_key import PersonalAPIKey, hash_key_value+from posthog.models.team import Teamfrom posthog.models.utils import generate_random_token_personal+try:+ from ee.models.rbac.access_control import AccessControl+except ImportError:+ pass-def _make_oauth_app(organization, user):++def _make_oauth_app(organization, user, name="Toolbar Test App"):return OAuthApplication.objects.create(- name="Toolbar Test App",+ name=name,client_type=OAuthApplication.CLIENT_CONFIDENTIAL,authorization_grant_type=OAuthApplication.GRANT_AUTHORIZATION_CODE,redirect_uris="https://example.com/callback",@@ -360,6 +366,82 @@ class TestToolbarOAuthScopesConfig(APIBaseTest):assert "*" not in settings.TOOLBAR_OAUTH_SCOPES, "Toolbar should use specific scopes, not wildcard"+class TestToolbarAccessTokenRevocation(APIBaseTest):+ """+ A toolbar OAuth access token is only checked against the `toolbar` access level when+ it's minted. Without a re-check on every request, a token minted before access was+ revoked would keep authenticating until its natural expiry.+ """++ def setUp(self):+ super().setUp()+ self.organization.available_product_features = [+ {"key": AvailableFeature.ACCESS_CONTROL, "name": AvailableFeature.ACCESS_CONTROL},+ ]+ self.organization.save()+ self.toolbar_app = _make_oauth_app(self.organization, self.user, name=settings.TOOLBAR_OAUTH_APPLICATION_NAME)+ self.token = _make_token(+ self.user,+ self.toolbar_app,+ "pha_toolbar_revocation",+ scope=" ".join(settings.TOOLBAR_OAUTH_SCOPES),+ )+ self.token.scoped_teams = [self.team.id]+ self.token.save()++ def _deny_toolbar_access(self):+ membership = OrganizationMembership.objects.get(user=self.user, organization=self.organization)+ AccessControl.objects.create(+ team=self.team,+ resource="toolbar",+ resource_id=None,+ access_level="none",+ organization_member=membership,+ )++ def _get(self):+ self.client.logout()+ return self.client.get(+ f"/api/projects/{self.team.id}/actions/",+ HTTP_AUTHORIZATION=f"Bearer {self.token.token}",+ )++ def test_token_authenticates_before_revocation(self):+ assert self._get().status_code not in (401, 403)++ def test_token_rejected_after_toolbar_access_revoked(self):+ # AuthenticationFailed maps to 401 here, same as the expired/invalid token+ # cases above - this authenticator declares an authenticate_header, so DRF+ # treats a rejection as "not authenticated" rather than "forbidden".+ self._deny_toolbar_access()+ assert self._get().status_code == 401++ def test_token_rejected_when_scoped_to_no_team(self):+ self.token.scoped_teams = []+ self.token.save()+ assert self._get().status_code == 401++ def test_token_rejected_when_scoped_to_multiple_teams(self):+ other_team = Team.objects.create(organization=self.organization, name="Other team")+ self.token.scoped_teams = [self.team.id, other_team.id]+ self.token.save()+ assert self._get().status_code == 401++ def test_non_toolbar_app_token_unaffected_by_toolbar_access_revocation(self):+ """The revocation re-check is gated on the token's OAuth application being the+ toolbar app - it must not affect tokens minted by any other OAuth client."""+ self._deny_toolbar_access()+ other_app = _make_oauth_app(self.organization, self.user, name="Some other app")+ other_token = _make_token(self.user, other_app, "pha_other_app", scope="action:read")++ self.client.logout()+ response = self.client.get(+ f"/api/projects/{self.team.id}/actions/",+ HTTP_AUTHORIZATION=f"Bearer {other_token.token}",+ )+ assert response.status_code not in (401, 403)++class TestOAuthCorsPreflightMiddleware(APIBaseTest):"""The toolbar runs in the customer's page and uses window.fetch.Customer code may monkey-patch fetch to inject custom headersdiff --git a/posthog/api/test/test_user.py b/posthog/api/test/test_user.pyindex 7c267ce83bae..7c14a274bd43 100644--- a/posthog/api/test/test_user.py+++ b/posthog/api/test/test_user.py@@ -4,6 +4,7 @@ from datetime import timedeltafrom typing import castfrom urllib.parse import quote, unquote+import pytestfrom freezegun.api import freeze_timefrom posthog.test.base import APIBaseTest, NonAtomicBaseTestfrom unittest import mock@@ -24,9 +25,11 @@ from rest_framework import statusfrom social_django.models import UserSocialAuthfrom posthog.api.email_verification import email_verification_token_generator+from posthog.api.oauth.toolbar_service import ToolbarOAuthState, build_toolbar_oauth_state, new_state_nonce+from posthog.constants import AvailableFeaturefrom posthog.models import Team, Userfrom posthog.models.instance_setting import set_instance_setting-from posthog.models.oauth import OAuthAccessToken, OAuthApplication+from posthog.models.oauth import OAuthAccessToken, OAuthApplication, OAuthGrant, OAuthRefreshTokenfrom posthog.models.organization import Organization, OrganizationMembershipfrom posthog.models.organization_domain import OrganizationDomainfrom posthog.models.personal_api_key import PersonalAPIKey@@ -36,6 +39,11 @@ from posthog.temporal.tests.delete_teams.inline import execute_deletion_workflowfrom products.dashboards.backend.models.dashboard import Dashboard+try:+ from ee.models.rbac.access_control import AccessControl+except ImportError:+ pass+def create_user(email: str, password: str, organization: Organization):"""@@ -2140,6 +2148,230 @@ class TestUserAPI(APIBaseTest):)+class TestToolbarAccessControl(APIBaseTest):+ """The toolbar launch endpoints must respect the `toolbar` resource's access control."""++ def setUp(self):+ super().setUp()+ self.organization.available_product_features = [+ {"key": AvailableFeature.ACCESS_CONTROL, "name": AvailableFeature.ACCESS_CONTROL},+ ]+ self.organization.save()+ self.team.app_urls = ["http://127.0.0.1:8010"]+ self.team.save()++ def _deny_toolbar_access(self):+ membership = OrganizationMembership.objects.get(user=self.user, organization=self.organization)+ AccessControl.objects.create(+ team=self.team,+ resource="toolbar",+ resource_id=None,+ access_level="none",+ organization_member=membership,+ )++ def test_redirect_to_site_denied_without_toolbar_access(self):+ self._deny_toolbar_access()++ response = self.client.get("/api/user/redirect_to_site/?appUrl=http%3A%2F%2F127.0.0.1%3A8010")++ self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)++ def test_redirect_to_site_allowed_with_default_access(self):+ response = self.client.get("/api/user/redirect_to_site/?appUrl=http%3A%2F%2F127.0.0.1%3A8010")++ self.assertEqual(response.status_code, status.HTTP_302_FOUND)++ def test_redirect_to_site_returns_404_without_crashing_when_user_has_no_team(self):+ """`team.app_urls` must not be dereferenced before the `team is None` guard, or a+ session-authed user with no current project crashes with an AttributeError instead of+ getting the expected 404."""+ new_user = User.objects.create_user(email="[email protected]", password="testpass123", first_name="")+ self.client.force_login(new_user)++ response = self.client.get("/api/user/redirect_to_site/?appUrl=http%3A%2F%2F127.0.0.1%3A8010")++ self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)++ @patch("posthog.api.user.get_or_create_toolbar_oauth_application")+ def test_toolbar_oauth_authorize_denied_without_toolbar_access(self, mock_get_or_create_app):+ self._deny_toolbar_access()++ response = self.client.get(+ "/toolbar_oauth/authorize/?redirect=http%3A%2F%2F127.0.0.1%3A8010&code_challenge=abc"+ )++ self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)+ mock_get_or_create_app.assert_not_called()++ def test_get_toolbar_preloaded_flags_denied_without_toolbar_access(self):+ cache.set("toolbar_flags_test-key", {"feature_flags": {"a-flag": True}, "team_id": self.team.id}, timeout=300)+ self._deny_toolbar_access()++ response = self.client.get("/api/user/get_toolbar_preloaded_flags/?key=test-key")++ self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)++ @patch("posthog.api.user.get_flags_from_service")+ def test_prepare_toolbar_preloaded_flags_denied_without_toolbar_access(self, mock_get_flags):+ mock_get_flags.return_value = {"flags": {}}+ self._deny_toolbar_access()++ response = self.client.post(+ "/api/user/prepare_toolbar_preloaded_flags/", {"distinct_id": "user123"}, content_type="application/json"+ )++ self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)+ mock_get_flags.assert_not_called()++ def test_toolbar_oauth_callback_denied_without_toolbar_access(self):+ self._deny_toolbar_access()++ response = self.client.get("/toolbar_oauth/callback?code=abc123&state=fake-state")++ self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)++ def test_toolbar_oauth_callback_narrows_grant_to_verified_team(self):+ """The generic first-party OAuth auto-approval issues the grant with scoped_teams=[]+ (unrestricted across every team in the org) since it has no notion of which team a toolbar+ launch was verified for. The callback must narrow it to that team, or the resulting tokens+ could be replayed against a different team in the same org where toolbar access is denied."""+ oauth_app = OAuthApplication.objects.create(+ name="Test Toolbar OAuth App",+ client_id="test_toolbar_client_id_scoping",+ client_type=OAuthApplication.CLIENT_PUBLIC,+ authorization_grant_type=OAuthApplication.GRANT_AUTHORIZATION_CODE,+ redirect_uris="https://example.com/callback",+ algorithm="RS256",+ user=self.user,+ )+ grant = OAuthGrant.objects.create(+ application=oauth_app,+ user=self.user,+ code="test-grant-code",+ expires=timezone.now() + timedelta(minutes=10),+ redirect_uri="https://example.com/callback",+ scope="openid",+ code_challenge="abc",+ code_challenge_method="S256",+ scoped_teams=[],+ scoped_organizations=[str(self.organization.id)],+ )+ signed_state, _ = build_toolbar_oauth_state(+ ToolbarOAuthState(+ nonce=new_state_nonce(),+ user_id=self.user.id,+ team_id=self.team.id,+ app_url="http://127.0.0.1:8010",+ )+ )++ with patch("posthog.api.user.get_or_create_toolbar_oauth_application", return_value=oauth_app):+ response = self.client.get(f"/toolbar_oauth/callback?code={grant.code}&state={signed_state}")++ self.assertEqual(response.status_code, status.HTTP_302_FOUND)+ grant.refresh_from_db()+ self.assertEqual(grant.scoped_teams, [self.team.id])++ def test_toolbar_oauth_refresh_denied_after_access_revoked(self):+ """A refresh token minted before access was revoked must not be usable to mint new+ tokens afterwards - the refresh endpoint has no session auth, so it must re-check+ the token owner's current toolbar access itself."""+ oauth_app = OAuthApplication.objects.create(+ name="Test Toolbar OAuth App",+ client_id="test_toolbar_client_id",+ client_type=OAuthApplication.CLIENT_PUBLIC,+ authorization_grant_type=OAuthApplication.GRANT_AUTHORIZATION_CODE,+ redirect_uris="https://example.com/callback",+ algorithm="RS256",+ user=self.user,+ )+ refresh_token = OAuthRefreshToken.objects.create(+ user=self.user,+ application=oauth_app,+ token="test_toolbar_refresh_token",+ scoped_teams=[self.team.id],+ )+ self._deny_toolbar_access()++ with patch("posthog.api.user.refresh_tokens") as mock_refresh_tokens:+ response = self.client.post(+ "/api/user/toolbar_oauth_refresh/",+ {"refresh_token": refresh_token.token, "client_id": oauth_app.client_id},+ content_type="application/json",+ )++ self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)+ mock_refresh_tokens.assert_not_called()++ def test_toolbar_oauth_refresh_denied_when_access_revoked_in_scoped_team_despite_switching_active_team(self):+ """The refresh check must gate on the token's scoped team, not the user's mutable current+ team - otherwise a user whose access was revoked in the project the token is scoped to+ could keep refreshing it by switching their active team to one where access remains."""+ other_team = Team.objects.create(organization=self.organization, name="Other team")+ oauth_app = OAuthApplication.objects.create(+ name="Test Toolbar OAuth App",+ client_id="test_toolbar_client_id_team_switch",+ client_type=OAuthApplication.CLIENT_PUBLIC,+ authorization_grant_type=OAuthApplication.GRANT_AUTHORIZATION_CODE,+ redirect_uris="https://example.com/callback",+ algorithm="RS256",+ user=self.user,+ )+ refresh_token = OAuthRefreshToken.objects.create(+ user=self.user,+ application=oauth_app,+ token="test_toolbar_refresh_token_team_switch",+ scoped_teams=[self.team.id],+ )+ self._deny_toolbar_access()+ self.user.current_team = other_team+ self.user.save()++ with patch("posthog.api.user.refresh_tokens") as mock_refresh_tokens:+ response = self.client.post(+ "/api/user/toolbar_oauth_refresh/",+ {"refresh_token": refresh_token.token, "client_id": oauth_app.client_id},+ content_type="application/json",+ )++ self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)+ mock_refresh_tokens.assert_not_called()++ def test_toolbar_oauth_refresh_denied_when_token_owner_has_no_team(self):+ """A refresh token with no scoped team (e.g. one minted before grants were narrowed to a+ single verified team) must be denied rather than allowed through - the check fails closed+ when it can't resolve exactly one scoped team to verify access against."""+ no_team_user = User.objects.create_user(+ email="[email protected]", password="testpass123", first_name=""+ )+ oauth_app = OAuthApplication.objects.create(+ name="Test Toolbar OAuth App",+ client_id="test_toolbar_client_id_no_team",+ client_type=OAuthApplication.CLIENT_PUBLIC,+ authorization_grant_type=OAuthApplication.GRANT_AUTHORIZATION_CODE,+ redirect_uris="https://example.com/callback",+ algorithm="RS256",+ user=no_team_user,+ )+ refresh_token = OAuthRefreshToken.objects.create(+ user=no_team_user,+ application=oauth_app,+ token="test_toolbar_refresh_token_no_team",+ )++ with patch("posthog.api.user.refresh_tokens") as mock_refresh_tokens:+ response = self.client.post(+ "/api/user/toolbar_oauth_refresh/",+ {"refresh_token": refresh_token.token, "client_id": oauth_app.client_id},+ content_type="application/json",+ )++ self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)+ mock_refresh_tokens.assert_not_called()++class TestSessionAuthEndpoints(APIBaseTest):"""Tests that certain endpoints require session authentication and reject Personal API Keys.diff --git a/posthog/api/user.py b/posthog/api/user.pyindex b1932d6c41f3..e9a18f43c71e 100644--- a/posthog/api/user.py+++ b/posthog/api/user.py@@ -84,6 +84,7 @@ from posthog.middleware import (is_read_only_impersonation,)from posthog.models import OrganizationInvite, Team, User, UserScenePersonalisation+from posthog.models.oauth import OAuthGrant, find_oauth_refresh_tokenfrom posthog.models.onboarding_delegation import cancel_pending_delegation, clear_delegation_statefrom posthog.models.organization import Organization, OrganizationMembershipfrom posthog.models.organization_domain import OrganizationDomain@@ -103,6 +104,7 @@ from posthog.rate_limit import (UserAuthenticationThrottle,UserEmailVerificationThrottle,)+from posthog.rbac.user_access_control import UserAccessControlfrom posthog.session.activity import (list_user_sessions,revoke_other_sessions,@@ -1455,6 +1457,11 @@ class UserViewSet(# Toolbar+def _user_can_access_toolbar(user: User, team: Team) -> bool:+ """Whether the user is allowed to launch the toolbar for this team."""+ return UserAccessControl(user, team=team).check_access_level_for_resource("toolbar", "viewer")++@require_http_methods(["GET"])def toolbar_oauth_authorize(request):"""@@ -1476,6 +1483,9 @@ def toolbar_oauth_authorize(request):if not team:return HttpResponse("No project found", status=400)+ if not _user_can_access_toolbar(request.user, team):+ return HttpResponse("You don't have access to the toolbar for this project.", status=403)+try:app_url = normalize_and_validate_app_url(team, redirect_url)@@ -1559,6 +1569,9 @@ def toolbar_oauth_callback(request):if not team:return HttpResponse("No project found", status=400)+ if not _user_can_access_toolbar(request.user, team):+ return HttpResponse("You don't have access to the toolbar for this project.", status=403)+try:state_payload = validate_and_consume_toolbar_oauth_state(signed_state=state,@@ -1569,6 +1582,13 @@ def toolbar_oauth_callback(request):except ToolbarOAuthError as exc:return HttpResponse(exc.detail, status=exc.status_code)+ # The first-party auto-approval path issues this grant with an org-wide+ # scoped_teams=[] (unrestricted across every team in the org), since the generic+ # /oauth/authorize/ view has no notion of which team a toolbar launch was verified+ # for. Narrow it to the verified team here, before the client can exchange the code,+ # so the resulting tokens can't be replayed against a team where toolbar access is denied.+ OAuthGrant.objects.filter(code=code, application=oauth_app, user=request.user).update(scoped_teams=[team.id])+# Re-validate app_url from the signed state against the team's allowlist.# validate_and_consume_toolbar_oauth_state already does this, but repeating# the call here makes the sanitisation visible at the point of use, which@@ -1625,6 +1645,23 @@ class ToolbarOAuthRefreshView(APIView):{"code": "invalid_request", "detail": "refresh_token and client_id are required"}, status=400)+ # Re-check current toolbar access here: the token itself is the only credential on this+ # AllowAny endpoint, so a user whose access was revoked after the token was issued must+ # not be able to keep minting fresh tokens with it. Check against the token's own scoped+ # team, not the user's current team - the user can switch their active team to one they+ # still have access to while continuing to refresh a token scoped to a different, revoked+ # project.+ token_record = find_oauth_refresh_token(refresh_token)+ if token_record:+ scoped_team_ids = token_record.scoped_teams or []+ team = Team.objects.filter(pk__in=scoped_team_ids).first() if len(scoped_team_ids) == 1 else None+ if not team or not _user_can_access_toolbar(token_record.user, team):+ logger.warning("toolbar_oauth_refresh_denied", reason="access_revoked")+ return JsonResponse(+ {"code": "forbidden", "detail": "You don't have access to the toolbar for this project."},+ status=403,+ )+try:token_payload = refresh_tokens(client_id=client_id, refresh_token=refresh_token)except ToolbarOAuthError as exc:@@ -1667,6 +1704,9 @@ def get_toolbar_preloaded_flags(request):)return JsonResponse({"error": "Unauthorized"}, status=403)+ if not _user_can_access_toolbar(request.user, request.user.team):+ return JsonResponse({"error": "Unauthorized"}, status=403)+feature_flags = cache_data.get("feature_flags", {})return JsonResponse({"featureFlags": feature_flags})@@ -1692,6 +1732,9 @@ def prepare_toolbar_preloaded_flags(request):logger.warning("[Toolbar Flags] No team found")return JsonResponse({"error": "No team found"}, status=400)+ if not _user_can_access_toolbar(request.user, team):+ return JsonResponse({"error": "Unauthorized"}, status=403)+# Use Rust flags service. Pass the internal token so this Django -> Rust# call bypasses the team's billing limiter and isn't counted as customer# SDK traffic — the toolbar launch is internal PostHog UI, not an SDK call.@@ -1733,12 +1776,19 @@ def redirect_to_site(request):# Consider removing this in favor of building the redirect URL client-side.REDIRECT_TO_SITE_COUNTER.inc()team = request.user.team+ if not team:+ return HttpResponse(status=404)+app_url = request.GET.get("appUrl") or (team.app_urls and team.app_urls[0])if not app_url:return HttpResponse(status=404)- if not team or not unparsed_hostname_in_allowed_url_list(team.app_urls, app_url):+ if not _user_can_access_toolbar(request.user, team):+ REDIRECT_TO_SITE_FAILED_COUNTER.inc()+ return HttpResponse("You don't have access to the toolbar for this project.", status=403)++ if not unparsed_hostname_in_allowed_url_list(team.app_urls, app_url):REDIRECT_TO_SITE_FAILED_COUNTER.inc()parsed_app_url = urllib.parse.urlparse(app_url)hostname = parsed_app_url.hostname or app_urldiff --git a/posthog/auth.py b/posthog/auth.pyindex d1f61a6d6057..6a0cd736889f 100644--- a/posthog/auth.py+++ b/posthog/auth.py@@ -43,10 +43,12 @@ from posthog.models.personal_api_key import ()from posthog.models.project_secret_api_key import ProjectSecretAPIKey, find_project_secret_api_keyfrom posthog.models.sharing_configuration import SharingConfiguration+from posthog.models.team import Teamfrom posthog.models.user import Userfrom posthog.models.utils import hash_key_valuefrom posthog.models.webauthn_credential import WebauthnCredentialfrom posthog.passkey import verify_passkey_authentication_response+from posthog.rbac.user_access_control import UserAccessControlfrom posthog.shared_link_user import SharedLinkUserfrom posthog.synthetic_user import SyntheticUser@@ -848,6 +850,8 @@ class OAuthAccessTokenAuthentication(authentication.BaseAuthentication):if not access_token:raise AuthenticationFailed(detail="Invalid access token.")+ self._enforce_toolbar_access(access_token)+self.access_token = access_tokentag_authentication(@@ -874,9 +878,32 @@ class OAuthAccessTokenAuthentication(authentication.BaseAuthentication):return Nonereturn None+ def _enforce_toolbar_access(self, access_token: OAuthAccessToken) -> None:+ """+ Toolbar OAuth tokens are only checked against the `toolbar` access level when+ they're minted (see toolbar_oauth_callback / ToolbarOAuthRefreshView) - that+ check doesn't re-run on every subsequent API request, so a token minted before+ access was revoked would otherwise keep authenticating until its natural+ expiry. Re-check here, scoped to the single team narrowed onto the token at+ mint time, failing closed if that scoping is missing or ambiguous.+ """+ application = access_token.application+ if not application or application.name != settings.TOOLBAR_OAUTH_APPLICATION_NAME:+ return++ user = access_token.user+ scoped_team_ids = access_token.scoped_teams or []+ team = Team.objects.filter(pk__in=scoped_team_ids).first() if len(scoped_team_ids) == 1 else None+ if (+ not user+ or not team+ or not UserAccessControl(user, team=team).check_access_level_for_resource("toolbar", "viewer")+ ):+ raise AuthenticationFailed(detail="You don't have access to the toolbar for this project.")+def _validate_token(self, token: str):try:- access_token = OAuthAccessToken.objects.select_related("user").get(token=token)+ access_token = OAuthAccessToken.objects.select_related("user", "application").get(token=token)if access_token.is_expired():raise AuthenticationFailed(detail="Access token has expired.")diff --git a/posthog/rbac/user_access_control.py b/posthog/rbac/user_access_control.pyindex 84212c3a919a..7dc081503602 100644--- a/posthog/rbac/user_access_control.py+++ b/posthog/rbac/user_access_control.py@@ -81,6 +81,7 @@ ACCESS_CONTROL_RESOURCES: tuple[APIScopeObject, ...] = ("logs","metrics","tracing",+ "toolbar",)# Resource inheritance mapping - child resources inherit access from parent resources@@ -175,7 +176,7 @@ def default_access_level(resource: APIScopeObject) -> AccessControlLevel:return "admin"if resource in ["organization"]:return "member"- if resource in ["activity_log"]:+ if resource in ["activity_log", "toolbar"]:return "viewer"return "editor"@@ -189,7 +190,7 @@ def minimum_access_level(resource: APIScopeObject) -> AccessControlLevel:def highest_access_level(resource: APIScopeObject) -> AccessControlLevel:"""Returns the highest allowed access level for a resource."""- if resource in ["activity_log"]:+ if resource in ["activity_log", "toolbar"]:return "viewer"return ordered_access_levels(resource)[-1]diff --git a/posthog/scopes.py b/posthog/scopes.pyindex 8114988f15fa..c5f9c0f04281 100644--- a/posthog/scopes.py+++ b/posthog/scopes.py@@ -106,6 +106,7 @@ APIScopeObject = Literal["tagger","ticket","task",+ "toolbar","tracing","field_note","uploaded_media",diff --git a/services/mcp/src/lib/oauth-scopes.generated.ts b/services/mcp/src/lib/oauth-scopes.generated.tsindex a641a4fd9f1f..fbfb2043150c 100644--- a/services/mcp/src/lib/oauth-scopes.generated.ts+++ b/services/mcp/src/lib/oauth-scopes.generated.ts@@ -179,6 +179,8 @@ export const OAUTH_SCOPES_SUPPORTED = ['ticket:write','task:read','task:write',+ 'toolbar:read',+ 'toolbar:write','tracing:read','tracing:write','field_note:read',