: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(security): credential review screen on first login post-provisioning (#58841)
Matt Brooker134787b4d1b7
diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.tsindex 0cf2c457c2ab..a35ee99714af 100644--- a/frontend/src/generated/core/api.schemas.ts+++ b/frontend/src/generated/core/api.schemas.ts@@ -3129,6 +3129,8 @@ export interface UserApi {/** Real-time notification types that currently have a live dispatch site. Drives the in-app notifications settings UI. Read-only. */readonly active_realtime_notification_types: readonly string[]readonly pending_invites: readonly PendingInviteApi[]+ /** True if the user has at least one Personal API Key and has not yet acknowledged their existing credentials. Used to gate a one-shot review screen on first post-provisioning login. Becomes False once the user POSTs to `/api/users/@me/credentials_review_complete/`. Read-only. */+ readonly requires_credential_review: boolean}export interface PaginatedUserListApi {@@ -3229,6 +3231,8 @@ export interface PatchedUserApi {/** Real-time notification types that currently have a live dispatch site. Drives the in-app notifications settings UI. Read-only. */readonly active_realtime_notification_types?: readonly string[]readonly pending_invites?: readonly PendingInviteApi[]+ /** True if the user has at least one Personal API Key and has not yet acknowledged their existing credentials. Used to gate a one-shot review screen on first post-provisioning login. Becomes False once the user POSTs to `/api/users/@me/credentials_review_complete/`. Read-only. */+ readonly requires_credential_review?: boolean}/**diff --git a/frontend/src/generated/core/api.ts b/frontend/src/generated/core/api.tsindex 2aa28103d710..4902afa09d51 100644--- a/frontend/src/generated/core/api.ts+++ b/frontend/src/generated/core/api.ts@@ -1927,6 +1927,20 @@ export const usersDestroy = async (uuid: string, options?: RequestInit): Promise})}+export const getUsersCredentialsReviewCompleteCreateUrl = (uuid: string) => {+ return `/api/users/${uuid}/credentials_review_complete/`+}++/**+ * Mark the user as having reviewed their existing credentials. Idempotent. Flips `requires_credential_review` to False so the post-login interstitial isn't shown again. Does not modify any credentials; the user revokes individual Personal API Keys via the existing PAT endpoints from the same screen.+ */+export const usersCredentialsReviewCompleteCreate = async (uuid: string, options?: RequestInit): Promise<void> => {+ return apiMutator<void>(getUsersCredentialsReviewCompleteCreateUrl(uuid), {+ ...options,+ method: 'POST',+ })+}+export const getUsersGithubLoginRetrieveUrl = (uuid: string) => {return `/api/users/${uuid}/github_login/`}diff --git a/frontend/src/scenes/appScenes.ts b/frontend/src/scenes/appScenes.tsindex 4eeba3dd5ccd..4a30458ec43b 100644--- a/frontend/src/scenes/appScenes.ts+++ b/frontend/src/scenes/appScenes.ts@@ -80,6 +80,7 @@ export const appScenes: Record<Scene | string, () => any> = {[Scene.OrganizationCreationConfirm]: () => import('./organization/ConfirmOrganization/ConfirmOrganization'),[Scene.PasswordResetComplete]: () => import('./authentication/PasswordResetComplete'),[Scene.AccountConnected]: () => import('./authentication/AccountConnected'),+ [Scene.CredentialReview]: () => import('./authentication/credential-review/CredentialReview'),[Scene.PasswordReset]: () => import('./authentication/PasswordReset'),[Scene.TwoFactorReset]: () => import('./authentication/TwoFactorReset'),[Scene.Person]: () => import('./persons/PersonScene'),diff --git a/frontend/src/scenes/authentication/credential-review/CredentialReview.tsx b/frontend/src/scenes/authentication/credential-review/CredentialReview.tsxnew file mode 100644index 000000000000..cbd0148f71a5--- /dev/null+++ b/frontend/src/scenes/authentication/credential-review/CredentialReview.tsx@@ -0,0 +1,48 @@+import { useActions, useValues } from 'kea'++import { LemonButton } from '@posthog/lemon-ui'++import { BridgePage } from 'lib/components/BridgePage/BridgePage'+import { HeartHog } from 'lib/components/hedgehogs'+import { SceneExport } from 'scenes/sceneTypes'+import { personalAPIKeysLogic } from 'scenes/settings/user/personalAPIKeysLogic'++import { credentialReviewLogic } from './credentialReviewLogic'+import { CredentialsReviewList } from './CredentialsReviewList'++export const scene: SceneExport = {+ component: CredentialReview,+ logic: credentialReviewLogic,+}++export function CredentialReview(): JSX.Element {+ const { markComplete } = useActions(credentialReviewLogic)+ const { keysLoading } = useValues(personalAPIKeysLogic)++ return (+ <BridgePage view="credential-review" fixedWidth={false}>+ <div className="px-12 py-8 flex flex-col items-center max-w-3xl w-full text-center">+ <h2 className="text-lg">Welcome to PostHog!</h2>+ <h1 className="text-3xl font-bold">One more thing.</h1>+ <div className="max-w-60 my-8">+ <HeartHog className="w-full h-full" />+ </div>+ <p className="mb-6 max-w-xl">+ Your account was set up with the API keys listed below. Review what each one can access, and revoke+ any you don't recognize before continuing.+ </p>+ <div className="w-full mb-6 text-left">+ <CredentialsReviewList />+ </div>+ <LemonButton+ type="primary"+ size="large"+ onClick={() => markComplete()}+ disabledReason={keysLoading ? 'Loading your API keys…' : null}+ >+ Continue to PostHog+ </LemonButton>+ </div>+ </BridgePage>+ )+}diff --git a/frontend/src/scenes/authentication/credential-review/CredentialsReviewList.tsx b/frontend/src/scenes/authentication/credential-review/CredentialsReviewList.tsxnew file mode 100644index 000000000000..1b64768eb3ca--- /dev/null+++ b/frontend/src/scenes/authentication/credential-review/CredentialsReviewList.tsx@@ -0,0 +1,98 @@+import { useActions, useValues } from 'kea'++import { LemonButton, LemonDialog, LemonTable, Tooltip } from '@posthog/lemon-ui'++import { humanFriendlyDetailedTime } from 'lib/utils'+import { personalAPIKeysLogic } from 'scenes/settings/user/personalAPIKeysLogic'++import { PersonalAPIKeyType } from '~/types'++function scopeSummary(key: PersonalAPIKeyType): string {+ if (!key.scopes?.length) {+ return 'No access'+ }+ if (key.scopes.includes('*')) {+ return 'Full access'+ }+ if (key.scopes.length <= 3) {+ return key.scopes.join(', ')+ }+ return `${key.scopes.slice(0, 3).join(', ')} + ${key.scopes.length - 3} more`+}++function teamScopeSummary(key: PersonalAPIKeyType): string {+ const orgs = key.scoped_organizations?.length ?? 0+ const teams = key.scoped_teams?.length ?? 0+ if (orgs === 0 && teams === 0) {+ return 'All projects'+ }+ const parts: string[] = []+ if (orgs > 0) {+ parts.push(`${orgs} organization${orgs === 1 ? '' : 's'}`)+ }+ if (teams > 0) {+ parts.push(`${teams} project${teams === 1 ? '' : 's'}`)+ }+ return parts.join(', ')+}++export function CredentialsReviewList(): JSX.Element {+ const { keys, keysLoading } = useValues(personalAPIKeysLogic)+ const { deleteKey } = useActions(personalAPIKeysLogic)++ return (+ <LemonTable+ dataSource={keys}+ loading={keysLoading}+ rowKey={(key) => key.id}+ columns={[+ {+ title: 'Label',+ dataIndex: 'label',+ render: (_, key) => <span className="font-semibold">{key.label}</span>,+ },+ {+ title: 'Access',+ render: (_, key) => (+ <Tooltip title={key.scopes?.join(', ') ?? ''}>+ <span>+ {scopeSummary(key)} · {teamScopeSummary(key)}+ </span>+ </Tooltip>+ ),+ },+ {+ title: 'Created',+ dataIndex: 'created_at',+ render: (value) => humanFriendlyDetailedTime(value as string),+ },+ {+ title: '',+ width: 0,+ render: (_, key) => (+ <LemonButton+ type="secondary"+ status="danger"+ size="small"+ onClick={() =>+ LemonDialog.open({+ title: `Revoke "${key.label}"?`,+ description:+ 'Any service still using this key will start receiving 401 errors immediately.',+ primaryButton: {+ status: 'danger',+ children: 'Revoke',+ onClick: () => deleteKey(key.id),+ },+ })+ }+ >+ Revoke+ </LemonButton>+ ),+ },+ ]}+ emptyState="No API keys found."+ />+ )+}diff --git a/frontend/src/scenes/authentication/credential-review/credentialReviewLogic.ts b/frontend/src/scenes/authentication/credential-review/credentialReviewLogic.tsnew file mode 100644index 000000000000..21ec01180b35--- /dev/null+++ b/frontend/src/scenes/authentication/credential-review/credentialReviewLogic.ts@@ -0,0 +1,39 @@+import { actions, afterMount, kea, listeners, path } from 'kea'+import { router } from 'kea-router'++import api from 'lib/api'+import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { personalAPIKeysLogic } from 'scenes/settings/user/personalAPIKeysLogic'+import { urls } from 'scenes/urls'+import { userLogic } from 'scenes/userLogic'++import type { credentialReviewLogicType } from './credentialReviewLogicType'++export const credentialReviewLogic = kea<credentialReviewLogicType>([+ path(['scenes', 'authentication', 'credentialReviewLogic']),+ actions({+ markComplete: true,+ }),+ listeners({+ markComplete: async () => {+ try {+ await api.create('api/users/@me/credentials_review_complete/')+ } catch {+ lemonToast.error('Could not save your review. Try again.')+ return+ }+ // Flip the local user state's requires_credential_review via reducer before+ // navigating: a stale in-flight loadUser response would otherwise re-trigger+ // the post-login redirect from userLogic.loadUserSuccess.+ userLogic.actions.credentialReviewDismissed()+ userLogic.actions.loadUser()+ router.actions.push(urls.projectHomepage())+ },+ }),+ afterMount(() => {+ // personalAPIKeysLogic only auto-loads teams (not keys) when it mounts; the+ // settings page calls loadKeys() from its own useEffect. Trigger it here so the+ // review table isn't dismissable while empty.+ personalAPIKeysLogic.actions.loadKeys()+ }),+])diff --git a/frontend/src/scenes/sceneTypes.ts b/frontend/src/scenes/sceneTypes.tsindex 650a82b31365..f8ae2648be3b 100644--- a/frontend/src/scenes/sceneTypes.ts+++ b/frontend/src/scenes/sceneTypes.ts@@ -117,6 +117,7 @@ export enum Scene {Person = 'Person',Persons = 'Persons',AccountConnected = 'AccountConnected',+ CredentialReview = 'CredentialReview',Pipeline = 'Pipeline',PipelineStatus = 'PipelineStatus',PipelineNode = 'PipelineNode',diff --git a/frontend/src/scenes/scenes.ts b/frontend/src/scenes/scenes.tsindex 94b8d737f982..a0a5dedf5762 100644--- a/frontend/src/scenes/scenes.ts+++ b/frontend/src/scenes/scenes.ts@@ -366,6 +366,12 @@ export const sceneConfigurations: Record<Scene | string, SceneConfig> = {projectBased: false,organizationBased: false,},+ [Scene.CredentialReview]: {+ name: 'Review API keys',+ layout: 'plain',+ projectBased: false,+ organizationBased: false,+ },[Scene.PreflightCheck]: { onlyUnauthenticated: true, layout: 'plain' },[Scene.ProjectCreateFirst]: {name: 'Project creation',@@ -859,6 +865,7 @@ export const routes: Record<string, [Scene | string, string]> = {[urls.login()]: [Scene.Login, 'login'],[urls.login2FA()]: [Scene.Login2FA, 'login2FA'],[urls.accountConnected(':kind')]: [Scene.AccountConnected, 'accountConnected'],+ [urls.credentialReview()]: [Scene.CredentialReview, 'credentialReview'],[urls.cliAuthorize()]: [Scene.CLIAuthorize, 'cliAuthorize'],[urls.cliLive()]: [Scene.CLILive, 'cliLive'],[urls.emailMFAVerify()]: [Scene.EmailMFAVerify, 'emailMFAVerify'],diff --git a/frontend/src/scenes/urls.ts b/frontend/src/scenes/urls.tsindex d6e56acc5b6d..0247bb629f4a 100644--- a/frontend/src/scenes/urls.ts+++ b/frontend/src/scenes/urls.ts@@ -152,6 +152,8 @@ export const urls = {*/accountConnected: (kind: string = ':kind'): string =>kind === ':kind' ? '/account-connected/:kind' : `/account-connected/${kind}`,+ /** One-shot credential review interstitial shown to users with existing API keys they haven't acknowledged. */+ credentialReview: (): string => '/account/credential-review',cliAuthorize: (): string => '/cli/authorize',cliLive: (): string => '/cli/live',emailMFAVerify: (): string => '/login/verify',diff --git a/frontend/src/scenes/userLogic.ts b/frontend/src/scenes/userLogic.tsindex 81ae4573f603..b6700930835c 100644--- a/frontend/src/scenes/userLogic.ts+++ b/frontend/src/scenes/userLogic.ts@@ -1,6 +1,7 @@import { actions, afterMount, kea, listeners, path, reducers, selectors } from 'kea'import { forms } from 'kea-forms'import { loaders } from 'kea-loaders'+import { router } from 'kea-router'import posthog from 'posthog-js'import api, { getCookie } from 'lib/api'@@ -93,6 +94,7 @@ export const userLogic = kea<userLogicType>([enabled,}),updateDataPipelineErrorThreshold: (threshold: number) => ({ threshold }),+ credentialReviewDismissed: true,updateRealtimeNotificationForTeam: (type: string, teamId: number, enabled: boolean) => ({type,teamId,@@ -242,6 +244,15 @@ export const userLogic = kea<userLogicType>([updateUserFailure: () => null,},],+ // Set when the user clicks Continue on /account/credential-review. Suppresses+ // the post-loadUser redirect so an in-flight stale loadUser response can't+ // bounce the user back to the review screen after they've already dismissed it.+ credentialReviewDismissedInSession: [+ false,+ {+ credentialReviewDismissed: () => true,+ },+ ],}),listeners(({ actions, values, cache }) => ({logout: ({ preserveLocation }) => {@@ -316,6 +327,20 @@ export const userLogic = kea<userLogicType>([}}}++ // First-login interstitial: route users with unreviewed pre-existing API keys+ // to the credential review screen before they enter the app. Gated server-side+ // by UserSerializer.get_requires_credential_review.+ //+ // credentialReviewDismissedInSession suppresses a bounce-back if a loadUser+ // call that was in-flight at dismiss time resolves later with stale state.+ if (+ user.requires_credential_review &&+ !values.credentialReviewDismissedInSession &&+ !router.values.location.pathname.startsWith('/account/credential-review')+ ) {+ router.actions.push(urls.credentialReview())+ }}},updateUserSuccess: () => {diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex 4a3dba218400..c1bb0cdb1873 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -330,6 +330,7 @@ export interface UserType extends UserBaseType {date_joined: stringnotification_settings: NotificationSettingsactive_realtime_notification_types?: readonly string[]+ requires_credential_review?: booleanevents_column_config: ColumnConfiganonymize_data: booleanallow_impersonation: booleandiff --git a/posthog/api/test/__snapshots__/test_action.ambr b/posthog/api/test/__snapshots__/test_action.ambrindex a1eda253d90e..78fd05cf6ba9 100644--- a/posthog/api/test/__snapshots__/test_action.ambr+++ b/posthog/api/test/__snapshots__/test_action.ambr@@ -15,6 +15,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -410,6 +411,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -493,6 +495,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -1020,6 +1023,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -1281,6 +1285,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -1340,6 +1345,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",diff --git a/posthog/api/test/__snapshots__/test_annotation.ambr b/posthog/api/test/__snapshots__/test_annotation.ambrindex a34f942f5159..c02f30aaa9b4 100644--- a/posthog/api/test/__snapshots__/test_annotation.ambr+++ b/posthog/api/test/__snapshots__/test_annotation.ambr@@ -15,6 +15,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -447,6 +448,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -503,6 +505,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -1067,6 +1070,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -1295,6 +1299,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",diff --git a/posthog/api/test/__snapshots__/test_element.ambr b/posthog/api/test/__snapshots__/test_element.ambrindex c714253523ff..bc6d6025f50c 100644--- a/posthog/api/test/__snapshots__/test_element.ambr+++ b/posthog/api/test/__snapshots__/test_element.ambr@@ -15,6 +15,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",diff --git a/posthog/api/test/__snapshots__/test_feature_flag.ambr b/posthog/api/test/__snapshots__/test_feature_flag.ambrindex 8e3e0155f443..16d14cd71edc 100644--- a/posthog/api/test/__snapshots__/test_feature_flag.ambr+++ b/posthog/api/test/__snapshots__/test_feature_flag.ambr@@ -1746,6 +1746,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -2524,6 +2525,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -2830,6 +2832,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -2868,6 +2871,7 @@T5."pending_email",T5."distinct_id",T5."is_email_verified",+ T5."credentials_reviewed_at",T5."requested_password_reset_at",T5."requested_2fa_reset_at",T5."has_seen_product_intro_for",diff --git a/posthog/api/test/__snapshots__/test_insight.ambr b/posthog/api/test/__snapshots__/test_insight.ambrindex 7e313e5e9bdf..f82d27b943a8 100644--- a/posthog/api/test/__snapshots__/test_insight.ambr+++ b/posthog/api/test/__snapshots__/test_insight.ambr@@ -586,6 +586,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -1590,6 +1591,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -2142,6 +2144,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",diff --git a/posthog/api/test/__snapshots__/test_organization_feature_flag.ambr b/posthog/api/test/__snapshots__/test_organization_feature_flag.ambrindex d3c4bbdf3567..60b2f821096b 100644--- a/posthog/api/test/__snapshots__/test_organization_feature_flag.ambr+++ b/posthog/api/test/__snapshots__/test_organization_feature_flag.ambr@@ -15,6 +15,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -2917,6 +2918,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -3471,6 +3473,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -3703,6 +3706,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -3748,6 +3752,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",diff --git a/posthog/api/test/__snapshots__/test_plugin.ambr b/posthog/api/test/__snapshots__/test_plugin.ambrindex 6ab541297ad3..2bda72405fbc 100644--- a/posthog/api/test/__snapshots__/test_plugin.ambr+++ b/posthog/api/test/__snapshots__/test_plugin.ambr@@ -15,6 +15,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -356,6 +357,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -738,6 +740,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -1220,6 +1223,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",diff --git a/posthog/api/test/__snapshots__/test_preflight.ambr b/posthog/api/test/__snapshots__/test_preflight.ambrindex 09eef1c4d762..0b88281c6698 100644--- a/posthog/api/test/__snapshots__/test_preflight.ambr+++ b/posthog/api/test/__snapshots__/test_preflight.ambr@@ -15,6 +15,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",diff --git a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambrindex 8e49905cc309..7e3fce966229 100644--- a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr+++ b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr@@ -15,6 +15,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -1151,6 +1152,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -1631,6 +1633,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -1895,6 +1898,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -1933,6 +1937,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -2487,6 +2492,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -2525,6 +2531,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -2772,6 +2779,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -2991,6 +2999,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -4126,6 +4135,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -4599,6 +4609,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -5037,6 +5048,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -5637,6 +5649,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -7181,6 +7194,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -8725,6 +8739,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -9267,6 +9282,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -9305,6 +9321,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -9410,6 +9427,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -9628,6 +9646,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -9666,6 +9685,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -10202,6 +10222,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -10240,6 +10261,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -10487,6 +10509,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -10668,6 +10691,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -11526,6 +11550,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -11564,6 +11589,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -11693,6 +11719,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -13724,6 +13751,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -14924,6 +14952,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -15142,6 +15171,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -15180,6 +15210,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -15588,6 +15619,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -15626,6 +15658,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -15707,6 +15740,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -16107,6 +16141,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -16544,6 +16579,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -16582,6 +16618,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -16797,6 +16834,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -17623,6 +17661,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -17661,6 +17700,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",@@ -17790,6 +17830,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -18260,6 +18301,7 @@T6."pending_email",T6."distinct_id",T6."is_email_verified",+ T6."credentials_reviewed_at",T6."requested_password_reset_at",T6."requested_2fa_reset_at",T6."has_seen_product_intro_for",diff --git a/posthog/api/test/notebooks/__snapshots__/test_notebook.ambr b/posthog/api/test/notebooks/__snapshots__/test_notebook.ambrindex a6bae0481e17..495d11a6596c 100644--- a/posthog/api/test/notebooks/__snapshots__/test_notebook.ambr+++ b/posthog/api/test/notebooks/__snapshots__/test_notebook.ambr@@ -15,6 +15,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -501,6 +502,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -539,6 +541,7 @@T5."pending_email",T5."distinct_id",T5."is_email_verified",+ T5."credentials_reviewed_at",T5."requested_password_reset_at",T5."requested_2fa_reset_at",T5."has_seen_product_intro_for",@@ -970,6 +973,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -1015,6 +1019,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -1420,6 +1425,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -1634,6 +1640,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",diff --git a/posthog/api/test/test_user.py b/posthog/api/test/test_user.pyindex b77fc4a59bbe..6b8501acd342 100644--- a/posthog/api/test/test_user.py+++ b/posthog/api/test/test_user.py@@ -221,6 +221,79 @@ class TestUserAPI(APIBaseTest):assert "active_realtime_notification_types" in bodyassert "comment_mention" in body["active_realtime_notification_types"]+ @parameterized.expand(+ [+ ("unreviewed_no_keys", False, False, False),+ ("unreviewed_with_keys", False, True, True),+ ("reviewed_with_keys", True, True, False),+ ("reviewed_no_keys", True, False, False),+ ]+ )+ def test_requires_credential_review(self, _name: str, reviewed: bool, with_key: bool, expected: bool):+ self.user.credentials_reviewed_at = timezone.now() if reviewed else None+ self.user.save(update_fields=["credentials_reviewed_at"])+ if with_key:+ PersonalAPIKey.objects.create(+ user=self.user,+ label="Test key",+ secure_value=hash_key_value("phx_test_value_1234567890"),+ scopes=["*"],+ )+ response = self.client.get("/api/users/@me/")+ assert response.status_code == 200+ assert response.json()["requires_credential_review"] is expected++ def test_credentials_review_complete_endpoint(self):+ User.objects.filter(pk=self.user.pk).update(credentials_reviewed_at=None)+ PersonalAPIKey.objects.create(+ user=self.user,+ label="Test key",+ secure_value=hash_key_value("phx_test_value_1234567890"),+ scopes=["*"],+ )++ response = self.client.get("/api/users/@me/")+ assert response.json()["requires_credential_review"] is True++ response = self.client.post("/api/users/@me/credentials_review_complete/")+ assert response.status_code == 204++ refreshed = User.objects.get(pk=self.user.pk)+ assert refreshed.credentials_reviewed_at is not None++ response = self.client.get("/api/users/@me/")+ assert response.json()["requires_credential_review"] is False++ first_ts = refreshed.credentials_reviewed_at+ response = self.client.post("/api/users/@me/credentials_review_complete/")+ assert response.status_code == 204+ assert User.objects.get(pk=self.user.pk).credentials_reviewed_at == first_ts++ def test_credentials_review_complete_requires_auth(self):+ self.client.logout()+ response = self.client.post("/api/users/@me/credentials_review_complete/")+ assert response.status_code == status.HTTP_401_UNAUTHORIZED++ def test_credentials_review_complete_rejects_personal_api_key_auth(self):+ # The partner-issued wildcard PAK is the thing this feature surfaces;+ # accepting it as auth here would let the attacker silently dismiss+ # their own review before the legit owner ever logs in.+ api_key_value = generate_random_token_personal()+ PersonalAPIKey.objects.create(+ user=self.user,+ label="Partner-minted key",+ secure_value=hash_key_value(api_key_value),+ scopes=["*"],+ )+ User.objects.filter(pk=self.user.pk).update(credentials_reviewed_at=None)++ self.client.logout()+ self.client.credentials(HTTP_AUTHORIZATION=f"Bearer {api_key_value}")+ response = self.client.post("/api/users/@me/credentials_review_complete/")+ assert response.status_code == status.HTTP_401_UNAUTHORIZED++ assert User.objects.get(pk=self.user.pk).credentials_reviewed_at is None+def test_can_only_list_yourself(self):"""At this moment only the current user can be retrieved from this endpoint.diff --git a/posthog/api/user.py b/posthog/api/user.pyindex 38423b4912fe..9ab82d2f7e28 100644--- a/posthog/api/user.py+++ b/posthog/api/user.py@@ -82,6 +82,7 @@ from posthog.models import OrganizationInvite, Team, User, UserScenePersonalisatfrom posthog.models.onboarding_delegation import cancel_pending_delegation, clear_delegation_statefrom posthog.models.organization import Organization, OrganizationMembershipfrom posthog.models.organization_domain import OrganizationDomain+from posthog.models.personal_api_key import PersonalAPIKeyfrom posthog.models.user import (NOTIFICATION_DEFAULTS,ROLE_CHOICES,@@ -216,6 +217,14 @@ class UserSerializer(serializers.ModelSerializer):"Drives the in-app notifications settings UI. Read-only."),)+ requires_credential_review = serializers.SerializerMethodField(+ help_text=(+ "True if the user has at least one Personal API Key and has not yet acknowledged "+ "their existing credentials. Used to gate a one-shot review screen on first "+ "post-provisioning login. Becomes False once the user POSTs to "+ "`/api/users/@me/credentials_review_complete/`. Read-only."+ ),+ )class Meta:model = User@@ -268,6 +277,7 @@ class UserSerializer(serializers.ModelSerializer):"is_organization_first_user","active_realtime_notification_types","pending_invites",+ "requires_credential_review",]read_only_fields = [@@ -296,6 +306,7 @@ class UserSerializer(serializers.ModelSerializer):"is_organization_first_user","active_realtime_notification_types","pending_invites",+ "requires_credential_review",]extra_kwargs = {@@ -352,6 +363,12 @@ class UserSerializer(serializers.ModelSerializer):def get_has_social_auth(self, instance: User) -> bool:return instance.social_auth.exists()+ @tracer.start_as_current_span("user_serializer.requires_credential_review")+ def get_requires_credential_review(self, instance: User) -> bool:+ if instance.credentials_reviewed_at is not None:+ return False+ return PersonalAPIKey.objects.filter(user=instance).exists()+@tracer.start_as_current_span("user_serializer.is_2fa_enabled")def get_is_2fa_enabled(self, instance: User) -> bool:return default_device(instance) is not None@@ -1202,6 +1219,32 @@ class UserViewSet(return Response({"success": True})+ @extend_schema(+ request=None,+ responses={204: None},+ description=(+ "Mark the user as having reviewed their existing credentials. Idempotent. "+ "Flips `requires_credential_review` to False so the post-login interstitial "+ "isn't shown again. Does not modify any credentials; the user revokes "+ "individual Personal API Keys via the existing PAT endpoints from the same screen."+ ),+ )+ @action(+ methods=["POST"],+ detail=True,+ url_path="credentials_review_complete",+ authentication_classes=[SessionAuthentication],+ )+ def credentials_review_complete(self, request, **kwargs):+ # Session-only auth: this endpoint dismisses the partner-issued-PAK review+ # screen, so accepting PersonalAPIKeyAuthentication here would let the+ # attacker who minted the PAK silently dismiss their own surfacing.+ user = self.get_object()+ if user.credentials_reviewed_at is None:+ user.credentials_reviewed_at = django_timezone.now()+ user.save(update_fields=["credentials_reviewed_at"])+ return Response(status=204)+#### Toolbardiff --git a/posthog/migrations/1170_credentials_reviewed_at.py b/posthog/migrations/1170_credentials_reviewed_at.pynew file mode 100644index 000000000000..d259cc607904--- /dev/null+++ b/posthog/migrations/1170_credentials_reviewed_at.py@@ -0,0 +1,17 @@+# Generated by Django 5.2.13 on 2026-05-18 14:07++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("posthog", "1169_organization_ai_training_fields"),+ ]++ operations = [+ migrations.AddField(+ model_name="user",+ name="credentials_reviewed_at",+ field=models.DateTimeField(blank=True, null=True),+ ),+ ]diff --git a/posthog/migrations/1171_backfill_credentials_reviewed_at.py b/posthog/migrations/1171_backfill_credentials_reviewed_at.pynew file mode 100644index 000000000000..e177596bd8d4--- /dev/null+++ b/posthog/migrations/1171_backfill_credentials_reviewed_at.py@@ -0,0 +1,26 @@+from django.db import migrations+from django.utils import timezone++BATCH_SIZE = 10_000+++def backfill_credentials_reviewed_at(apps, schema_editor):+ User = apps.get_model("posthog", "User")+ now = timezone.now()++ queryset = User.objects.filter(credentials_reviewed_at__isnull=True).only("id")+ while True:+ ids = list(queryset.values_list("id", flat=True)[:BATCH_SIZE])+ if not ids:+ break+ User.objects.filter(id__in=ids).update(credentials_reviewed_at=now)+++class Migration(migrations.Migration):+ dependencies = [+ ("posthog", "1170_credentials_reviewed_at"),+ ]++ operations = [+ migrations.RunPython(backfill_credentials_reviewed_at, reverse_code=migrations.RunPython.noop),+ ]diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txtindex 5969ba6bf675..21c87619460b 100644--- a/posthog/migrations/max_migration.txt+++ b/posthog/migrations/max_migration.txt@@ -1 +1 @@-1169_organization_ai_training_fields+1171_backfill_credentials_reviewed_atdiff --git a/posthog/models/user.py b/posthog/models/user.pyindex 9175e50f6448..6d5ee9000e60 100644--- a/posthog/models/user.py+++ b/posthog/models/user.py@@ -200,6 +200,7 @@ class User(AbstractUser, UUIDTClassicModel, ModelActivityMixin): # type: ignorepending_email = models.EmailField(_("pending email address awaiting verification"), null=True, blank=True)distinct_id = models.CharField(max_length=200, null=True, blank=True, unique=True)is_email_verified = models.BooleanField(null=True, blank=True)+ credentials_reviewed_at = models.DateTimeField(null=True, blank=True)requested_password_reset_at = models.DateTimeField(null=True, blank=True)requested_2fa_reset_at = models.DateTimeField(null=True, blank=True)has_seen_product_intro_for = models.JSONField(null=True, blank=True)diff --git a/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambr b/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambrindex b8d3a841b285..c6f937bb0cb3 100644--- a/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambr+++ b/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambr@@ -185,6 +185,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -223,6 +224,7 @@T4."pending_email",T4."distinct_id",T4."is_email_verified",+ T4."credentials_reviewed_at",T4."requested_password_reset_at",T4."requested_2fa_reset_at",T4."has_seen_product_intro_for",@@ -309,6 +311,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -831,6 +834,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -869,6 +873,7 @@T4."pending_email",T4."distinct_id",T4."is_email_verified",+ T4."credentials_reviewed_at",T4."requested_password_reset_at",T4."requested_2fa_reset_at",T4."has_seen_product_intro_for",@@ -1010,6 +1015,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -1313,6 +1319,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -1850,6 +1857,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -1888,6 +1896,7 @@T4."pending_email",T4."distinct_id",T4."is_email_verified",+ T4."credentials_reviewed_at",T4."requested_password_reset_at",T4."requested_2fa_reset_at",T4."has_seen_product_intro_for",diff --git a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambrindex 7bc89402a4c3..c451d8badd9d 100644--- a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr+++ b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr@@ -23,6 +23,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -717,6 +718,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -1407,6 +1409,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -2093,6 +2096,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -2779,6 +2783,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -3469,6 +3474,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -4159,6 +4165,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -4849,6 +4856,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -5571,6 +5579,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -6241,6 +6250,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -6321,6 +6331,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -7063,6 +7074,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -7950,6 +7962,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -9247,6 +9260,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -9970,6 +9984,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -10764,6 +10779,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -11540,6 +11556,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -12285,6 +12302,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",diff --git a/posthog/tasks/test/__snapshots__/test_process_scheduled_changes.ambr b/posthog/tasks/test/__snapshots__/test_process_scheduled_changes.ambrindex 9f837b9441fe..1771ed1bc7ff 100644--- a/posthog/tasks/test/__snapshots__/test_process_scheduled_changes.ambr+++ b/posthog/tasks/test/__snapshots__/test_process_scheduled_changes.ambr@@ -511,6 +511,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",@@ -1341,6 +1342,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_password_reset_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for",diff --git a/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr b/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambrindex 5808375f97c0..30f0692393c6 100644--- a/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr+++ b/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr@@ -312,6 +312,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -444,6 +445,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -810,6 +812,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",@@ -982,6 +985,7 @@"posthog_user"."pending_email","posthog_user"."distinct_id","posthog_user"."is_email_verified",+ "posthog_user"."credentials_reviewed_at","posthog_user"."requested_2fa_reset_at","posthog_user"."has_seen_product_intro_for","posthog_user"."strapi_id",diff --git a/services/mcp/definitions/core.yaml b/services/mcp/definitions/core.yamlindex 2f60f11cd521..331d8c07d729 100644--- a/services/mcp/definitions/core.yaml+++ b/services/mcp/definitions/core.yaml@@ -785,6 +785,9 @@ tools:users-cancel-email-change-request-partial-update:operation: users_cancel_email_change_request_partial_updateenabled: false+ users-credentials-review-complete-create:+ operation: users_credentials_review_complete_create+ enabled: falseusers-destroy:operation: users_destroyenabled: falsediff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 327c378186ac..6ae5d55a0de3 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -25491,6 +25491,8 @@ export namespace Schemas {/** Real-time notification types that currently have a live dispatch site. Drives the in-app notifications settings UI. Read-only. */readonly active_realtime_notification_types: readonly string[];readonly pending_invites: readonly PendingInvite[];+ /** True if the user has at least one Personal API Key and has not yet acknowledged their existing credentials. Used to gate a one-shot review screen on first post-provisioning login. Becomes False once the user POSTs to `/api/users/@me/credentials_review_complete/`. Read-only. */+ readonly requires_credential_review: boolean;}export interface PaginatedUserList {@@ -31224,6 +31226,8 @@ export namespace Schemas {/** Real-time notification types that currently have a live dispatch site. Drives the in-app notifications settings UI. Read-only. */readonly active_realtime_notification_types?: readonly string[];readonly pending_invites?: readonly PendingInvite[];+ /** True if the user has at least one Personal API Key and has not yet acknowledged their existing credentials. Used to gate a one-shot review screen on first post-provisioning login. Becomes False once the user POSTs to `/api/users/@me/credentials_review_complete/`. Read-only. */+ readonly requires_credential_review?: boolean;}export interface PatchedUserInterview {