mirror of
https://github.com/bitwarden/browser
synced 2026-02-03 10:13:31 +00:00
Ssh agent llm detector
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use sysinfo::{Pid, System};
|
||||
use tracing::info;
|
||||
|
||||
/// Peerinfo represents the information of a peer process connecting over a socket.
|
||||
/// This can be later extended to include more information (icon, app name) for the corresponding application.
|
||||
@@ -9,6 +10,7 @@ pub struct PeerInfo {
|
||||
pid: u32,
|
||||
process_name: String,
|
||||
peer_type: PeerType,
|
||||
is_llm_agent: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -25,15 +27,15 @@ impl PeerInfo {
|
||||
|
||||
fn from_pid(peer_pid: u32, peer_type: PeerType) -> Result<Self, ()> {
|
||||
let mut system = System::new();
|
||||
system.refresh_processes(
|
||||
sysinfo::ProcessesToUpdate::Some(&[Pid::from_u32(peer_pid)]),
|
||||
true,
|
||||
);
|
||||
system.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
|
||||
let is_llm_agent = ProcessTreeInfo::from_pid(&mut system, peer_pid).is_llm_agent;
|
||||
|
||||
if let Some(process) = system.process(Pid::from_u32(peer_pid)) {
|
||||
Ok(Self {
|
||||
pid: peer_pid,
|
||||
process_name: process.name().to_str().ok_or(())?.to_string(),
|
||||
peer_type,
|
||||
is_llm_agent,
|
||||
})
|
||||
} else {
|
||||
Err(())
|
||||
@@ -45,6 +47,7 @@ impl PeerInfo {
|
||||
pid: 0,
|
||||
process_name: "Unknown application".to_string(),
|
||||
peer_type: PeerType::UnixSocket,
|
||||
is_llm_agent: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +66,45 @@ impl Debug for PeerInfo {
|
||||
.field("pid", &self.pid)
|
||||
.field("process_name", &self.process_name)
|
||||
.field("peer_type", &self.peer_type)
|
||||
.field(
|
||||
"is_llm_agent",
|
||||
&ProcessTreeInfo::from_pid(&mut System::new(), self.pid).is_llm_agent,
|
||||
)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
const KNOWN_LLM_AGENT_NAMES: &[&str] = &["claude"];
|
||||
|
||||
struct ProcessTreeInfo {
|
||||
is_llm_agent: bool,
|
||||
}
|
||||
|
||||
impl ProcessTreeInfo {
|
||||
pub fn from_pid(system: &mut System, pid: u32) -> Self {
|
||||
let mut current_pid = Pid::from_u32(pid);
|
||||
let mut is_llm_agent = false;
|
||||
|
||||
loop {
|
||||
if let Some(process) = system.process(current_pid) {
|
||||
let process_name = process.exe();
|
||||
println!("Checking process: {:?}", process_name);
|
||||
println!("process {:?}", process);
|
||||
if KNOWN_LLM_AGENT_NAMES.contains(&"abcdefgh") {
|
||||
is_llm_agent = true;
|
||||
break;
|
||||
} else {
|
||||
if let Some(parent_pid) = process.parent() {
|
||||
current_pid = parent_pid;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Self { is_llm_agent }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ export const DefaultFeatureFlagValue = {
|
||||
/* Autofill */
|
||||
[FeatureFlag.MacOsNativeCredentialSync]: FALSE,
|
||||
[FeatureFlag.WindowsDesktopAutotype]: FALSE,
|
||||
[FeatureFlag.SshAgentV2]: FALSE,
|
||||
[FeatureFlag.SshAgentV2]: true,
|
||||
|
||||
/* Tools */
|
||||
[FeatureFlag.DesktopSendUIRefresh]: FALSE,
|
||||
|
||||
Reference in New Issue
Block a user