Skip to content

Commit 4f0470d

Browse files
authored
Merge pull request #999 from 0xdeafbeef/agent/silence-aura-fallback-output
fix(browser): silence Aura allowlist fallback output
2 parents d3c1bd2 + af643f5 commit 4f0470d

2 files changed

Lines changed: 133 additions & 39 deletions

File tree

scripts/lib/bundled-plugins.sh

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,33 +1090,17 @@ import sys
10901090
10911091
path = Path(sys.argv[1])
10921092
source = path.read_text(encoding="utf-8")
1093-
patterns = [
1094-
re.compile(
1095-
r'async fetchBlocked\((?P<url>[A-Za-z_$][\w$]*)\)\{'
1096-
r'let (?P<response>[A-Za-z_$][\w$]*)=await (?P<fetch>[A-Za-z_$][\w$]*)'
1097-
r'\((?P=url)\.endpoint,\{method:"GET"\}\);'
1098-
r'if\(!(?P=response)\.ok\)throw new Error\((?P<format>[A-Za-z_$][\w$]*)'
1099-
r'\(`Browser Use cannot determine if \$\{(?P=url)\.displayUrl\} is allowed\. '
1100-
r'Please try again later or use another source\.`\)\);'
1101-
r'let (?P<json>[A-Za-z_$][\w$]*)=await (?P=response)\.json\(\);'
1102-
r'return (?P<status>[A-Za-z_$][\w$]*)\((?P=json)\)\}'
1103-
),
1104-
re.compile(
1105-
r'async fetchBlocked\((?P<url>[A-Za-z_$][\w$]*),(?P<label>[A-Za-z_$][\w$]*)\)\{'
1106-
r'let (?P<response>[A-Za-z_$][\w$]*)=await (?P<fetch>[A-Za-z_$][\w$]*)'
1107-
r'\((?P=url)\.endpoint,\{method:"GET"\}\);'
1108-
r'if\(!(?P=response)\.ok\)throw new Error\((?P<format>[A-Za-z_$][\w$]*)'
1109-
r'\(`\$\{(?P=label)\} cannot determine if \$\{(?P=url)\.displayUrl\} is allowed\. '
1110-
r'Please try again later or use another source\.`\)\);'
1111-
r'let (?P<json>[A-Za-z_$][\w$]*)=await (?P=response)\.json\(\);'
1112-
r'return (?P<status>[A-Za-z_$][\w$]*)\((?P=json)\)\}'
1113-
),
1114-
]
1115-
match = None
1116-
for pattern in patterns:
1117-
match = pattern.search(source)
1118-
if match is not None:
1119-
break
1093+
pattern = re.compile(
1094+
r'async fetchBlocked\((?P<url>[A-Za-z_$][\w$]*),(?P<label>[A-Za-z_$][\w$]*)\)\{'
1095+
r'let (?P<response>[A-Za-z_$][\w$]*)=await (?P<fetch>[A-Za-z_$][\w$]*)'
1096+
r'\((?P=url)\.endpoint,\{method:"GET"\}\);'
1097+
r'if\(!(?P=response)\.ok\)throw new Error\((?P<format>[A-Za-z_$][\w$]*)'
1098+
r'\(`\$\{(?P=label)\} cannot determine if \$\{(?P=url)\.displayUrl\} is allowed\. '
1099+
r'Please try again later or use another source\.`\)\);'
1100+
r'let (?P<json>[A-Za-z_$][\w$]*)=await (?P=response)\.json\(\);'
1101+
r'return (?P<status>[A-Za-z_$][\w$]*)\((?P=json)\)\}'
1102+
)
1103+
match = pattern.search(source)
11201104
if match is None:
11211105
if "/aura/site_status" not in source and "fetchBlocked(" not in source:
11221106
raise SystemExit(0)
@@ -1132,19 +1116,14 @@ fetch = match.group("fetch")
11321116
formatter = match.group("format")
11331117
json_value = match.group("json")
11341118
status = match.group("status")
1135-
label = match.groupdict().get("label")
1119+
label = match.group("label")
11361120
error = "__codexLinuxErr"
1137-
error_message = (
1138-
f'Browser Use cannot determine if ${{{url}.displayUrl}} is allowed. Please try again later or use another source.'
1139-
if label is None
1140-
else f'${{{label}}} cannot determine if ${{{url}.displayUrl}} is allowed. Please try again later or use another source.'
1141-
)
1142-
args = url if label is None else f"{url},{label}"
1121+
error_message = f'${{{label}}} cannot determine if ${{{url}.displayUrl}} is allowed. Please try again later or use another source.'
11431122
replacement = (
1144-
f'async fetchBlocked({args}){{let {response};try{{{response}=await {fetch}({url}.endpoint,{{method:"GET"}})}}'
1123+
f'async fetchBlocked({url},{label}){{let {response};try{{{response}=await {fetch}({url}.endpoint,{{method:"GET"}})}}'
11451124
f'catch({error}){{if(String({url}?.endpoint??"").includes("/aura/site_status")&&'
1146-
f'String({error}?.message??{error}).toLowerCase().includes("allowlist"))return console.warn'
1147-
f'("codexLinuxSiteStatusAllowlistFallback",{url}.endpoint),!1;throw {error}}}'
1125+
f'String({error}?.message??{error}).toLowerCase().includes("allowlist"))'
1126+
f'return!1/*codexLinuxSiteStatusAllowlistFallback*/;throw {error}}}'
11481127
f'if(!{response}.ok)throw new Error({formatter}(`{error_message}`));'
11491128
f'let {json_value}=await {response}.json();return {status}({json_value})}}'
11501129
)

