Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
abad952
test(agent): cover browser offsite navigation not ending the turn
senamakel Nov 15, 2026
f7c37e6
feat(browser): add is_public_https URL guard
senamakel Nov 15, 2026
8eb5d75
fix(browser): treat offsite redirects as recoverable results
senamakel Nov 15, 2026
64ed925
Merge remote-tracking branch 'origin/main' into task-offsite-links
senamakel Nov 15, 2026
2fb0c9d
feat(browser): add browser_never_open module
senamakel Nov 15, 2026
16106c5
test(browser): add regression tests for never-open browser mode
senamakel Nov 15, 2026
53c5b31
feat(browser): enforce never-open list before allow-all
senamakel Nov 15, 2026
234454d
fix(browser): report normalized offsite url and drop open instruction
senamakel Nov 15, 2026
0fad44d
test(browser): drop redundant offsite url assertion
senamakel Nov 15, 2026
0dfc126
style(browser): reformat never-open and offsite code with rustfmt
senamakel Nov 15, 2026
8fea04a
feat(browser): refuse never-open hosts on every navigation, fail closed
senamakel Nov 15, 2026
ceae656
feat(browser): enforce never-open list on browser dials
senamakel Nov 15, 2026
3019ca5
test(browser): cover unicode hosts, trailing dots and unreadable lists
senamakel Nov 15, 2026
666d0b9
fix(browser): enforce never-open list on every browser dial
senamakel Nov 15, 2026
63efbdb
style(browser_never_open): wrap long lines to satisfy rustfmt
senamakel Nov 15, 2026
ece8cfa
fix(browser): enforce the never-open list on every browser dial
senamakel Nov 15, 2026
7fa11d5
chore(browser): reorder module declarations alphabetically
senamakel Nov 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ OPENHUMAN_TEMPERATURE=0.7
# ---------------------------------------------------------------------------
# [optional] Default: 0
OPENHUMAN_BROWSER_ALLOW_ALL=0
# [optional] A file of hosts the browser never opens, one per line (`#`
# comments; a host covers its subdomains). Unset, nothing is denied. Set but
# unreadable, the browser opens no page at all. Checked on every connection
# the browser makes (clicks and redirects included), whatever
# OPENHUMAN_BROWSER_ALLOW_ALL says.
# OPENHUMAN_BROWSER_DENY_FILE=
# [optional] Trace TinyComputer runs, as `[computer] trace = true` does: every
# browser task records its decisions and keeps its full report, and desktop
# commands are traced, under <workspace>/state/computer/. Reports hold page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ pub(super) fn recovery_policy_with_effect(
Some((class, budget))
}

/// Whether `error` is the browser's report of a page an action led to and
/// the session left (`the page reached, <url>, is not permitted ...; the
/// session left it`).
fn is_browser_left_page(error: &str) -> bool {
let text = error.trim_start();
let text = text
.strip_prefix("BlockedByPolicy:")
.unwrap_or(text)
.trim_start();
text.starts_with("the page reached, ")
&& text.contains("is not permitted by this session's allowed origins; the session left it")
}

