Skip to content

Commit 4c11302

Browse files
authored
fix(memory): rank exact hits by net relevance
1 parent 6d668c7 commit 4c11302

26 files changed

Lines changed: 2872 additions & 575 deletions

‎apps/macos/Tests/OpenClawIPCTests/ExecApprovalsSocketPathGuardTests.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ struct ExecApprovalsSocketPathGuardTests {
170170
// old filesystem assertions here flaked on their 0755 default
171171
// (#104019). Creation-with-0700 is covered by the explicit-path
172172
// tests in this suite.
173-
try await TestIsolation.withEnvValues(["OPENCLAW_STATE_DIR": stateDir.path]) {
173+
await TestIsolation.withEnvValues(["OPENCLAW_STATE_DIR": stateDir.path]) {
174174
let socketPath = ExecApprovalsStore.socketPath()
175175
#expect(socketPath == stateDir.appendingPathComponent("exec-approvals.sock").path)
176176
}

‎apps/macos/Tests/OpenClawIPCTests/ExecApprovalsStoreRefactorTests.swift‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,19 +2242,16 @@ extension ExecApprovalsStoreRefactorTests {
22422242
[.modificationDate: Date().addingTimeInterval(-31)],
22432243
ofItemAtPath: lockURL.path)
22442244

2245-
let startedAt = Date()
22462245
let result = ExecApprovalsStore.addAllowlistEntry(
22472246
agentId: "main",
22482247
pattern: "/bin/echo")
2249-
let elapsed = Date().timeIntervalSince(startedAt)
22502248

22512249
guard case .failure(.unavailable) = result else {
22522250
Issue.record("expected lock contention failure")
22532251
return
22542252
}
22552253
#expect(FileManager().fileExists(atPath: lockURL.path))
22562254
#expect(try Data(contentsOf: lockURL) == Data("{".utf8))
2257-
#expect(elapsed < 0.5)
22582255
#expect(ExecApprovalsStore.loadFile().agents?["main"]?.allowlist?.isEmpty != false)
22592256
}
22602257
}

‎docs/gateway/security/index.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ Private/internal destinations stay blocked unless you explicitly opt in.
481481
- Default: `browser.ssrfPolicy.dangerouslyAllowPrivateNetwork` unset, so private/internal/special-use destinations stay blocked. Legacy alias `allowPrivateNetwork` still accepted.
482482
- Opt-in: set `dangerouslyAllowPrivateNetwork: true` to allow those destinations.
483483
- In strict mode, use `hostnameAllowlist` (patterns like `*.example.com`) and `allowedHostnames` (exact host exceptions, including otherwise-blocked names like `localhost`) for explicit exceptions.
484-
- Navigation is checked before the request and best-effort re-checked on the final `http(s)` URL after navigation, to reduce redirect-based pivots.
484+
- Direct navigation requests are preflight checked. During the action and bounded post-action grace, guarded Playwright interactions (click, coordinate click, hover, drag, scroll, select, press, type, form fill, and evaluate) intercept policy-denied top-level and subframe document loads before HTTP request bytes, then best-effort re-check the final `http(s)` URL.
485+
- Before each fresh managed Chrome launch, OpenClaw best-effort disables network prediction, suppressing Chromium's observed speculative preconnect for those denied loads. This is defense in depth, not a policy boundary: a browser reused across a control-service restart and other browser backends may not share the hardening. Page routing remains request-level interception, not a network firewall: redirect hops, a popup's first request, Service Worker traffic, page code that runs after the bounded guard window, and some background/subresource paths can bypass it. Final-URL checks remain detection/quarantine defense; complete prevention requires owner-side egress isolation or a policy-enforcing proxy.
485486

486487
```json5
487488
{

‎docs/tools/browser.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ main model can read the screenshot directly.
290290

291291
<Accordion title="SSRF policy">
292292

293-
- Browser navigation and open-tab are SSRF-guarded before navigation and best-effort re-checked on the final `http(s)` URL afterwards.
293+
- Browser navigation and open-tab requests are preflight checked. During the action and bounded post-action grace, guarded Playwright interactions (click, coordinate click, hover, drag, scroll, select, press, type, form fill, and evaluate) intercept policy-denied top-level and subframe document loads before HTTP request bytes, then best-effort re-check the final `http(s)` URL.
294+
- Before each fresh OpenClaw-managed Chrome launch, OpenClaw best-effort disables network prediction, suppressing Chromium's observed speculative preconnect for those denied loads. This is defense in depth, not a policy boundary: a browser reused across a control-service restart and other browser backends may not share the hardening. Playwright routing is still not a network firewall and does not intercept redirect hops, a popup's first request, Service Worker traffic, page code that runs after the bounded guard window, or every background/subresource path. Complete egress isolation requires owner-side isolation or a policy-enforcing proxy.
294295
- In strict SSRF mode, remote CDP endpoint discovery and `/json/version` probes (`cdpUrl`) are checked too.
295296
- Gateway/provider `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, and `NO_PROXY` environment variables do not automatically proxy the OpenClaw-managed browser. Managed Chrome launches direct by default so provider proxy settings do not weaken browser SSRF checks.
296297
- OpenClaw-managed local CDP readiness probes and DevTools WebSocket connections bypass the managed network proxy for the exact launched loopback endpoint, so `openclaw browser start` still works when an operator proxy blocks loopback egress.

