Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(mobile): reject malformed inbox report fields (#127518)

Chris Volzerfb452fb0f094
diff --git a/products/mobile/docs/API.md b/products/mobile/docs/API.md
index 457c382b6f25..f15c3022fa28 100644
--- a/products/mobile/docs/API.md
+++ b/products/mobile/docs/API.md
@@ -12,6 +12,9 @@ types should come from the generated schemas; update the Django serializer and r
`hogli build:openapi` when those contracts change. Mobile CI includes the Signals schema
file for typechecking, and its type-only import adds nothing to the native bundle.
+Inbox pages validate the fields used to render report rows before they enter the query cache. A malformed page fails
+the request while previously loaded pages remain visible. The load-more retry requests the failed page again.
+
| Domain | Module | Endpoints | Notes |
| -------------------------------- | ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| Account | `src/api/users.ts` | `GET /api/users/@me/`, `GET /api/organizations/{id}/` | [AUTH.md](AUTH.md) |
diff --git a/products/mobile/src/api/reports.test.ts b/products/mobile/src/api/reports.test.ts
index afb5894cae9b..1a5b66287b15 100644
--- a/products/mobile/src/api/reports.test.ts
+++ b/products/mobile/src/api/reports.test.ts
@@ -1,3 +1,5 @@
+import { reportFixture } from '@/model/adapters/testFixtures'
+
import { setAuthProvider } from './client'
import { dismissReport, fetchInboxPage, fetchLatestReviewerArtefact, INBOX_PAGE_SIZE, resolveReport } from './reports'
@@ -41,19 +43,69 @@ describe('reports api', () => {
})
})
- test.each([undefined, [], { count: 1 }, { results: [null] }, { results: [{}] }])(
- 'rejects an invalid inbox page: %p',
- async (body) => {
- globalThis.fetch = jest.fn(async () => ({
- ok: true,
- status: 200,
- headers: { get: () => null },
- text: async () => JSON.stringify(body) ?? '',
- })) as unknown as typeof fetch
+ test.each([
+ undefined,
+ [],
+ { count: 1 },
+ { results: [null] },
+ { results: [{}] },
+ { count: 1, next: null, results: [{ id: 'synthetic-report' }] },
+ ...[
+ { id: '' },
+ { title: {} },
+ { status: null },
+ { source_products: null },
+ { source_products: [42] },
+ { created_at: 'invalid' },
+ { updated_at: null },
+ { signal_count: -1 },
+ { is_suggested_reviewer: 'yes' },
+ { implementation_pr_url: {} },
+ { pull_requests: null },
+ { pull_requests: [null] },
+ { pull_requests: [{ url: 42 }] },
+ { assignee: [] },
+ { assignee: { kind: {} } },
+ { ranking: { scores: { pr_merged: 'high' } } },
+ ].map((fields) => ({ count: 1, next: null, results: [{ ...reportFixture(), ...fields }] })),
+ { count: '1', results: [reportFixture()] },
+ { count: 1, next: {}, results: [reportFixture()] },
+ ])('rejects an invalid inbox page: %p', async (body) => {
+ globalThis.fetch = jest.fn(async () => ({
+ ok: true,
+ status: 200,
+ headers: { get: () => null },
+ text: async () => JSON.stringify(body) ?? '',
+ })) as unknown as typeof fetch
- await expect(fetchInboxPage(0)).rejects.toThrow("Couldn't load your inbox. Try again.")
+ await expect(fetchInboxPage(0)).rejects.toThrow("Couldn't load your inbox. Try again.")
+ })
+
+ test.each([
+ null,
+ { status: 'not_available', model: null, scored_at: null, predictions: [] },
+ { status: 'unscored', model: null, scored_at: null, predictions: [] },
+ {
+ status: 'scored',
+ model: 'example-model',
+ scored_at: '2026-10-01T00:00:00Z',
+ predictions: [{ outcome: 'pr_merged', probability: 0.5, lift: null, readable: true }],
+ },
+ { scores: { pr_merged: 0.5 } },
+ ])('accepts current and legacy rankings with nullable titles and unknown sources: %p', async (ranking) => {
+ const report = {
+ ...reportFixture({ title: null, source_products: ['future_source'], assignee: null }),
+ ranking,
}
- )
+ const page = { count: 1, next: null, results: [report] }
+ globalThis.fetch = jest.fn(async () => ({
+ ok: true,
+ status: 200,
+ headers: { get: () => null },
+ text: async () => JSON.stringify(page),
+ })) as unknown as typeof fetch
+ await expect(fetchInboxPage(0)).resolves.toEqual(page)
+ })
test('finds the newest reviewer assignment beyond the first artefact page', async () => {
const assignment = { id: 'assignment', type: 'suggested_reviewers', content: [{ github_login: 'reviewer' }] }
diff --git a/products/mobile/src/api/reports.ts b/products/mobile/src/api/reports.ts
index 6b8b63fa43c2..a46daa53f8c5 100644
--- a/products/mobile/src/api/reports.ts
+++ b/products/mobile/src/api/reports.ts
@@ -187,6 +187,52 @@ export interface InboxPageApi {
export const INBOX_PAGE_SIZE = 20
+function isOptionalString(value: unknown): boolean {
+ return value === undefined || value === null || typeof value === 'string'
+}
+
+function isReportDate(value: unknown): boolean {
+ return typeof value === 'string' && Number.isFinite(Date.parse(value))
+}
+
+function isInboxPullRequest(value: unknown): boolean {
+ return (
+ isRecord(value) &&
+ typeof value.url === 'string' &&
+ typeof value.state === 'string' &&
+ typeof value.merged === 'boolean' &&
+ isOptionalString(value.id) &&
+ isOptionalString(value.review_decision)
+ )
+}
+
+const INBOX_REPORT_FIELDS = {
+ id: (value) => typeof value === 'string' && value.trim() !== '',
+ title: isOptionalString,
+ status: (value) => typeof value === 'string',
+ source_products: (value) => Array.isArray(value) && value.every((source) => typeof source === 'string'),
+ created_at: isReportDate,
+ updated_at: isReportDate,
+ signal_count: (value) => typeof value === 'number' && Number.isSafeInteger(value) && value >= 0,
+ is_suggested_reviewer: (value) => value === undefined || typeof value === 'boolean',
+ implementation_pr_url: isOptionalString,
+ pull_requests: (value) => Array.isArray(value) && value.every(isInboxPullRequest),
+ assignee: (value) => value == null || (isRecord(value) && typeof value.kind === 'string'),
+ ranking: (value) => {
+ if (value == null) return true
+ if (!isRecord(value)) return false
+ const scores = value.scores
+ if (scores == null) return true
+ if (!isRecord(scores)) return false
+ const score = scores.pr_merged
+ return score == null || (typeof score === 'number' && Number.isFinite(score))
+ },
+} satisfies Partial<Record<keyof SignalReportApi, (value: unknown) => boolean>>
+
+function isInboxReport(value: unknown): boolean {
+ return isRecord(value) && Object.entries(INBOX_REPORT_FIELDS).every(([field, validate]) => validate(value[field]))
+}
+
export async function fetchInboxPage(offset: number, signal?: AbortSignal): Promise<InboxPageApi> {
const page = await apiJson<InboxPageApi>(projectPath('signals/reports/'), {
query: { view: 'for_you', sort: 'priority', limit: INBOX_PAGE_SIZE, offset } satisfies SignalsReportsListParams,
@@ -195,7 +241,10 @@ export async function fetchInboxPage(offset: number, signal?: AbortSignal): Prom
if (
!isRecord(page) ||
!Array.isArray(page.results) ||
- page.results.some((report) => !isRecord(report) || typeof report.id !== 'string')
+ !page.results.every(isInboxReport) ||
+ !Number.isSafeInteger(page.count) ||
+ page.count < 0 ||
+ (page.next !== undefined && page.next !== null && typeof page.next !== 'string')
) {
throw new Error("Couldn't load your inbox. Try again.")
}
diff --git a/products/mobile/src/features/inbox/hooks.test.tsx b/products/mobile/src/features/inbox/hooks.test.tsx
index b5efd2e406b2..c863247206e3 100644
--- a/products/mobile/src/features/inbox/hooks.test.tsx
+++ b/products/mobile/src/features/inbox/hooks.test.tsx
@@ -382,7 +382,7 @@ describe('inbox hooks', () => {
}
})
- test.each(['server error', 'invalid page'])(
+ test.each(['server error', 'invalid page', 'invalid report'])(
'pages through the ranking, retrying after %s only when asked, reading states once per page',
async (failure) => {
const offsets: string[] = []
@@ -401,7 +401,11 @@ describe('inbox hooks', () => {
secondPageFailures -= 1
return failure === 'server error'
? jsonResponse({ detail: 'Server error' }, 500)
- : jsonResponse({ count: INBOX_PAGE_SIZE + 1, next: null })
+ : jsonResponse({
+ count: INBOX_PAGE_SIZE + 1,
+ next: null,
+ ...(failure === 'invalid report' ? { results: [{ id: 'synthetic-report' }] } : {}),
+ })
}
return jsonResponse(
offset === '0'