tests/scripts_smoke.sh

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ JSON
163163
{"name":"browser","version":"0.1.0-alpha2","interface":{"category":"Engineering"}}
164164
JSON
165165
cat > "$resources_dir/plugins/openai-bundled/plugins/browser/scripts/browser-client.mjs" <<'JS'
166-
function lu(e){let t=globalThis.nodeRepl?.env[e];return typeof t=="string"?t:void 0}function th(){let e=import.meta.__codexNativePipe;return e==null||typeof e.createConnection!="function"?null:e}var I2=new Set(["about:blank"]);function Gb(e){if(I2.has(e))return!0;let t;try{t=new URL(e)}catch{return!1}return t.protocol==="http:"||t.protocol==="https:"}class Uf{async fetchBlocked(e){let r=await bS(e.endpoint,{method:"GET"});if(!r.ok)throw new Error(ae(`Browser Use cannot determine if ${e.displayUrl} is allowed. Please try again later or use another source.`));let n=await r.json();return TF(n)}}var Cb=kE(hV.platform()),EV=()=>_P()==="win32"?TV():CV(),CV=async()=>(await yP(Cb)).map(e=>wP.resolve(Cb,e)),TV=async()=>[];export function setupAtlasRuntime() {}
166+
function lu(e){let t=globalThis.nodeRepl?.env[e];return typeof t=="string"?t:void 0}function th(){let e=import.meta.__codexNativePipe;return e==null||typeof e.createConnection!="function"?null:e}var I2=new Set(["about:blank"]);function Gb(e){if(I2.has(e))return!0;let t;try{t=new URL(e)}catch{return!1}return t.protocol==="http:"||t.protocol==="https:"}class Uf{async fetchBlocked(e,t){let r=await bS(e.endpoint,{method:"GET"});if(!r.ok)throw new Error(ae(`${t} cannot determine if ${e.displayUrl} is allowed. Please try again later or use another source.`));let n=await r.json();return TF(n)}}var Cb=kE(hV.platform()),EV=()=>_P()==="win32"?TV():CV(),CV=async()=>(await yP(Cb)).map(e=>wP.resolve(Cb,e)),TV=async()=>[];export function setupAtlasRuntime() {}
167167
JS
168168
}
169169

