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(oauth): grant the read scope alongside write on the consent screen (#81072)

Michael Matlokafe262c28e098
diff --git a/frontend/src/scenes/oauth/oauthAuthorizeLogic.test.ts b/frontend/src/scenes/oauth/oauthAuthorizeLogic.test.ts
index 44646f047c40..fc5bb6084eaf 100644
--- a/frontend/src/scenes/oauth/oauthAuthorizeLogic.test.ts
+++ b/frontend/src/scenes/oauth/oauthAuthorizeLogic.test.ts
@@ -30,8 +30,13 @@ describe('oauthAuthorizeLogic', () => {
const effectiveScopesCases: { name: string; scopes: string[]; apply?: () => void; expected: string[] }[] = [
{
- name: 'grants the full requested set, collapsed to the highest action',
+ name: 'grants both halves of the pair for an object at write level',
scopes: ['openid', 'feature_flag:read', 'feature_flag:write', 'insight:read'],
+ expected: ['openid', 'feature_flag:read', 'feature_flag:write', 'insight:read'],
+ },
+ {
+ name: 'keeps the write half alone when the read half was never requested',
+ scopes: ['openid', 'feature_flag:write', 'insight:read'],
expected: ['openid', 'feature_flag:write', 'insight:read'],
},
{
@@ -208,7 +213,7 @@ describe('oauthAuthorizeLogic', () => {
expect(row).toMatchObject({ locked: true, value: 'write' })
expect(row?.description).toContain('Write')
expect(logic.values.effectiveScopes).toContain('feature_flag:write')
- expect(logic.values.effectiveScopes).not.toContain('feature_flag:read')
+ expect(logic.values.effectiveScopes).toContain('feature_flag:read')
})
it('resets access selections when scopes are reloaded', () => {
diff --git a/frontend/src/scenes/oauth/oauthAuthorizeLogic.ts b/frontend/src/scenes/oauth/oauthAuthorizeLogic.ts
index 5456e57fcfff..bd5619469934 100644
--- a/frontend/src/scenes/oauth/oauthAuthorizeLogic.ts
+++ b/frontend/src/scenes/oauth/oauthAuthorizeLogic.ts
@@ -855,6 +855,14 @@ export const oauthAuthorizeLogic = kea<oauthAuthorizeLogicType>([
if (row.key === '*') {
return row.value === 'write' ? ['*'] : wildcardReadScopes(oauthApplication)
}
+ // Write grants read too, but clients diff the granted `scope` against what they
+ // asked for, so a missing `:read` reads as a partial grant. Spell both out when
+ // the client asked for both, and only then: granting a half it never requested
+ // is the same mismatch in the other direction.
+ if (row.value === 'write') {
+ const readScope = `${row.key}:read`
+ return scopes.includes(readScope) ? [readScope, `${row.key}:write`] : [`${row.key}:write`]
+ }
return [`${row.key}:${row.value}`]
})
// Also grant the required strings verbatim: collapsing read+write pairs above