/// Tools that reach a service on the user's behalf: an external connector,
/// the hosted backend, or the memory store. Work can go on without them.
pub(super) fn is_optional_service(tool: &str) -> bool {
Expand Down Expand Up @@ -188,6 +201,17 @@ pub(super) fn classified_recovery_policy(
if let Some(policy) = fetched_site_policy(tool, error) {
return policy;
}
// A browser action that ran and took the session to a page on another
// site, which the session then left (TinyComputer's `LeftRefusedPage`).
// The keyword classifier reads its "is not permitted" as a missing
// permission, a zero-retry class: one click on a link to another site
// ended nine operator runs in a row before the agent could report. The
// tool answers it as a result naming the page now; should the text still
// arrive as a failure, it is a refusal the agent can work around (open
// the page itself, or carry on), not a reason to end the run.
if tool == "browser" && is_browser_left_page(error) {
return Some(("blocked_by_policy", 2));
}
// A tool-owned JSON error contract is less ambiguous than rendered prose;
// the harness reads only its explicit status/code fields.
if let Some(decision) = json_error_recovery(error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,18 @@ async fn a_failed_browser_task_nudges_toward_its_hint_then_stops_on_a_repeat() {
let summary = slot.lock().unwrap().clone().unwrap();
assert!(summary.contains("task_failed"), "{summary}");
}

/// What the browser tool said when a click on Hacker News took the session
/// to another site (production, 2026-11-15): TinyComputer left the page,
/// the call itself ran. Read as a missing permission (budget 0), it ended
/// nine operator runs in a row before the agent could report.
const BROWSER_LEFT_PAGE: &str = "BlockedByPolicy: the page reached, \
https://www.spacex.com/launches/starship-flight-15, is not permitted by this session's \
allowed origins; the session left it";

#[test]
fn a_browser_page_left_for_another_site_does_not_end_the_turn() {
let policy = recovery_policy("browser", BROWSER_LEFT_PAGE, false).expect("classified");
assert_eq!(policy.0, "blocked_by_policy");
assert!(policy.1 >= 1, "{policy:?}");
}
24 changes: 24 additions & 0 deletions crates/openhuman-core/src/modules/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use tinycomputer_bus::DesktopResponse;

use crate::config::Config;

#[path = "browser_never_open.rs"]
pub(crate) mod never_open;
#[path = "browser_output.rs"]
mod output;
use output::{append_output_chunk, check_output_size, finish_output, ReleaseOnDrop};
Expand Down Expand Up @@ -480,6 +482,11 @@ impl BrowserClient {
"local/private host '{host}' is blocked"
)));
}
// The operator's never-open list holds whatever allow-all says; a
// list that cannot be read refuses every page (fails closed).
if let Some(reason) = never_open::refusal(url.as_str()) {
return Err(BrowserCallError::Policy(reason));
}
if !allow_all
&& !self.allows_any_site()
&& !self.browser_domains().iter().any(|allowed| {
Expand Down Expand Up @@ -667,6 +674,23 @@ fn browser_allow_all() -> bool {
)
}

/// Whether `raw` is an https URL on a public host (no userinfo, no private
/// or local address): what the browser may be asked to open at all.
pub(crate) fn is_public_https(raw: &str) -> bool {
let Ok(url) = url::Url::parse(raw) else {
return false;
};
if url.scheme() != "https" || !url.username().is_empty() || url.password().is_some() {
return false;
}
match url.host() {
Some(url::Host::Ipv4(ip)) => !private_or_local(&ip.to_string()),
Some(url::Host::Ipv6(ip)) => !private_or_local(&ip.to_string()),
Some(url::Host::Domain(host)) => !private_or_local(host),
None => false,
}
}

fn private_or_local(host: &str) -> bool {
let host = host.trim_end_matches('.').to_ascii_lowercase();
if host == "localhost" || host.ends_with(".localhost") || host.ends_with(".local") {
Expand Down
7 changes: 7 additions & 0 deletions crates/openhuman-core/src/modules/browser_egress_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ impl BrowserEgressHost {
if !is_alias(&target.policy_id, target.expected_generation) {
return Err(refused());
}
// The operator's never-open list holds for every connection the
// browser makes: a click, a redirect or a task's own navigation all
// dial here before the request is sent. Refused hosts get no grant.
if let Some(reason) = super::browser::never_open::dial_refusal(&target.hostname) {
tracing::info!(%reason, "[computer] browser dial refused by the never-open list");
return Err(refused());
}
let config = crate::core::runtime::DispatchCtx::ambient()
.load_config()
.await
Expand Down
103 changes: 103 additions & 0 deletions crates/openhuman-core/src/modules/browser_never_open.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//! The sites the browser never opens, read from the file the host names in
//! `OPENHUMAN_BROWSER_DENY_FILE` (Teeny's bin/spine points it at
//! `deploy/browser-deny.txt`). One host per line; `#` starts a comment; a
//! host covers itself and every subdomain of it. Unset, nothing is denied.
//! Set but unreadable, every page is refused: the list fails closed.
//!
//! Two places consult it. `check_url` refuses a navigation the core starts
//! (`open`, `task`, the `browser_open` tool). `BrowserEgressHost::authorize`
//! refuses every connection the browser itself makes, which is where a click
//! or a redirect to a listed host is stopped before its request is sent. A
//! page the browser has already left is not shown, but it is never fetched
//! by a dial the list refuses.

use std::ffi::OsStr;
use std::fs;

/// The environment variable that names the never-open file.
pub(crate) const DENY_FILE_ENV: &str = "OPENHUMAN_BROWSER_DENY_FILE";

/// Why `url` may not be opened under the never-open list the environment
/// names, or None when the browser may open it.
pub(crate) fn refusal(url: &str) -> Option<String> {
refusal_for(std::env::var_os(DENY_FILE_ENV).as_deref(), url)
}

/// Why a connection to `hostname` is refused under the environment's list, or
/// None when it may be made.
pub(crate) fn dial_refusal(hostname: &str) -> Option<String> {
dial_refusal_for(std::env::var_os(DENY_FILE_ENV).as_deref(), hostname)
}

/// `refusal` for a given file (None: no list is set).
fn refusal_for(file: Option<&OsStr>, url: &str) -> Option<String> {
let file = file?;
match load(file) {
Ok(list) => check(url, &list),
Err(reason) => Some(reason),
}
}

/// `dial_refusal` for a given file (None: no list is set).
fn dial_refusal_for(file: Option<&OsStr>, hostname: &str) -> Option<String> {
let file = file?;
match load(file) {
Ok(list) => check_host(hostname, &list),
Err(reason) => Some(reason),
}
}

fn load(file: &OsStr) -> Result<Vec<String>, String> {
match fs::read_to_string(file) {
Ok(text) => Ok(parse(&text)),
Err(error) => Err(format!(
"the never-open list at {} could not be read ({error}), so no page is opened",
file.to_string_lossy()
)),
}
}

/// The canonical form of a host, the way the URL parser writes it: IDNA and
/// lower-case, without a trailing dot. None when it is not a host.
fn canonical(host: &str) -> Option<String> {
url::Host::parse(host.trim().trim_end_matches('.'))
.ok()
.map(|parsed| parsed.to_string())
Comment on lines +63 to +65

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Strip trailing dots after IDNA normalization

If the deny file contains a hostname ending in an IDNA dot-equivalent, such as example.com。 (U+3002), this strips trailing dots before url::Host::parse converts that character into an ASCII dot. The list consequently stores example.com., while check_host() canonicalizes a normal URL or dial hostname to example.com. Neither the equality nor the subdomain comparison matches, so the deny entry fails to block the site at either enforcement point. Strip trailing dots from the parsed, IDNA-normalized hostname instead.

Useful? React with 👍 / 👎.

}

/// The hosts listed in `text`, canonical, without comments or blank lines.
/// Entries that are not hosts are dropped, never matched.
pub(crate) fn parse(text: &str) -> Vec<String> {
text.lines()
.map(|line| line.split('#').next().unwrap_or("").trim())
.filter(|line| !line.is_empty())
.filter_map(canonical)
.collect()
}

/// Why `url` is denied by `list`, when it is: its host is an entry or under one.
pub(crate) fn check(url: &str, list: &[String]) -> Option<String> {
let host = url::Url::parse(url)
.ok()
.and_then(|parsed| parsed.host_str().map(str::to_owned));
match host {
Some(host) => check_host(&host, list),
None => Some(format!("'{url}' has no host the never-open list can check")),
}
}

/// Why `hostname` is denied by `list`, when it is.
pub(crate) fn check_host(hostname: &str, list: &[String]) -> Option<String> {
let Some(host) = canonical(hostname) else {
return Some(format!(
"'{hostname}' is not a host the never-open list can check"
));
};
list.iter()
.find(|denied| host == **denied || host.ends_with(&format!(".{denied}")))
.map(|denied| format!("host '{host}' is on the never-open list (entry '{denied}')"))
}

#[cfg(test)]
#[path = "browser_never_open_tests.rs"]
mod tests;
93 changes: 93 additions & 0 deletions crates/openhuman-core/src/modules/browser_never_open_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use super::*;

fn list(text: &str) -> Vec<String> {
parse(text)
}

#[test]
fn a_listed_host_and_its_subdomains_are_denied_but_not_a_lookalike() {
let deny = list("x.com\n");
assert!(check("https://x.com/home", &deny).is_some());
assert!(check("https://mobile.x.com/post/1", &deny).is_some());
assert!(check("https://X.COM./", &deny).is_some());
// A host that merely ends in the same letters is another site.
assert_eq!(check("https://notx.com/", &deny), None);
assert_eq!(check("https://example.com/x.com", &deny), None);
}

#[test]
fn comments_blank_lines_and_case_in_the_file_are_ignored() {
let deny = parse("# X and its kin\n\n X.com # the account keys\nMail.Google.com\n");
assert_eq!(
deny,
vec!["x.com".to_string(), "mail.google.com".to_string()]
);
assert!(check("https://mail.google.com/mail", &deny).is_some());
}

#[test]
fn an_unparseable_url_is_refused_when_a_list_is_set() {
assert!(check("not a url", &list("x.com\n")).is_some());
}

#[test]
fn no_list_set_denies_nothing() {
assert_eq!(refusal_for(None, "https://x.com/"), None);
}

#[test]
fn a_list_that_cannot_be_read_refuses_every_page() {
let missing = std::env::temp_dir().join("openhuman-never-open-does-not-exist.txt");
let reason =
refusal_for(Some(missing.as_os_str()), "https://example.com/").expect("fails closed");
assert!(reason.contains("could not be read"), "{reason}");
}

#[test]
fn the_file_named_by_the_environment_is_the_list() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("browser-deny.txt");
std::fs::write(&file, "never-open.example\n").unwrap();
assert!(refusal_for(Some(file.as_os_str()), "https://www.never-open.example/a").is_some());
assert_eq!(
refusal_for(Some(file.as_os_str()), "https://example.com/"),
None
);
}

#[test]
fn a_unicode_entry_matches_its_punycode_host_and_subdomains() {
let deny = list("bücher.example\n");
assert_eq!(deny, vec!["xn--bcher-kva.example".to_string()]);
assert!(check("https://xn--bcher-kva.example/", &deny).is_some());
assert!(check("https://www.bücher.example/", &deny).is_some());
}

#[test]
fn a_dial_is_refused_for_a_listed_host_with_a_trailing_dot_or_case() {
let deny = list("x.com\n");
assert!(check_host("X.com.", &deny).is_some());
assert!(check_host("edge.x.com", &deny).is_some());
assert_eq!(check_host("example.com", &deny), None);
}

#[test]
fn a_dial_with_a_list_that_cannot_be_read_is_refused() {
let missing = std::env::temp_dir().join("openhuman-never-open-missing-dial.txt");
assert!(dial_refusal_for(Some(missing.as_os_str()), "example.com")
.expect("fails closed")
.contains("could not be read"));
assert_eq!(dial_refusal_for(None, "x.com"), None);
}

#[test]
fn an_empty_list_refuses_no_dial_and_no_page() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("empty.txt");
std::fs::write(&file, "# nothing yet\n").unwrap();
assert_eq!(dial_refusal_for(Some(file.as_os_str()), "x.com"), None);
assert_eq!(
refusal_for(Some(file.as_os_str()), "https://example.com/path"),
None
);
}
23 changes: 21 additions & 2 deletions crates/openhuman-core/src/tools/impl/browser/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mod capture;
mod cleanup;
#[path = "browser_keychain.rs"]
mod keychain;
#[path = "browser_offsite.rs"]
mod offsite;
#[path = "browser_pending.rs"]
mod pending;
#[path = "browser_session_pool.rs"]
Expand Down Expand Up @@ -468,10 +470,18 @@ impl BrowserTool {
let id = self.session_for_url(starting_url).await?;
match verb {
"open" => {
let page = self
let page = match self
.client
.navigate(&id, NavigateRequest::new(required(args, "url")?))
.await?;
.await
{
Ok(page) => page,
// A redirect to another site: say where, never fail the turn.
Err(error) => match offsite::left_for(&error) {
Some(url) => return Ok(offsite::left_reply("open", &url)),
None => return Err(error.into()),
},
};
self.capture(&id, "open").await;
Ok(serde_json::to_value(page)?)
}
Expand Down Expand Up @@ -561,6 +571,15 @@ impl BrowserTool {
if secret.is_none() && done.is_ok() && capture::follows(&kind) {
self.capture(&id, &kind).await;
}
if let Err(error) = &done {
if let Some(url) = offsite::left_for(error) {
let reply = offsite::left_reply(&kind, &url);
return Ok(match &secret {
Some(secret) => keychain::redact_value(reply, secret),
None => reply,
});
}
}
match secret {
None => Ok(serde_json::to_value(done?)?),
Some(secret) => match done {
Expand Down
Loading
Loading