Skip to content

Commit fa9b486

Browse files
committed
Remove blanket password restrictions from browser workflows
1 parent 34c57b9 commit fa9b486

5 files changed

Lines changed: 46 additions & 20 deletions

File tree

‎crates/jcode-app-core/src/tool/browser.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn browser_tool_description_text() -> &'static str {
2525
if browser_handoff_disabled() {
2626
return "Control the browser using direct actions. Check action='status' first; run setup only if not ready. Browser handoff is disabled for this process. Complete browser tasks with direct actions in the requested tab.";
2727
}
28-
"Control the browser. Check action='status' first; run setup only if not ready. Use action='handoff' by default for browser tasks with goal, tab_id, and optional trusted context. Jev handles the entire task until complete or genuinely blocked; navigation alone is not completion. Direct actions are for setup, tab discovery/creation, or blocked handoffs. list_tabs includes signed-in tabs across windows. On requested_help=script/text, supply exact executable script candidates or exact text_values and resume. On requested_help=user_login, ask the user to sign in/finish 2FA in that tab, wait, then resume the handoff."
28+
"Control the browser. Check action='status' first; run setup only if not ready. Use action='handoff' by default for browser tasks with goal, tab_id, and optional trusted context. Jev handles the entire task until complete or genuinely blocked; navigation alone is not completion. Direct actions are for setup, tab discovery/creation, or blocked handoffs. list_tabs includes signed-in tabs across windows. On requested_help=script/text, supply exact executable script candidates or exact text_values and resume. On requested_help=user_login, ask the user to complete the CAPTCHA in that tab, wait, then resume the handoff."
2929
}
3030

3131
/// Opt-in process-local control for direct-only benchmark arms. Normal sessions
@@ -268,7 +268,7 @@ impl Tool for BrowserTool {
268268
),
269269
(
270270
"text_values",
271-
json!({"type":"array", "maxItems":16, "items":{"type":"string", "maxLength":2000}, "description":"Exact non-sensitive text to type. Never passwords, OTPs, or payment credentials."}),
271+
json!({"type":"array", "maxItems":16, "items":{"type":"string", "maxLength":2000}, "description":"Exact text to type. Never payment credentials."}),
272272
),
273273
(
274274
"candidates",

‎crates/jcode-app-core/src/tool/browser_fast.rs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ fn parse_observation(output: ToolOutput) -> Result<Value> {
401401
);
402402
if redact_credentials(&mut page) {
403403
page["sensitive"] = json!(true);
404+
page["credentials_redacted"] = json!(true);
404405
}
405406
Ok(page)
406407
}
@@ -641,12 +642,14 @@ pub(super) async fn run(
641642
// than aborting the whole task or reusing them on another page.
642643
used_exact.extend(0..input.candidates.len());
643644
}
645+
if observation["credentials_redacted"]==true {
646+
requested_help=Some("direct_actions");
647+
return Ok(("hand_back","Page credentials were redacted before reaching the browser decision service. Continue with direct browser actions using the same tab_id.".into()));
648+
}
644649
if observation["sensitive"]==true {
645-
// Login, 2FA and CAPTCHA screens are the user's to complete in
646-
// their own browser. Say so explicitly so the main agent asks the
647-
// user, waits, and re-runs the same handoff on the same tab.
650+
// CAPTCHA challenges need the user in the same browser tab.
648651
requested_help=Some("user_login");
649-
return Ok(("hand_back","The page needs the user: sign-in, one-time code, CAPTCHA, or account recovery. Ask the user to complete it in this browser tab (their saved session and password manager apply), wait for them to confirm, then re-run this same handoff with the same tab_id to continue. Never type credentials. Never reset passwords.".into()));
652+
return Ok(("hand_back","The page needs the user to complete a CAPTCHA. Ask the user to complete it in this browser tab, wait for them to confirm, then re-run this same handoff with the same tab_id to continue.".into()));
650653
}
651654
if stale>=3 {return Ok(("hand_back","Browser stalled: repeated unchanged observations".into()));}
652655
if trace.len()==budget {return Ok(("hand_back","Action step budget exhausted; final action has been observed".into()));}

