diff --git a/config/releases/0.7.0.json b/config/releases/0.7.0.json index 9246e67bab..47fdd0321c 100644 --- a/config/releases/0.7.0.json +++ b/config/releases/0.7.0.json @@ -2,12 +2,17 @@ "product_version": "0.7.0", "chromium_version": "159.0.8154.13", "integration_repository": "BrowserOperator/browser-operator-core", - "required_merged_pr": 114, + "required_merged_pr": 115, "required_base_branch": "main", "allowed_mergers": [ "tysonthomas9" ], "additional_merged_prs": [ + { + "repository": "BrowserOperator/browser-operator-core", + "number": 114, + "base_branch": "main" + }, { "repository": "BrowserOperator/build-script", "number": 1, diff --git a/docs/chromium-159-stable-refresh.md b/docs/chromium-159-stable-refresh.md index f22f733ee2..02a3654f1d 100644 --- a/docs/chromium-159-stable-refresh.md +++ b/docs/chromium-159-stable-refresh.md @@ -13,6 +13,13 @@ two toolbar icons are retained. The earlier 159.0.8144.0 test series is not used: it lacks the latest AI update and branding patches and belongs to a different Chromium build branch. +Chromium 159 also requires the `devtools_frontend_zip` GN target for its Blink +archive/SBOM integration. The fork carries the pinned stock target and unchanged +ZIP helper, plus locale metadata for remote files. Actual archive verification +passed: all 2,951 expected fork resources, the AI bundle and all 80 remote +locales are present; repeated generation produces identical bytes. This +preserves the fork's frontend resources in the new archive. + Patch conflicts retain upstream 159 additions and removals. Parsed XML checks preserve every active upstream message ID, including whitespace-formatted attributes that text matching misses. The custom manual-update fallback ID is @@ -43,8 +50,9 @@ against the fork separately. Existing AI behavior and security backports must survive. A successful stock sync alone is not runtime security qualification. The release policy names this exact engine version and still requires owner -merge of core PR114 and build-script PR1. PR114 remains stacked on integration -PR111; retarget it to `main` after its parent merges. No candidate upload, +merge of the final security PR115, parent core PR114 and build-script PR1. +The stack is PR111 → PR114 → PR115; retarget each child to `main` after its +parent merges. The signed candidate must match PR115's final merged tree. No candidate upload, public release or production Omaha catalog promotion is authorized before the matching owner merges. Windows follows completed Mac qualification through the same entry point, with a version-aware Windows backend and actual tests. diff --git a/docs/devtools-159-security-backports.md b/docs/devtools-159-security-backports.md new file mode 100644 index 0000000000..29f2d66acc --- /dev/null +++ b/docs/devtools-159-security-backports.md @@ -0,0 +1,43 @@ +# DevTools security changes for Chromium 159 + +Reviewed stock DevTools from `047c90eca37c7170d826d72245d5df9281989cf3` +to Chromium 159.0.8154.13's pinned +`3d48567555b6795967c376050698efe2bf4f0f98`. The stock delta spans 1,572 files; +this change carries targeted protections into the older fork while retaining +Browser Operator's custom AI panel and previous HTML/font-CSS security fixes. +It does not claim a complete merge of stock DevTools or exhaustive security parity. + +The extension `openResource` API now checks the caller's runtime host policy +before revealing source code, page resources or network requests. This follows +the stock implementation, including its distinction between an apparent +`sourceURL` and the script's actual inspected target. Denied resources return a +permission error before resource/network lookup. Allowed custom-scheme scripts +continue to open when their inspected target is permitted. + +Stock 159 also has a newer security-origin framework that this fork does not +have. The inherited Google FileAgent therefore receives a conservative adapted +mitigation: only ordinary HTTP(S) network files can share a web origin, and +scripts additionally require known non-synthetic bindings with matching source +origins. Source-mapped, synthetic, local, malformed, opaque and unverifiable +files use a unique identity per file. Provenance is recomputed on every use; +only the opaque identity is cached. Ambiguous files require separate chats. + +The inherited agent backend now blocks disallowed context before refreshing or +serializing it and rechecks after asynchronous work and before model requests. +This protects direct backend calls and provenance changes while the UI awaits +data. Browser Operator's separate `panels/ai_chat` implementation is unchanged. + +Validation: targeted frontend build with full TypeScript checking passed; +all 80 tests across ExtensionServer, AiAgent and FileAgent passed in actual +headless Browser Operator 158 using disposable test profiles. New regressions +cover denied resource lookups, allowed custom schemes, misleading source URLs, +per-file opaque identities and origin changes during refresh, enhancement and +generator suspension. The extension fixture waits for its mock resource tree +before changing the inspected URL. Targeted ESLint passed. + +These results qualify the frontend changes before compiling 159. They do not +substitute for testing the final signed 159 ARM64/universal apps, native updater +or mounted DMGs. Release publication stays held for the matching owner merges. + +This is PR115, stacked on PR114. Its final source tree is the required release +merge; parent PR114 and build-script PR1 must also be merged by the owner. diff --git a/front_end/models/ai_assistance/agents/AiAgent.test.ts b/front_end/models/ai_assistance/agents/AiAgent.test.ts index 354e080367..1a511c3a5b 100644 --- a/front_end/models/ai_assistance/agents/AiAgent.test.ts +++ b/front_end/models/ai_assistance/agents/AiAgent.test.ts @@ -384,6 +384,68 @@ describeWithEnvironment('AiAgent', () => { } return new TestContext(); } + + it('blocks a cross-origin selection before refreshing or serializing it', async () => { + const client = mockAidaClient([[{explanation: 'answer'}]]); + const agent = new AiAgentMock({aidaClient: client}); + await Array.fromAsync(agent.run('first', {selected: getTestContext('https://a.test')})); + const selected = getTestContext('https://b.test'); + const refresh = sinon.spy(selected, 'refresh'); + const enhance = sinon.spy(agent, 'enhanceQuery'); + const details = sinon.spy(agent, 'handleContextDetails'); + assert.deepEqual(await Array.fromAsync(agent.run('second', {selected})), [ + {type: ResponseType.ERROR, error: ErrorType.BLOCK}, + ]); + sinon.assert.notCalled(refresh); + sinon.assert.notCalled(enhance); + sinon.assert.notCalled(details); + sinon.assert.calledOnce(client.doConversation as sinon.SinonStub); + }); + + it('blocks an origin change during the first context refresh', async () => { + const client = mockAidaClient(); + const agent = new AiAgentMock({aidaClient: client}); + const selected = getTestContext('https://a.test'); + let origin = 'https://a.test'; + sinon.stub(selected, 'getOrigin').callsFake(() => origin); + sinon.stub(selected, 'refresh').callsFake(async () => { origin = 'https://b.test'; }); + const enhance = sinon.spy(agent, 'enhanceQuery'); + assert.deepEqual(await Array.fromAsync(agent.run('question', {selected})), [ + {type: ResponseType.ERROR, error: ErrorType.BLOCK}, + ]); + sinon.assert.notCalled(enhance); + sinon.assert.notCalled(client.doConversation as sinon.SinonStub); + }); + + it('does not send a query if provenance changes during enhancement', async () => { + const client = mockAidaClient(); + const agent = new AiAgentMock({aidaClient: client}); + const selected = getTestContext('https://a.test'); + let origin = 'https://a.test'; + sinon.stub(selected, 'getOrigin').callsFake(() => origin); + sinon.stub(agent, 'enhanceQuery').callsFake(async () => { + origin = 'https://b.test'; + return 'private file content'; + }); + assert.deepEqual(await Array.fromAsync(agent.run('question', {selected})), [ + {type: ResponseType.ERROR, error: ErrorType.BLOCK}, + ]); + sinon.assert.notCalled(client.doConversation as sinon.SinonStub); + }); + + it('rechecks provenance when the consumer resumes a yielded query', async () => { + const client = mockAidaClient(); + const agent = new AiAgentMock({aidaClient: client}); + const selected = getTestContext('https://a.test'); + let origin = 'https://a.test'; + sinon.stub(selected, 'getOrigin').callsFake(() => origin); + const run = agent.run('question', {selected}); + assert.strictEqual((await run.next()).value?.type, ResponseType.USER_QUERY); + origin = 'https://b.test'; + assert.deepEqual((await run.next()).value, {type: ResponseType.ERROR, error: ErrorType.BLOCK}); + sinon.assert.notCalled(client.doConversation as sinon.SinonStub); + }); + it('checks context origins', () => { const tests = [ { diff --git a/front_end/models/ai_assistance/agents/AiAgent.ts b/front_end/models/ai_assistance/agents/AiAgent.ts index fca93b284c..29bb11f5ad 100644 --- a/front_end/models/ai_assistance/agents/AiAgent.ts +++ b/front_end/models/ai_assistance/agents/AiAgent.ts @@ -178,10 +178,8 @@ export abstract class ConversationContext { if (!agentOrigin) { return true; } - // Currently does not handle opaque origins because they - // are not available to DevTools, instead checks - // that serialization of the origin is the same - // https://html.spec.whatwg.org/#ascii-serialisation-of-an-origin. + // File contexts use a unique identity when provenance cannot establish a + // web origin. Equal serialized "null" origins must not authorize a switch. return this.getOrigin() === agentOrigin; } @@ -489,19 +487,33 @@ export abstract class AiAgent { signal?: AbortSignal, }, multimodalInput?: MultimodalInput): AsyncGenerator { - await options.selected?.refresh(); + const selected = options.selected; + const selectedOrigin = selected?.getOrigin(); + const contextAllowed = (): boolean => !selected || + (selected.getOrigin() === selectedOrigin && selected.isOriginAllowed(this.#origin)); + if (!contextAllowed()) { + yield this.#createErrorResponse(ErrorType.BLOCK); + return; + } + await selected?.refresh(); + if (!contextAllowed()) { + yield this.#createErrorResponse(ErrorType.BLOCK); + return; + } - if (options.selected) { + if (selected) { // First context set on the agent determines its origin from now on. if (this.#origin === undefined) { - this.#origin = options.selected.getOrigin(); - } - if (options.selected.isOriginAllowed(this.#origin)) { - this.context = options.selected; + this.#origin = selectedOrigin; } + this.context = selected; } - const enhancedQuery = await this.enhanceQuery(initialQuery, options.selected, multimodalInput?.type); + const enhancedQuery = await this.enhanceQuery(initialQuery, selected, multimodalInput?.type); + if (!contextAllowed()) { + yield this.#createErrorResponse(ErrorType.BLOCK); + return; + } Host.userMetrics.freestylerQueryLength(enhancedQuery.length); let query: Host.AidaClient.Part|Host.AidaClient.Part[]; @@ -516,12 +528,20 @@ export abstract class AiAgent { imageId: multimodalInput?.id, }; - yield* this.handleContextDetails(options.selected); + if (!contextAllowed()) { + yield this.#createErrorResponse(ErrorType.BLOCK); + return; + } + yield* this.handleContextDetails(selected); for (let i = 0; i < MAX_STEPS; i++) { yield { type: ResponseType.QUERYING, }; + if (!contextAllowed()) { + yield this.#createErrorResponse(ErrorType.BLOCK); + return; + } let rpcId: Host.AidaClient.RpcGlobalId|undefined; let textResponse = ''; diff --git a/front_end/models/ai_assistance/agents/FileAgent.test.ts b/front_end/models/ai_assistance/agents/FileAgent.test.ts index 329a794cdf..a29ab07fee 100644 --- a/front_end/models/ai_assistance/agents/FileAgent.test.ts +++ b/front_end/models/ai_assistance/agents/FileAgent.test.ts @@ -3,6 +3,7 @@ // found in the LICENSE file. import * as Host from '../../../core/host/host.js'; +import * as Platform from '../../../core/platform/platform.js'; import * as SDK from '../../../core/sdk/sdk.js'; import {createUISourceCode, mockAidaClient} from '../../../testing/AiAssistanceHelpers.js'; import { @@ -38,6 +39,53 @@ describeWithMockConnection('FileAgent', () => { }); }); + describe('context provenance', () => { + it('keeps synthetic, mapped and opaque files isolated while preserving each file identity', async () => { + const file = await createUISourceCode(); + assert.exists(file); + sinon.stub(file.project(), 'type').returns(Workspace.Workspace.projectTypes.Network); + const context = new FileContext(file); + const binding = Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance(); + const scripts = sinon.stub(binding, 'scriptsForUISourceCode'); + const script = sinon.createStubInstance(SDK.Script.Script); + script.sourceURL = file.url(); + script.hasSourceURL = false; + scripts.returns([script]); + assert.strictEqual(context.getOrigin(), 'http://example.test'); + script.hasSourceURL = true; + const opaque = context.getOrigin(); + assert.notStrictEqual(opaque, 'http://example.test'); + assert.strictEqual(new FileContext(file).getOrigin(), opaque); + script.hasSourceURL = false; + assert.strictEqual(context.getOrigin(), 'http://example.test'); + scripts.returns([]); + assert.strictEqual(context.getOrigin(), opaque); + scripts.throws(new Error('missing binding')); + assert.strictEqual(context.getOrigin(), opaque); + const other = await createUISourceCode({url: Platform.DevToolsPath.urlString`data:text/javascript,other`}); + assert.exists(other); + assert.notStrictEqual(new FileContext(other).getOrigin(), opaque); + assert.notStrictEqual(new FileContext(other).getOrigin(), 'null'); + }); + + it('never trusts a source map or mismatched script origin', async () => { + const file = await createUISourceCode(); + assert.exists(file); + sinon.stub(file.project(), 'type').returns(Workspace.Workspace.projectTypes.Network); + const context = new FileContext(file); + const script = sinon.createStubInstance(SDK.Script.Script); + script.sourceURL = 'https://attacker.test/script.js' as typeof script.sourceURL; + script.hasSourceURL = false; + sinon.stub(Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance(), 'scriptsForUISourceCode') + .returns([script]); + const opaque = context.getOrigin(); + assert.notStrictEqual(opaque, 'http://example.test'); + script.sourceURL = file.url(); + sinon.stub(file.contentType(), 'isFromSourceMap').returns(true); + assert.strictEqual(context.getOrigin(), opaque); + }); + }); + describe('buildRequest', () => { it('builds a request with a model id', async () => { mockHostConfig('test model'); diff --git a/front_end/models/ai_assistance/agents/FileAgent.ts b/front_end/models/ai_assistance/agents/FileAgent.ts index 4379a8c871..1fa00e3f17 100644 --- a/front_end/models/ai_assistance/agents/FileAgent.ts +++ b/front_end/models/ai_assistance/agents/FileAgent.ts @@ -5,7 +5,8 @@ import * as Host from '../../../core/host/host.js'; import * as i18n from '../../../core/i18n/i18n.js'; import * as Root from '../../../core/root/root.js'; -import type * as Workspace from '../../workspace/workspace.js'; +import * as Bindings from '../../bindings/bindings.js'; +import * as Workspace from '../../workspace/workspace.js'; import {FileFormatter} from '../data_formatters/FileFormatter.js'; import { @@ -74,6 +75,10 @@ const UIStringsNotTranslate = { const lockedString = i18n.i18n.lockedString; +// Opaque contexts must not share the URL API's serialized "null" origin. +const opaqueFileOrigins = new WeakMap(); +let nextOpaqueFileOrigin = 0; + export class FileContext extends ConversationContext { #file: Workspace.UISourceCode.UISourceCode; @@ -83,7 +88,32 @@ export class FileContext extends ConversationContext + !script.hasSourceURL && new URL(script.sourceURL).origin === url.origin)) { + return url.origin; + } + } + } catch { + // Missing bindings and malformed/unverifiable URLs are opaque too. + } + let origin = opaqueFileOrigins.get(this.#file); + if (!origin) { + origin = `opaque-file:${++nextOpaqueFileOrigin}:${crypto.randomUUID()}`; + opaqueFileOrigins.set(this.#file, origin); + } + return origin; } override getItem(): Workspace.UISourceCode.UISourceCode { diff --git a/front_end/models/extensions/ExtensionServer.test.ts b/front_end/models/extensions/ExtensionServer.test.ts index 2aa6be69b8..079d595f01 100644 --- a/front_end/models/extensions/ExtensionServer.test.ts +++ b/front_end/models/extensions/ExtensionServer.test.ts @@ -14,7 +14,7 @@ import { getExtensionOrigin, } from '../../testing/ExtensionHelpers.js'; import {MockProtocolBackend} from '../../testing/MockScopeChain.js'; -import {addChildFrame, FRAME_URL, getMainFrame} from '../../testing/ResourceTreeHelpers.js'; +import {addChildFrame, FRAME_URL, getInitializedResourceTreeModel, getMainFrame} from '../../testing/ResourceTreeHelpers.js'; import {encodeSourceMap} from '../../testing/SourceMapEncoder.js'; import * as Components from '../../ui/legacy/components/utils/utils.js'; import * as UI from '../../ui/legacy/legacy.js'; @@ -485,6 +485,77 @@ const hostsPolicy = { runtimeBlockedHosts: [allowedUrl, blockedUrl], }; +describeWithDevtoolsExtension('openResource hosts policy', { + hostsPolicy: {runtimeAllowedHosts: [FRAME_URL], runtimeBlockedHosts: [blockedUrl]}, +}, context => { + expectConsoleLogs({error: ['Extension server error: Operation failed: Permission denied']}); + const blockedResource = urlString`http://web.dev/script.js`; + const allowedResource = urlString`http://example.com/script.js`; + const permissionDenied = { + code: 'E_FAILED', + description: 'Operation failed: %s', + details: ['Permission denied'], + isError: true, + }; + + beforeEach(() => { + createTarget({type: SDK.Target.Type.FRAME}).setInspectedURL(FRAME_URL); + assert.exists(context.chrome.devtools); + }); + + async function createSourceURLScript(url: Platform.DevToolsPath.UrlString, targetUrl: Platform.DevToolsPath.UrlString) { + const target = createTarget({id: 'script-target' as Protocol.Target.TargetID}); + await getInitializedResourceTreeModel(target); + target.setInspectedURL(targetUrl); + const script = sinon.createStubInstance(SDK.Script.Script, {target, contentURL: url}); + script.hasSourceURL = true; + const project = new Bindings.ContentProviderBasedProject.ContentProviderBasedProject( + Workspace.Workspace.WorkspaceImpl.instance(), 'open-resource-test', Workspace.Workspace.projectTypes.Network, + '', false); + const source = new Workspace.UISourceCode.UISourceCode(project, url, Common.ResourceType.resourceTypes.Script); + sinon.stub(Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding, 'instance') + .returns(sinon.createStubInstance( + Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding, {scriptsForUISourceCode: [script]})); + sinon.stub(Workspace.Workspace.WorkspaceImpl.instance(), 'uiSourceCodeForURL').withArgs(url).returns(source); + return source; + } + + async function openResource(url: Platform.DevToolsPath.UrlString): Promise { + return await new Promise(resolve => { + context.chrome.devtools!.panels.openResource(url, 0, undefined, (response?: unknown) => resolve(response)); + }); + } + + it('denies blocked URLs before resource or network lookup', async () => { + sinon.stub(Workspace.Workspace.WorkspaceImpl.instance(), 'uiSourceCodeForURL').returns(null); + const resourceLookup = sinon.stub(SDK.ResourceTreeModel.ResourceTreeModel, 'resourceForURL'); + const networkLookup = sinon.stub(Logs.NetworkLog.NetworkLog.instance(), 'requestForURL').returns(null); + const reveal = sinon.stub(Common.Revealer.RevealerRegistry.instance(), 'reveal').resolves(); + for (const resource of [sinon.createStubInstance(SDK.Resource.Resource), null]) { + resourceLookup.returns(resource); + assert.deepEqual(await openResource(blockedResource), permissionDenied); + } + sinon.assert.notCalled(resourceLookup); + sinon.assert.notCalled(networkLookup); + sinon.assert.notCalled(reveal); + }); + + it('opens a custom-scheme sourceURL script on an allowed target', async () => { + const url = urlString`webpack://app/script.js`; + const source = await createSourceURLScript(url, FRAME_URL); + const reveal = sinon.stub(Common.Revealer.RevealerRegistry.instance(), 'reveal').resolves(); + assert.deepEqual(await openResource(url), {code: 'OK', description: 'OK', details: []}); + sinon.assert.calledOnceWithExactly(reveal, source.uiLocation(0, 0), false); + }); + + it('denies an allowed-looking sourceURL script on a blocked target', async () => { + await createSourceURLScript(allowedResource, blockedResource); + const reveal = sinon.stub(Common.Revealer.RevealerRegistry.instance(), 'reveal').resolves(); + assert.deepEqual(await openResource(allowedResource), permissionDenied); + sinon.assert.notCalled(reveal); + }); +}); + function waitForFunction(fn: () => T): Promise { return new Promise(r => { const check = () => { diff --git a/front_end/models/extensions/ExtensionServer.ts b/front_end/models/extensions/ExtensionServer.ts index e144f218e3..623d50ef4e 100644 --- a/front_end/models/extensions/ExtensionServer.ts +++ b/front_end/models/extensions/ExtensionServer.ts @@ -761,16 +761,23 @@ export class ExtensionServer extends Common.ObjectWrapper.ObjectWrapper