The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
browser-extension: fail closed on unreadable policy, resync options, gate the ID
shukieshah9e26a42456e7
diff --git a/browser-extension/src/background/settings.ts b/browser-extension/src/background/settings.tsindex f1d020c4..39e3caf0 100644--- a/browser-extension/src/background/settings.ts+++ b/browser-extension/src/background/settings.ts@@ -16,10 +16,13 @@ const KEY = 'settings';// Concurrent popup and options patches must merge over the preceding write, not a stale snapshot.const withSettingsLock = serial();-/** Effective settings plus the ones policy fixed. */+/** Effective settings plus the ones policy fixed. `managedError` is set when Chrome could not+ * read the policy values, in which case nothing may be captured or changed: the locks in force+ * are unknown. */export interface SettingsState {settings: Settings;locked: LockedSetting[];+ managedError?: string;}/**@@ -82,8 +85,10 @@ export function lockedIn(patch: Partial<Settings>, locked: readonly LockedSettinexport async function getSettingsState(): Promise<SettingsState> {const [stored, managed] = await Promise.all([getStoredSettings(), readManaged()]);- const { patch, locked } = resolveManaged(managed);- return { settings: merge(stored, patch), locked };+ const { patch, locked } = resolveManaged(managed.values);+ const state: SettingsState = { settings: merge(stored, patch), locked };+ if (managed.error) state.managedError = managed.error;+ return state;}export async function getSettings(): Promise<Settings> {@@ -100,7 +105,7 @@ export function saveSettings(patch: Partial<Settings>): Promise<Settings> {const [current, managed] = await Promise.all([getStoredSettings(), readManaged()]);const next = merge(current, patch);await ext.storage.local.set({ [KEY]: next });- return merge(next, resolveManaged(managed).patch);+ return merge(next, resolveManaged(managed.values).patch);});}@@ -113,14 +118,18 @@ async function getStoredSettings(): Promise<Settings> {return resolveSettings(got[KEY]);}-// Managed storage is absent where nothing manages the browser: Firefox rejects-// the read without an enterprise policy, and test doubles have no managed area.-// Both mean no policy values.-async function readManaged(): Promise<unknown> {+// No managed area (test doubles) and Firefox's refusal when no enterprise policy+// configures the extension both mean no policy. Any other failure is reported, not+// read as "no policy": that would drop an admin's locks silently.+async function readManaged(): Promise<{ values?: unknown; error?: string }> {+ const area = ext.storage.managed;+ if (!area) return {};try {- return await ext.storage.managed?.get(null);- } catch {- return undefined;+ return { values: await area.get(null) };+ } catch (err) {+ const message = err instanceof Error ? err.message : String(err);+ if (/managed storage manifest not found/i.test(message)) return {};+ return { error: message };}}diff --git a/browser-extension/src/background/sw.ts b/browser-extension/src/background/sw.tsindex 178a0f1f..f366f123 100644--- a/browser-extension/src/background/sw.ts+++ b/browser-extension/src/background/sw.ts@@ -5,7 +5,7 @@ import '../adapters/claude.js'; // registers the Claude adapter (side effect)import '../adapters/chatgpt.js'; // registers the ChatGPT adapter (side effect)import { ext } from '../shared/browser.js';import type { ChatTurn } from '../shared/types.js';-import { getSettings, getSettingsState, lockedIn, saveSettings, siteEnabled } from './settings.js';+import { getSettingsState, lockedIn, saveSettings, siteEnabled } from './settings.js';import { Assembler } from './assembler.js';import { enqueueTurn, flush, installFlushAlarm } from './delivery.js';import { detectBrowser } from '../shared/browser-identity.js';@@ -79,7 +79,10 @@ ext.runtime.onMessage.addListener((msg: unknown, sender, sendResponse) => {});async function finalizeTurn(turn: ChatTurn): Promise<void> {- const settings = await getSettings();+ const { settings, managedError } = await getSettingsState();+ // Fail closed: when Chrome cannot read the policy, the retention and endpoint an admin locked+ // are unknown, so the turn is not captured rather than sent under the user's settings.+ if (managedError) return;// siteEnabled covers both the global toggle and the per-site toggle.if (!siteEnabled(settings, turn.site)) return;await enqueueTurn(turn, settings, browserIdentity);@@ -99,14 +102,17 @@ function isControlType(type: unknown): type is ControlMessage['type'] {async function handleControl(msg: ControlMessage): Promise<unknown> {switch (msg.type) {case 'GET_STATUS': {- const { settings, locked } = await getSettingsState();+ const state = await getSettingsState();const q = await ext.storage.local.get('delivery_queue');- return { settings, locked, queueDepth: (q.delivery_queue ?? []).length, active: assembler.active };+ return { ...state, queueDepth: (q.delivery_queue ?? []).length, active: assembler.active };}case 'SET_SETTINGS': {const parsed = parseSettingsPatch(msg.patch);const state = await getSettingsState();if (!parsed.ok) return { error: parsed.error, ...state };+ if (state.managedError) {+ return { error: `your organization's settings could not be read: ${state.managedError}`, ...state };+ }const locked = lockedIn(parsed.patch, state.locked);if (locked) return { error: `${locked} is set by your organization and cannot be changed here`, ...state };return { settings: await saveSettings(parsed.patch), locked: state.locked };diff --git a/browser-extension/src/options/options.html b/browser-extension/src/options/options.htmlindex 84256309..5d494590 100644--- a/browser-extension/src/options/options.html+++ b/browser-extension/src/options/options.html@@ -28,8 +28,7 @@<button id="perm-grant" data-testid="perm-grant">Grant site access</button></div>- <p class="managed" id="managed" data-testid="managed" hidden>Some settings are managed by your- organization and cannot be changed here.</p>+ <p class="managed" id="managed" data-testid="managed" hidden>Some settings are managed by your organization and cannot be changed here.</p><label for="endpoint">OTLP logs endpoint</label><input type="text" id="endpoint" data-testid="endpoint" />diff --git a/browser-extension/src/options/options.ts b/browser-extension/src/options/options.tsindex fbd01976..a61a1dcc 100644--- a/browser-extension/src/options/options.ts+++ b/browser-extension/src/options/options.ts@@ -7,25 +7,43 @@ const $ = <T extends HTMLElement>(id: string) => document.getElementById(id) asconst SITES: readonly SiteName[] = ['claude_web', 'chatgpt_web'];const siteBox = (site: SiteName) => $(`site_${site}`) as HTMLInputElement;+interface SettingsReply {+ settings?: Settings;+ locked?: LockedSetting[];+ managedError?: string;+ error?: string;+}+// Settings fixed by policy: shown, disabled, and left out of every save.let locked = new Set<LockedSetting>();-async function load(): Promise<void> {- const status = (await ext.runtime.sendMessage({ type: 'GET_STATUS' })) as {- settings: Settings;- locked?: LockedSetting[];- };- locked = new Set(status.locked ?? []);+/** Show what policy enforces. Locked controls take the enforced value; unlocked ones keep whatever+ * the user has typed, so a save refused because a lock arrived can be repeated without it. */+function applyPolicy(reply: SettingsReply): void {+ if (!reply.settings) return;+ locked = new Set(reply.locked ?? []);+ const unreadable = reply.managedError != null;const endpoint = $('endpoint') as HTMLInputElement;- endpoint.value = status.settings.endpoint;- endpoint.disabled = locked.has('endpoint');+ endpoint.disabled = unreadable || locked.has('endpoint');+ if (locked.has('endpoint')) endpoint.value = reply.settings.endpoint;for (const site of SITES) {- siteBox(site).checked = status.settings.sites[site] !== false;- siteBox(site).disabled = locked.has(`sites.${site}`);+ const box = siteBox(site);+ box.disabled = unreadable || locked.has(`sites.${site}`);+ if (locked.has(`sites.${site}`)) box.checked = reply.settings.sites[site] !== false;}($('save') as HTMLButtonElement).disabled =endpoint.disabled && SITES.every((site) => siteBox(site).disabled);- $('managed').hidden = locked.size === 0;+ $('managed').textContent = unreadable+ ? "Your organization's settings could not be read, so capture is paused and nothing can be changed."+ : 'Some settings are managed by your organization and cannot be changed here.';+ $('managed').hidden = !unreadable && locked.size === 0;+}++async function load(): Promise<void> {+ const status = (await ext.runtime.sendMessage({ type: 'GET_STATUS' })) as SettingsReply & { settings: Settings };+ ($('endpoint') as HTMLInputElement).value = status.settings.endpoint;+ for (const site of SITES) siteBox(site).checked = status.settings.sites[site] !== false;+ applyPolicy(status);}$('save').addEventListener('click', async () => {@@ -36,9 +54,9 @@ $('save').addEventListener('click', async () => {if (!locked.has(`sites.${site}`)) sites[site] = siteBox(site).checked;}if (Object.keys(sites).length > 0) patch.sites = sites as Settings['sites'];- const res = (await ext.runtime.sendMessage({ type: 'SET_SETTINGS', patch })) as {- error?: string;- };+ const res = (await ext.runtime.sendMessage({ type: 'SET_SETTINGS', patch })) as SettingsReply;+ // Every reply carries the policy now in force, which may have changed since the page loaded.+ if (res) applyPolicy(res);// The service worker validates every patch; a rejected one changes nothing.const error = $('error');error.textContent = res?.error ?? '';diff --git a/browser-extension/src/popup/popup.ts b/browser-extension/src/popup/popup.tsindex e19e63fd..29fd9b0a 100644--- a/browser-extension/src/popup/popup.ts+++ b/browser-extension/src/popup/popup.ts@@ -6,6 +6,7 @@ import type { LockedSetting, Settings } from '../shared/types.js';interface Status {settings: Settings;locked?: LockedSetting[];+ managedError?: string;queueDepth: number;active: number;}@@ -19,11 +20,16 @@ async function refresh(): Promise<void> {$('endpoint').textContent = status.settings.endpoint;$('queue').textContent = String(status.queueDepth);$('active').textContent = String(status.active);- // Settings fixed by policy stay visible but cannot be changed here.+ // Settings fixed by policy stay visible but cannot be changed here. When the policy could not be+ // read, nothing can be changed and nothing is captured.const locked = new Set(status.locked ?? []);- ($('enabled') as HTMLInputElement).disabled = locked.has('enabled');- ($('retention') as HTMLSelectElement).disabled = locked.has('retention');- $('managed').hidden = locked.size === 0;+ const unreadable = status.managedError != null;+ ($('enabled') as HTMLInputElement).disabled = unreadable || locked.has('enabled');+ ($('retention') as HTMLSelectElement).disabled = unreadable || locked.has('retention');+ $('managed').textContent = unreadable+ ? "Your organization's settings could not be read, so capture is paused."+ : 'Some settings are managed by your organization.';+ $('managed').hidden = !unreadable && locked.size === 0;}$('enabled').addEventListener('change', async (e) => {diff --git a/browser-extension/test/unit/settings-managed.test.ts b/browser-extension/test/unit/settings-managed.test.tsindex 0629ce07..7217ddd1 100644--- a/browser-extension/test/unit/settings-managed.test.ts+++ b/browser-extension/test/unit/settings-managed.test.ts@@ -65,11 +65,18 @@ describe('effective settings', () => {expect(locked).toEqual(['enabled', 'endpoint']);});- it('treats a browser without managed storage as unmanaged', async () => {+ it("reads Firefox's no-policy refusal as unmanaged", async () => {managed.get.mockRejectedValue(new Error('Managed storage manifest not found'));expect(await getSettingsState()).toEqual({ settings: DEFAULT_SETTINGS, locked: [] });});+ it('reports any other managed-storage failure instead of reading it as no policy', async () => {+ managed.get.mockRejectedValue(new Error('IO error: LOCK: Resource temporarily unavailable'));+ const state = await getSettingsState();+ expect(state.managedError).toContain('IO error');+ expect(state.locked).toEqual([]);+ });+it('saves the user choice beside a lock without writing the policy value', async () => {managed.get.mockResolvedValue({ retention: 'metadata' });const effective = await saveSettings({ enabled: false });diff --git a/browser-extension/test/unit/targets.test.ts b/browser-extension/test/unit/targets.test.tsindex d834103f..ee2e8fcb 100644--- a/browser-extension/test/unit/targets.test.ts+++ b/browser-extension/test/unit/targets.test.ts@@ -146,7 +146,8 @@ describe('chrome self-hosted build', () => {// Chrome derives the ID from the CRX signing key, and every fleet's force-install policy names// it. Changing it means a new key, a new extension, and rewriting every policy, so this// assertion is deliberately a literal.- expect(CHROME_EXTENSION_ID).toBe('PENDING_SIGNING_KEY');+ // Fails until the production signing key's ID is pinned here, so a placeholder cannot merge.+ expect(CHROME_EXTENSION_ID).toMatch(/^[a-p]{32}$/);});it('points installed copies at the update feed the release workflow publishes', () => {