‎crates/jcode-app-core/src/tool/browser_fast_actions.rs‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(super) const OBSERVE_SCRIPT: &str = r#"return (() => {
5151
const aria=clip(e.getAttribute('aria-label')),name=clip(e.getAttribute('name')),placeholder=clip(e.getAttribute('placeholder'));
5252
const autocomplete=clip(e.getAttribute('autocomplete'),80);
5353
const text=e.matches(excluded)?'':visibleText(e,180);
54-
if(type==='password'||/one-time-code/i.test(autocomplete)||/captcha|\botp\b|verification code|security code|reset password/i.test(aria+' '+name+' '+text+' '+e.getAttribute('src')))sensitive=true;
54+
if(/captcha/i.test(aria+' '+name+' '+text+' '+e.getAttribute('src')))sensitive=true;
5555
if(elements.length>=64)continue;
5656
const css=selector(e);if(css.length>1000||!unique(css))continue;
5757
if(!identity.nodes.has(e))identity.nodes.set(e,identity.next++);
@@ -67,7 +67,7 @@ pub(super) const OBSERVE_SCRIPT: &str = r#"return (() => {
6767
elements.push({identity:identity.nodes.get(e),selector:css,tag:e.localName,type,role,text,aria,name,placeholder,autocomplete,search,form_action:form?clip(form.action,500):'',href:e.localName==='a'?clip(e.href,1000):'',target:clip(e.getAttribute('target')||baseTarget,40),disabled:!!e.disabled||e.getAttribute('aria-disabled')==='true',form:!!form,options:e.localName==='select'?Array.from(e.options).filter(o=>o.value.length<=200).slice(0,16).map(o=>({text:clip(o.text),value:o.value,disabled:o.disabled})):[]});
6868
}
6969
const body=visibleText(main||document.body||document.documentElement,6000);
70-
if(/captcha|one.time (password|code)|verification code|reset (your )?password/i.test(body))sensitive=true;
70+
if(/captcha/i.test(body))sensitive=true;
7171
const root=document.scrollingElement||document.documentElement;
7272
const scrollState=e=>({can_up:e.scrollTop>0,can_down:e.scrollTop+e.clientHeight<e.scrollHeight-1,can_left:e.scrollLeft>0,can_right:e.scrollLeft+e.clientWidth<e.scrollWidth-1});
7373
const scroll_containers=[];scanned=0;
@@ -129,12 +129,7 @@ pub(super) fn risky(text: &str) -> bool {
129129
"sign",
130130
"log out",
131131
"logout",
132-
"reset",
133-
"password",
134-
"otp",
135132
"captcha",
136-
"verification",
137-
"security code",
138133
"credit",
139134
"card",
140135
"bank",
@@ -261,7 +256,7 @@ pub(super) fn candidates(input: &BrowserInput, observation: &Value) -> Result<Ve
261256
)?;
262257
}
263258
if matches!(tag, "input" | "textarea")
264-
&& matches!(kind, "" | "text" | "search" | "email" | "url")
259+
&& matches!(kind, "" | "text" | "search" | "email" | "url" | "password")
265260
{
266261
for (index, text) in input.text_values.iter().enumerate() {
267262
add(

‎crates/jcode-app-core/src/tool/browser_fast_live_tests.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ async fn live_browser_handoff_completes_search_and_nested_navigation() {
203203
}
204204

205205
#[tokio::test]
206-
#[ignore = "requires Jcode subscription or Jev BYOK credentials, an existing BROWSER_SESSION, and a disposable local fixture with visible password/verification controls"]
206+
#[ignore = "requires Jcode subscription or Jev BYOK credentials, an existing BROWSER_SESSION, and a disposable local fixture with a visible CAPTCHA"]
207207
async fn live_browser_handoff_sensitive_fixture_hands_back_without_actions() {
208208
let ctx = fixture_context();
209209
let tab_id = local_fixture_tab("JCODE_BROWSER_HANDOFF_TEST_BLOCKED_TAB_ID", &ctx).await;
210210
let result = handoff(
211211
tab_id,
212-
"Continue to the Browser controls documentation. Hand back if blocked by sensitive authentication or verification. Never reset a password.",
212+
"Continue to the Browser controls documentation. Hand back if blocked by a CAPTCHA.",
213213
ctx,
214214
)
215215
.await;

‎crates/jcode-app-core/src/tool/browser_fast_tests.rs‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::browser_fast_actions::risky;
12
use super::*;
23
use std::collections::VecDeque;
34
use std::sync::Mutex;
@@ -223,9 +224,9 @@ async fn sensitive_pages_never_reach_transport() {
223224
result["reason"]
224225
.as_str()
225226
.unwrap()
226-
.contains("Never reset passwords")
227+
.contains("complete a CAPTCHA")
227228
);
228-
// #1743: the main agent must know to ask the user to sign in and resume.
229+
// The main agent must know to ask the user to complete the challenge and resume.
229230
assert_eq!(result["requested_help"], "user_login");
230231
assert!(result["reason"].as_str().unwrap().contains("same tab_id"));
231232
assert!(transport.observed.lock().unwrap().is_empty());
@@ -456,14 +457,40 @@ fn auto_candidates_filter_risky_controls_and_use_only_supplied_text() {
456457
assert!(
457458
!options
458459
.iter()
459-
.any(|c| matches!(c.input.selector.as_deref(), Some("#bad" | "#send" | "#pw")))
460+
.any(|c| matches!(c.input.selector.as_deref(), Some("#bad" | "#send")))
460461
);
461-
let typing = options.iter().find(|c| c.input.action == "type").unwrap();
462+
let typing = options
463+
.iter()
464+
.find(|c| c.input.action == "type" && c.input.selector.as_deref() == Some("#q"))
465+
.unwrap();
466+
let password = options
467+
.iter()
468+
.find(|c| c.input.action == "type" && c.input.selector.as_deref() == Some("#pw"))
469+
.unwrap();
470+
assert_eq!(password.input.text.as_deref(), Some("trusted query"));
471+
assert_eq!(password.input.submit, Some(false));
462472
assert_eq!(typing.input.text.as_deref(), Some("trusted query"));
463473
assert_eq!(typing.input.submit, Some(false));
464474
let select = options.iter().find(|c| c.input.action == "select").unwrap();
465475
assert_eq!(select.input.text.as_deref(), Some("en"));
466476
}
477+
#[test]
478+
fn password_workflows_are_not_blanket_blocked() {
479+
for label in [
480+
"Reset password",
481+
"Password",
482+
"OTP",
483+
"Verification code",
484+
"Security code",
485+
] {
486+
assert!(!risky(label), "{label}");
487+
}
488+
assert!(risky("CAPTCHA"));
489+
assert!(risky("Pay now"));
490+
assert!(!OBSERVE_SCRIPT.contains("type==='password'"));
491+
assert!(OBSERVE_SCRIPT.contains("if(/captcha/i.test(body))sensitive=true;"));
492+
}
493+
467494
#[test]
468495
fn candidates_are_capped_below_model_limit() {
469496
let mut input = input();
@@ -631,6 +658,7 @@ async fn credentials_in_page_never_reach_transport_or_parent() {
631658
assert_eq!(value["status"], "hand_back");
632659
assert!(!value.to_string().contains(secret));
633660
assert!(value["final_observation"]["sensitive"] == true);
661+
assert_eq!(value["requested_help"], "direct_actions");
634662
assert!(transport.observed.lock().unwrap().is_empty());
635663
}
636664
}

0 commit comments

Comments
 (0)