GeezerVison is showing github.com — Merge pull request #4160 from lidge-jun/lane-b/3-3859 · agentHits/opencodex@b27aa50
File treeExpand file treeCollapse file tree Open diff view settings docs-site/src/content/docs/reference/configuration
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs-site/src/content/docs/reference/configuration/server.md +26Lines changed: 26 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -224,6 +224,32 @@ use `ssh -g -L`, broad container publishing, or forwarding modes that expose the | 224 | 224 | `0.0.0.0`. Bind explicitly with `ssh -L 127.0.0.1:20100:localhost:10100` when unsure. | 225 | 225 | ::: | 226 | 226 |
| | 227 | +## Account email masking (`privacy`) | | 228 | + | | 229 | +Stored account emails are masked everywhere they leave the proxy — the dashboard account lists, | | 230 | +`GET /api/codex-auth/accounts`, `GET /api/oauth/status`, and the `ocx status` logins section all | | 231 | + | | 232 | + | | 233 | +| Field | Type | Default | Meaning | | | 234 | +| --- | --- | --- | --- | | | 235 | +| `privacy.maskEmails?` | `boolean` | `true` | Set to `false` to show stored account emails in full. Absent, `true`, and any malformed value all keep masking, so only a deliberate `false` reveals an address. | | | 236 | + | | 237 | +Turn it off when you run many accounts on a machine you control and cannot tell them apart from | | 238 | +masked forms. Read the flag as a disclosure decision rather than a display preference: management | | 239 | +is not always loopback, so on a hub configured with `remoteGui` an unmasked address reaches every | | 240 | +management principal that can reach the hub, not only someone sitting at the machine. The flag | | 241 | +moves only the email field — tokens, refresh tokens, and account identifiers stay redacted either | | 242 | +way. | | 243 | + | | 244 | +```json | | 245 | +{ "privacy": { "maskEmails": false } } | | 246 | +``` | | 247 | + | | 248 | +`ocx config set privacy.maskEmails false` fails with `config parent path not found` until the | | 249 | +block exists, because `config set` walks into existing objects and never creates them. Write the | | 250 | +whole object instead — `ocx config set privacy '{"maskEmails":false}'` — or add the block to | | 251 | +`config.json` by hand. | | 252 | + | 227 | 253 | ## Storage cleanup | 228 | 254 |
| 229 | 255 | `storageCleanupPolicy` is disabled by default. When enabled, it runs on `startup`, `daily`, `weekly`, | |
Collapse file Copy file name to clipboardExpand all lines: src/cli/index.ts +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1428,9 +1428,13 @@ async function handleStatus() { | 1428 | 1428 | } | 1429 | 1429 | } | 1430 | 1430 | const { collectOAuthHealthEntriesForCli, oauthLoginSummary } = await import("../oauth"); | | 1431 | + const { emailMaskingEnabled } = await import("../lib/privacy"); | 1431 | 1432 | const { formatOAuthHealthForStatus } = await import("./status-oauth"); | 1432 | 1433 | console.log(` OAuth logins:`); | 1433 | | - for (const e of oauthLoginSummary()) { | | 1434 | + // The operator's own `privacy.maskEmails` decision applies to the CLI too: `ocx status` is not | | 1435 | + // the dashboard, but it reads the same stored addresses, and a flag that only moved one of the | | 1436 | + // two would leave the operator unable to tell which surface they had configured. | | 1437 | + for (const e of oauthLoginSummary(emailMaskingEnabled(loadConfig()))) { | 1434 | 1438 | console.log(` ${e.provider.padEnd(10)} ${e.loggedIn ? `✓ logged in${e.email ? ` (${e.email})` : ""}` : "✗ not logged in"}`); | 1435 | 1439 | } | 1436 | 1440 | const oauthHealthBlock = formatOAuthHealthForStatus(await collectOAuthHealthEntriesForCli()); | |
Collapse file Copy file name to clipboardExpand all lines: src/codex/auth-api.ts +13-5Lines changed: 13 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -115,7 +115,7 @@ export { clearMainAccountInfoCache } from "./main-account-cache"; | 115 | 115 | import type { CodexQuotaRefreshOutcome } from "./quota-refresh-outcome"; | 116 | 116 | import { getMainAccountHardLockStatus, type MainAccountHardLockStatus } from "./main-account-hard-lock"; | 117 | 117 | import { observeMainReserveRevocation } from "./reserve-availability"; | 118 | | -import { maskEmail } from "../lib/privacy"; | | 118 | +import { emailMaskingEnabled, projectEmail } from "../lib/privacy"; | 119 | 119 | import { codexWarmupFailureReason, warmCodexAccount } from "./warmup"; | 120 | 120 | export { maskEmail } from "../lib/privacy"; | 121 | 121 | import type { CodexAccount, CodexAccountCredentials, OcxConfig } from "../types"; | @@ -370,14 +370,15 @@ function poolAccountDto( | 370 | 370 | hasCredential: boolean, | 371 | 371 | paused: boolean, | 372 | 372 | priority: number, | | 373 | + maskEmails: boolean, | 373 | 374 | ): CodexAuthAccountDto { | 374 | 375 | const plan = codexPlanValue(account.plan); | 375 | 376 | const quota = quotaForPlan(quotaResult.quota, plan); | 376 | 377 | const needsReauth = !hasCredential || quotaResult.needsReauth || isAccountNeedsReauth(account.id); | 377 | 378 | const health = projectCodexAccountHealth({ accountId: account.id, needsReauth }); | 378 | 379 | return { | 379 | 380 | id: account.id, | 380 | | - email: maskEmail(account.email) ?? account.email, | | 381 | + email: projectEmail(account.email, maskEmails) ?? account.email, | 381 | 382 | ...(account.alias !== undefined ? { alias: account.alias } : {}), | 382 | 383 | ...(plan !== undefined ? { plan } : {}), | 383 | 384 | logLabel: codexAccountLogLabel(account), | @@ -1929,6 +1930,8 @@ export async function listCodexAuthAccountsSnapshot( | 1929 | 1930 | ): Promise<CodexAuthAccountsSnapshot> { | 1930 | 1931 | const runtimeConfig = getRuntimeConfig(config); | 1931 | 1932 | const poolAccounts = (runtimeConfig.codexAccounts ?? []).filter(isSelectableCodexPoolAccount); | | 1933 | + // One redaction decision for the whole snapshot, read once from the operator's config (#3859). | | 1934 | + const maskEmails = emailMaskingEnabled(runtimeConfig); | 1932 | 1935 | const mainResult = await fetchMainAccountInfoAttempt(forceRefresh, 1); | 1933 | 1936 | const refreshedPool = await mapWithConcurrency(poolAccounts, POOL_QUOTA_REFRESH_CONCURRENCY, async account => { | 1934 | 1937 | const cred = getCodexAccountCredential(account.id); | @@ -1973,6 +1976,7 @@ export async function listCodexAuthAccountsSnapshot( | 1973 | 1976 | false, | 1974 | 1977 | isCodexAccountPaused(runtimeConfig, accountId), | 1975 | 1978 | getCodexAccountPriority(runtimeConfig, accountId), | | 1979 | + maskEmails, | 1976 | 1980 | )]; | 1977 | 1981 | } | 1978 | 1982 | const resultGeneration = quotaResult.credentialGeneration ?? quotaResult.freshCredentialGeneration; | @@ -1992,6 +1996,7 @@ export async function listCodexAuthAccountsSnapshot( | 1992 | 1996 | true, | 1993 | 1997 | isCodexAccountPaused(runtimeConfig, accountId), | 1994 | 1998 | getCodexAccountPriority(runtimeConfig, accountId), | | 1999 | + maskEmails, | 1995 | 2000 | )]; | 1996 | 2001 | }); | 1997 | 2002 | const fetchedMainGeneration = mainResult.identityGeneration ?? captureMainAccountIdentityGeneration(); | @@ -2008,7 +2013,7 @@ export async function listCodexAuthAccountsSnapshot( | 2008 | 2013 | }); | 2009 | 2014 | const main: CodexAuthAccountDto = { | 2010 | 2015 | id: MAIN_CODEX_ACCOUNT_ID, | 2011 | | - email: maskEmail(mainInfo.email) ?? "Codex App login", | | 2016 | + email: projectEmail(mainInfo.email, maskEmails) ?? "Codex App login", | 2012 | 2017 | plan: mainInfo.plan, | 2013 | 2018 | ...(mainSnapshotLive && mainResult.quotaRefresh && mainResult.quotaRefreshGeneration !== undefined | 2014 | 2019 | && isMainAccountIdentityGenerationLive(mainResult.quotaRefreshGeneration) | @@ -3026,6 +3031,9 @@ export async function handleCodexAuthAPI( | 3026 | 3031 | if (url.pathname === "/api/codex-auth/login-status" && req.method === "GET") { | 3027 | 3032 | const flowId = url.searchParams.get("flowId"); | 3028 | 3033 | const accountId = url.searchParams.get("accountId")?.trim(); | | 3034 | + // Transient flow state carries the address of the account being added, so it follows the | | 3035 | + // same operator policy as the stored accounts it is about to become. | | 3036 | + const maskFlowEmails = emailMaskingEnabled(config); | 3029 | 3037 | // Reauth always has a pre-existing credential; never treat "credential exists" as success | 3030 | 3038 | // when the flow map entry is gone (would false-complete on lost/expired flow state). | 3031 | 3039 | const reauthStatus = url.searchParams.get("reauth") === "1"; | @@ -3042,11 +3050,11 @@ export async function handleCodexAuthAPI( | 3042 | 3050 | ...(readCodexAccountRecord(accountId)?.codexValidationPending ? { validationPending: true } : {}), | 3043 | 3051 | }); | 3044 | 3052 | } | 3045 | | - return jsonResponse(st ? { ...st, email: maskEmail(st.email) ?? undefined } : { status: "expired" }); | | 3053 | + return jsonResponse(st ? { ...st, email: projectEmail(st.email, maskFlowEmails) ?? undefined } : { status: "expired" }); | 3046 | 3054 | } | 3047 | 3055 | // Legacy fallback: return latest pending flow | 3048 | 3056 | for (const [, st] of codexAuthLoginState) { | 3049 | | - if (st.status === "pending") return jsonResponse({ ...st, email: maskEmail(st.email) ?? undefined }); | | 3057 | + if (st.status === "pending") return jsonResponse({ ...st, email: projectEmail(st.email, maskFlowEmails) ?? undefined }); | 3050 | 3058 | } | 3051 | 3059 | return jsonResponse({ status: "idle" }); | 3052 | 3060 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/config.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1146,6 +1146,9 @@ const configSchema = z.object({ | 1146 | 1146 | // candidates are rejected explicitly by remoteGuiConfigError below. | 1147 | 1147 | hub: hubConfigSchema.optional().catch(undefined), | 1148 | 1148 | remoteGui: remoteGuiConfigSchema.optional().catch(undefined), | | 1149 | + // A malformed privacy block must never be read as "unmask": .catch(undefined) drops it and | | 1150 | + // emailMaskingEnabled then falls back to masked, which is also what an absent block means. | | 1151 | + privacy: z.object({ maskEmails: z.boolean().optional() }).strict().optional().catch(undefined), | 1149 | 1152 | // A malformed present client block must remain diagnosable from raw config and | 1150 | 1153 | // fail closed through src/client/state.ts; unrelated provider state still loads. | 1151 | 1154 | client: clientConnectionSchema.optional().catch(undefined), | |
Collapse file Copy file name to clipboardExpand all lines: src/lib/privacy.ts +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,31 @@ export function maskEmail(value: string | null | undefined): string | null { | 10 | 10 | return `${local[0]}***${local[local.length - 1]}@${domain}`; | 11 | 11 | } | 12 | 12 |
| | 13 | +/** | | 14 | + * Whether stored account emails are masked in management and CLI projections (#3859). | | 15 | + * | | 16 | + * Fail closed on every ambiguity: a missing config, a missing `privacy` block, and a missing or | | 17 | + * malformed `maskEmails` all mask. Only the literal boolean `false` unmasks, so a hand-edited | | 18 | + * `"false"` string or a typo cannot silently disclose an address. Callers read this once at the | | 19 | + * request boundary and pass the answer down — the projection helpers take a boolean rather than | | 20 | + * a config so that `getLoginStatus` stays free of config I/O. | | 21 | + */ | | 22 | +export function emailMaskingEnabled(config: { privacy?: { maskEmails?: boolean } } | null | undefined): boolean { | | 23 | + return config?.privacy?.maskEmails !== false; | | 24 | +} | | 25 | + | | 26 | +/** | | 27 | + * Project a stored account email for a surface outside the proxy (#3859). | | 28 | + * | | 29 | + * One redaction decision for every call site, rather than each one forking on the flag: an | | 30 | + * unmasked projection still normalises an empty or absent address to `null`, so a consumer's | | 31 | + * "is there an email" test cannot start answering differently just because masking is off. | | 32 | + */ | | 33 | +export function projectEmail(value: string | null | undefined, mask: boolean): string | null { | | 34 | + if (!mask) return value ? value : null; | | 35 | + return maskEmail(value); | | 36 | +} | | 37 | + | 13 | 38 | export function maskAccountId(value: string | null | undefined): string | null { | 14 | 39 | if (!value) return null; | 15 | 40 | const id = value.trim(); | |
Collapse file Copy file name to clipboardExpand all lines: src/oauth/index.ts +18-7Lines changed: 18 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,7 +4,7 @@ import { parseCallbackInput } from "./callback-server"; | 4 | 4 | import type { OcxConfig, OcxProviderConfig, RefreshPolicy } from "../types"; | 5 | 5 | import { ConfigMutationLockError, loadConfig, mutatePersistedConfig, saveConfig } from "../config"; | 6 | 6 | import { resolveProviderApiKey } from "../providers/key-store"; | 7 | | -import { maskEmail } from "../lib/privacy"; | | 7 | +import { projectEmail } from "../lib/privacy"; | 8 | 8 | import { KiroTokenRefreshError, environmentKiroRoutingMetadata, loginKiro, refreshKiroToken, settleKiroLoginTransaction } from "./kiro"; | 9 | 9 | import { | 10 | 10 | OAuthMutationBusyError, | @@ -1805,14 +1805,22 @@ export interface OAuthAccountSummary { | 1805 | 1805 | plan: string | null; | 1806 | 1806 | } | 1807 | 1807 |
| 1808 | | -export function getLoginStatus(provider: string): { loggedIn: boolean; email?: string; source?: OAuthCredentials["source"]; error?: string; done: boolean; activeAccountId?: string; accounts?: OAuthAccountSummary[] } { | | 1808 | +/** | | 1809 | + * Token-safe login state for one provider. | | 1810 | + * | | 1811 | + * `maskEmails` is an explicit boolean rather than a config read (#3859). This module must not | | 1812 | + * acquire a dependency on config I/O to answer a redaction question: the caller already holds | | 1813 | + * the config at its request boundary and resolves the policy there with `emailMaskingEnabled`. | | 1814 | + * The default masks, so every existing caller keeps today's behaviour. | | 1815 | + */ | | 1816 | +export function getLoginStatus(provider: string, maskEmails = true): { loggedIn: boolean; email?: string; source?: OAuthCredentials["source"]; error?: string; done: boolean; activeAccountId?: string; accounts?: OAuthAccountSummary[] } { | 1809 | 1817 | const cred = getCredential(provider); | 1810 | 1818 | const st = loginState.get(provider); | 1811 | 1819 | const set = getAccountSet(provider); | 1812 | 1820 | const accounts: OAuthAccountSummary[] | undefined = set?.accounts.map(a => ({ | 1813 | 1821 | id: a.id, | 1814 | 1822 | ...(a.alias ? { alias: a.alias } : {}), | 1815 | | - email: maskEmail(a.credential.email) ?? undefined, | | 1823 | + email: projectEmail(a.credential.email, maskEmails) ?? undefined, | 1816 | 1824 | active: a.id === set.activeAccountId, | 1817 | 1825 | ...(a.needsReauth ? { needsReauth: true } : {}), | 1818 | 1826 | expiresAt: a.credential.expires, | @@ -1832,18 +1840,21 @@ export function getLoginStatus(provider: string): { loggedIn: boolean; email?: s | 1832 | 1840 | .find(a => a.id === set.activeAccountId)?.needsReauth === true; | 1833 | 1841 | return { | 1834 | 1842 | loggedIn: !!cred && !activeNeedsReauth, | 1835 | | - email: maskEmail(cred?.email) ?? undefined, | | 1843 | + email: projectEmail(cred?.email, maskEmails) ?? undefined, | 1836 | 1844 | source: cred?.source, | 1837 | 1845 | error: st?.error, | 1838 | 1846 | done: st?.done ?? false, | 1839 | 1847 | ...(set ? { activeAccountId: set.activeAccountId, accounts } : {}), | 1840 | 1848 | }; | 1841 | 1849 | } | 1842 | 1850 |
| 1843 | | -/** Token-safe per-provider login state for the CLI `ocx status` logins section (no tokens, masked email). */ | 1844 | | -export function oauthLoginSummary(): Array<{ provider: string; loggedIn: boolean; email?: string }> { | | 1851 | +/** | | 1852 | + * Token-safe per-provider login state for the CLI `ocx status` logins section. Never tokens; the | | 1853 | + * email follows the operator's `privacy.maskEmails` policy, masked by default (#3859). | | 1854 | + */ | | 1855 | +export function oauthLoginSummary(maskEmails = true): Array<{ provider: string; loggedIn: boolean; email?: string }> { | 1845 | 1856 | return listOAuthProviders().map(provider => { | 1846 | | - const status = getLoginStatus(provider); | | 1857 | + const status = getLoginStatus(provider, maskEmails); | 1847 | 1858 | return { provider, loggedIn: status.loggedIn, ...(status.email ? { email: status.email } : {}) }; | 1848 | 1859 | }); | 1849 | 1860 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/server/management/oauth-account-routes.ts +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,6 +25,7 @@ import { | 25 | 25 | } from "../../oauth"; | 26 | 26 | import { OAuthMutationBusyError, removeCredential } from "../../oauth/store"; | 27 | 27 | import { providerDestinationResolvedError } from "../../lib/destination-policy"; | | 28 | +import { emailMaskingEnabled } from "../../lib/privacy"; | 28 | 29 | import { reconcileLiveStateStores } from "../../lib/state-store-registrations"; | 29 | 30 | import { enrichProviderFromCatalog, listKeyLoginProviders } from "../../oauth/key-providers"; | 30 | 31 | import { deriveProviderPresets } from "../../providers/derive"; | @@ -233,7 +234,10 @@ export async function handleOauthAccountRoutes(ctx: ManagementContext): Promise< | 233 | 234 | if (url.pathname === "/api/oauth/status" && req.method === "GET") { | 234 | 235 | const provider = (url.searchParams.get("provider") ?? "").trim().toLowerCase(); | 235 | 236 | if (!isPublicOAuthProvider(provider)) return jsonResponse({ error: "unknown oauth provider" }, 400); | 236 | | - const status = getLoginStatus(provider); | | 237 | + // Resolved here, at the request boundary that already holds the config, and passed down. | | 238 | + // getLoginStatus stays free of config I/O. This route does not re-mask afterwards: it | | 239 | + // consumes the already-projected status rather than redacting a second time. | | 240 | + const status = getLoginStatus(provider, emailMaskingEnabled(config)); | 237 | 241 | return jsonResponse(status); | 238 | 242 | } | 239 | 243 |
| @@ -269,7 +273,7 @@ export async function handleOauthAccountRoutes(ctx: ManagementContext): Promise< | 269 | 273 | } = await import("../../oauth/health"); | 270 | 274 | const projectAccounts = () => { | 271 | 275 | const set = getAccountSet(provider); | 272 | | - const current = getLoginStatus(provider); | | 276 | + const current = getLoginStatus(provider, emailMaskingEnabled(config)); | 273 | 277 | return { | 274 | 278 | activeAccountId: current.activeAccountId ?? null, | 275 | 279 | accounts: (current.accounts ?? []).map(summary => { | |
Collapse file Copy file name to clipboardExpand all lines: src/types/config.ts +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -288,6 +288,26 @@ export interface OcxRemoteGuiConfig { | 288 | 288 |
| 289 | 289 | export type OcxConnectedClientId = "codex" | "claude"; | 290 | 290 |
| | 291 | +/** | | 292 | + * Redaction policy for management and CLI projections (#3859). | | 293 | + * | | 294 | + * `privacy` rather than `dashboard`: `ocx status` and `ocx account` are not the dashboard, and | | 295 | + * they read the same projections. | | 296 | + */ | | 297 | +export interface OcxPrivacyConfig { | | 298 | + /** | | 299 | + * Mask stored account emails before they leave the proxy. Omitted or `true` is the historical | | 300 | + * behaviour and the default. | | 301 | + * | | 302 | + * Setting this to `false` is a real disclosure decision, not a display preference. Management | | 303 | + * is not always loopback — under `remoteGui` the unmasked address reaches every management | | 304 | + * principal that can reach the hub, not only someone sitting at the machine. The default | | 305 | + * therefore stays masked, and turning it off is an explicit opt-in by the operator who owns | | 306 | + * those accounts. | | 307 | + */ | | 308 | + maskEmails?: boolean; | | 309 | +} | | 310 | + | 291 | 311 | export interface OcxClientConnectionConfig { | 292 | 312 | serverUrl: string; | 293 | 313 | managementUrl: string; | @@ -335,6 +355,8 @@ export interface OcxConfig { | 335 | 355 | remoteGui?: OcxRemoteGuiConfig; | 336 | 356 | /** Remote-hub client state. The admission secret is stored only in service-api-token. */ | 337 | 357 | client?: OcxClientConnectionConfig; | | 358 | + /** Operator-facing redaction policy for management and CLI projections. */ | | 359 | + privacy?: OcxPrivacyConfig; | 338 | 360 | /** Opt in to one identical-turn retry when a Responses completion has no text or tool call. */ | 339 | 361 | emptyCompletionRetry?: boolean; | 340 | 362 | /** | |
|