@@ -7144,6 +7144,120 @@ for (const [key, value] of Object.entries(expected)) {
71447144
NODE
71457145
}
71467146

7147+
test_browser_use_site_status_allowlist_fallback_patch_behavior() {
7148+
info "Checking Browser Use site_status allowlist fallback patch behavior"
7149+
local workspace="$TMP_DIR/browser-site-status-allowlist-fallback"
7150+
local client="$workspace/browser-client.mjs"
7151+
local first_patch="$workspace/browser-client.first-patch.mjs"
7152+
local output_log="$workspace/output.log"
7153+
7154+
mkdir -p "$workspace"
7155+
cat > "$client" <<'JS'
7156+
var fetchImpl;function F(e,t){return fetchImpl(e,t)}function G(e){return e}function H(e){return e.blocked===!0}var policy={async fetchBlocked(e,t){let s=await F(e.endpoint,{method:"GET"});if(!s.ok)throw new Error(G(`${t} cannot determine if ${e.displayUrl} is allowed. Please try again later or use another source.`));let n=await s.json();return H(n)}};
7157+
JS
7158+
7159+
(
7160+
warn() { echo "[WARN] $*" >&2; }
7161+
info() { echo "[INFO] $*" >&2; }
7162+
# shellcheck disable=SC1091
7163+
source "$REPO_DIR/scripts/lib/bundled-plugins.sh"
7164+
patch_browser_use_site_status_allowlist_fallback "$client"
7165+
cp "$client" "$first_patch"
7166+
patch_browser_use_site_status_allowlist_fallback "$client"
7167+
) >"$output_log" 2>&1
7168+
7169+
cmp -s "$first_patch" "$client" || fail "Expected Browser Use site_status fallback patch to be byte-identical on second application"
7170+
assert_occurrence_count "$client" "codexLinuxSiteStatusAllowlistFallback" 1
7171+
assert_not_contains "$client" "console.warn"
7172+
assert_not_contains "$output_log" "Could not find Browser Use site_status allowlist fallback insertion point"
7173+
7174+
node - "$client" <<'NODE'
7175+
const assert = require("node:assert/strict");
7176+
const fs = require("node:fs");
7177+
const vm = require("node:vm");
7178+
7179+
const client = process.argv[2];
7180+
const source = fs.readFileSync(client, "utf8");
7181+
const warnings = [];
7182+
const context = {
7183+
console: {
7184+
warn(...args) {
7185+
warnings.push(args);
7186+
},
7187+
},
7188+
};
7189+
vm.createContext(context);
7190+
vm.runInContext(source, context);
7191+
7192+
const matchingUrl = {
7193+
endpoint: "http://127.0.0.1/aura/site_status?url=https%3A%2F%2Fexample.com",
7194+
displayUrl: "https://example.com/",
7195+
};
7196+
const otherUrl = {
7197+
endpoint: "http://127.0.0.1/aura/other",
7198+
displayUrl: "https://example.com/",
7199+
};
7200+
7201+
(async () => {
7202+
const allowlistError = new Error("native ALLOWLIST is unavailable");
7203+
context.fetchImpl = async () => {
7204+
throw allowlistError;
7205+
};
7206+
assert.strictEqual(await context.policy.fetchBlocked(matchingUrl, "Chrome"), false);
7207+
7208+
await assert.rejects(
7209+
context.policy.fetchBlocked(otherUrl, "Chrome"),
7210+
(error) => error === allowlistError,
7211+
);
7212+
7213+
const otherError = new Error("native policy is unavailable");
7214+
context.fetchImpl = async () => {
7215+
throw otherError;
7216+
};
7217+
await assert.rejects(
7218+
context.policy.fetchBlocked(matchingUrl, "Chrome"),
7219+
(error) => error === otherError,
7220+
);
7221+
7222+
context.fetchImpl = async () => ({ ok: false });
7223+
await assert.rejects(
7224+
context.policy.fetchBlocked(matchingUrl, "Chrome"),
7225+
(error) => error.message === "Chrome cannot determine if https://example.com/ is allowed. Please try again later or use another source.",
7226+
);
7227+
7228+
const jsonError = new Error("invalid site_status JSON");
7229+
context.fetchImpl = async () => ({
7230+
ok: true,
7231+
json: async () => {
7232+
throw jsonError;
7233+
},
7234+
});
7235+
await assert.rejects(
7236+
context.policy.fetchBlocked(matchingUrl, "Chrome"),
7237+
(error) => error === jsonError,
7238+
);
7239+
7240+
let fetchedEndpoint;
7241+
let fetchedMethod;
7242+
context.fetchImpl = async (endpoint, options) => {
7243+
fetchedEndpoint = endpoint;
7244+
fetchedMethod = options.method;
7245+
return {
7246+
ok: true,
7247+
json: async () => ({ blocked: true }),
7248+
};
7249+
};
7250+
assert.strictEqual(await context.policy.fetchBlocked(matchingUrl, "Chrome"), true);
7251+
assert.strictEqual(fetchedEndpoint, matchingUrl.endpoint);
7252+
assert.strictEqual(fetchedMethod, "GET");
7253+
assert.strictEqual(warnings.length, 0);
7254+
})().catch((error) => {
7255+
console.error(error);
7256+
process.exitCode = 1;
7257+
});
7258+
NODE
7259+
}
7260+
71477261
test_browser_plugin_renamed_upstream_staging() {
71487262
info "Checking Browser plugin staging from renamed upstream resources"
71497263
local workspace="$TMP_DIR/browser-plugin-renamed"
@@ -7834,7 +7948,7 @@ var Cb=kE(hV.platform()),EV=()=>_P()==="win32"?TV():CV(),CV=async()=>(await yP(C
78347948
function lu(e){let t=globalThis.nodeRepl?.env[e];return typeof t=="string"?t:void 0}
78357949
function Me(){let e=globalThis.nodeRepl;return e?.config==null?void 0:e}
78367950
import{platform as yT}from"node:os";function eh(){return"privileged native pipe bridge is not available; browser-client is not trusted"}function th(){let e=globalThis.nodeRepl?.nativePipe;return e==null||typeof e.createConnection!="function"?null:e}var ml=class e{constructor(t){this.socket=t}static async create(t){let r=th();if(r!=null){let n=await r.createConnection(t);return new e(n)}throw new Error(eh())}};
7837-
async fetchBlocked(e){let r=await bS(e.endpoint,{method:"GET"});if(!r.ok)throw new Error(ae(`Browser Use cannot determine if ${e.displayUrl} is allowed. Please try again later or use another source.`));let n=await r.json();return TF(n)}
7951+
async fetchBlocked(e,t){let r=await bS(e.endpoint,{method:"GET"});if(!r.ok)throw new Error(ae(`${t} cannot determine if ${e.displayUrl} is allowed. Please try again later or use another source.`));let n=await r.json();return TF(n)}
78387952
JS
78397953
cat > "$chrome_dir/scripts/check-native-host-manifest.js" <<'JS'
78407954
#!/usr/bin/env node
@@ -10254,6 +10368,7 @@ main() {
1025410368
test_bundled_plugin_system_computer_use_preserves_cosmic_helper_name
1025510369
test_browser_use_node_repl_fallback_runtime
1025610370
test_browser_use_file_url_policy_patch_behavior
10371+
test_browser_use_site_status_allowlist_fallback_patch_behavior
1025710372
test_browser_plugin_renamed_upstream_staging
1025810373
test_upstream_bundled_skills_staging
1025910374
test_upstream_bundled_skills_validator_guards

0 commit comments

Comments
 (0)