‎extensions/browser/src/browser-tool.schema.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@ describe("browser tool schema", () => {
3838
expect(properties.action.enum).toEqual(expect.arrayContaining(["download", "waitfordownload"]));
3939
expect(properties.path).toBeDefined();
4040
});
41+
42+
it("exposes scrollIntoView on nested and flattened act params", () => {
43+
const properties = BrowserToolSchema.properties as BrowserSchemaRecord;
44+
const requestProperties = properties.request.properties as BrowserSchemaRecord;
45+
46+
expect(properties.kind.enum).toContain("scrollIntoView");
47+
expect(requestProperties.kind.enum).toContain("scrollIntoView");
48+
});
4149
});

‎extensions/browser/src/browser-tool.schema.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const BROWSER_ACT_KINDS = [
2020
"type",
2121
"press",
2222
"hover",
23+
"scrollIntoView",
2324
"drag",
2425
"select",
2526
"fill",

‎extensions/browser/src/browser/chrome.profile-decoration.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* OpenClaw-managed Chrome profile decoration.
33
*
4-
* Applies a stable profile name, color, download directory, and clean-exit
5-
* markers to the managed Chrome profile's Local State and Preferences files.
4+
* Applies managed-browser policy, a stable profile name, color, download
5+
* directory, and clean-exit markers to Chrome's profile files.
66
*/
77
import fs from "node:fs";
88
import path from "node:path";
@@ -12,6 +12,8 @@ import {
1212
DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME,
1313
} from "./constants.js";
1414

15+
const CHROME_NETWORK_PREDICTION_DISABLED = 2;
16+
1517
function decoratedMarkerPath(userDataDir: string) {
1618
return path.join(userDataDir, ".openclaw-profile-decorated");
1719
}
@@ -120,6 +122,16 @@ export function usesOpenClawMockKeychain(userDataDir: string): boolean {
120122
return readDefaultProfileInfo(localState)?.openclaw_mock_keychain === true;
121123
}
122124

125+
/** Disable Chromium network prediction in an OpenClaw-managed Chrome profile. */
126+
export function ensureProfileNetworkPredictionDisabled(userDataDir: string) {
127+
const preferencesPath = path.join(userDataDir, "Default", "Preferences");
128+
const prefs = safeReadJson(preferencesPath) ?? {};
129+
// Chromium can preconnect before CDP Fetch interception. Disable that source
130+
// of target contact before each fresh managed-browser launch.
131+
setDeep(prefs, ["net", "network_prediction_options"], CHROME_NETWORK_PREDICTION_DISABLED);
132+
safeWriteJson(preferencesPath, prefs);
133+
}
134+
123135
/**
124136
* Best-effort profile decoration (name + lobster-orange). Chrome preference keys
125137
* vary by version; we keep this conservative and idempotent.

‎extensions/browser/src/browser/chrome.test.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ import {
3030
resolveBrowserExecutableForPlatform,
3131
stopOpenClawChrome,
3232
} from "./chrome.js";
33-
import { usesOpenClawMockKeychain } from "./chrome.profile-decoration.js";
33+
import {
34+
ensureProfileNetworkPredictionDisabled,
35+
usesOpenClawMockKeychain,
36+
} from "./chrome.profile-decoration.js";
3437
import {
3538
DEFAULT_OPENCLAW_BROWSER_COLOR,
3639
DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME,
@@ -307,6 +310,22 @@ describe("browser chrome profile decoration", () => {
307310
expect(prefs.exited_cleanly).toBe(true);
308311
});
309312

313+
it("disables speculative network prediction without replacing sibling net prefs", async () => {
314+
const userDataDir = await createUserDataDir();
315+
const preferencesPath = path.join(userDataDir, "Default", "Preferences");
316+
await fsp.mkdir(path.dirname(preferencesPath), { recursive: true });
317+
await fsp.writeFile(
318+
preferencesPath,
319+
`${JSON.stringify({ net: { quic_allowed: false } })}\n`,
320+
"utf-8",
321+
);
322+
323+
ensureProfileNetworkPredictionDisabled(userDataDir);
324+
325+
const prefs = await readJson(preferencesPath);
326+
expect(prefs.net).toEqual({ quic_allowed: false, network_prediction_options: 2 });
327+
});
328+
310329
it("is idempotent when rerun on an existing profile", async () => {
311330
const userDataDir = await createUserDataDir();
312331
decorateOpenClawProfile(userDataDir, { color: DEFAULT_OPENCLAW_BROWSER_COLOR });

‎extensions/browser/src/browser/chrome.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import {
6363
import {
6464
decorateOpenClawProfile,
6565
ensureProfileCleanExit,
66+
ensureProfileNetworkPredictionDisabled,
6667
isProfileDecorated,
6768
usesOpenClawMockKeychain,
6869
} from "./chrome.profile-decoration.js";
@@ -1126,6 +1127,12 @@ export async function launchOpenClawChrome(
11261127
}
11271128
}
11281129

1130+
try {
1131+
ensureProfileNetworkPredictionDisabled(userDataDir);
1132+
} catch (err) {
1133+
log.warn(`openclaw browser network-prediction prefs failed: ${String(err)}`);
1134+
}
1135+
11291136
try {
11301137
ensureProfileCleanExit(userDataDir);
11311138
} catch (err) {

0 commit comments

Comments
 (0)