Skip to content

Commit 5bbff18

Browse files
authored
feat(git-host): AskPass 通道只许本账户连接,凭据用后清零(S13、S14) (#137)
- Unix 改用仅属主可进的目录 + 0600 套接字,两端都核对对端 uid; Windows 改用受保护 DACL 的命名管道,拒绝远程客户端,助手写入前核对属主 - 每个请求带 256 位会话令牌;格式、长度、超时、提示种类与次数都有上限, 被拒请求不进宿主,只记 vcs.authentication.request_rejected 的 reason - 令牌、请求帧和答案放在预分配、不扩容的缓冲区里,释放时清零 - 读写失败按类别集中过滤:助手已离开不记,其他错误和超时都记 response_failed - platform-tests 用真实助手进程在三平台验证应答、取消、错误令牌和会话失效; Windows 另验证管道属主和 DACL - rust-core-api.md 补充 AskPass 通道、上限和日志事件说明
1 parent 43e3f27 commit 5bbff18

17 files changed

Lines changed: 2086 additions & 324 deletions

File tree

‎rust/Cargo.lock‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rust/contracts/rust-core-api.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,23 @@ answer `"retry"` to repeat the failed transfer with helper bypass, at most three
12571257
total attempts. The AskPass C ABI is called only in the child app's early helper
12581258
mode. Credential answers are never copied into events or settings.
12591259

1260+
The helper reaches its invocation's session over a channel that only the same
1261+
account can open: on Unix, a socket (mode 0600) in a fresh owner-only directory,
1262+
with both ends also checking the peer's user ID; on Windows, a named pipe that
1263+
refuses remote clients, whose protected DACL admits only the current user, and
1264+
whose owner the helper verifies before writing. Each request also carries a
1265+
256-bit session token taken from the child's environment. Core drops a request
1266+
before any prompt reaches the host when it comes from another account, carries
1267+
another token, is malformed or longer than 16 KiB, asks a prompt longer than
1268+
8 KiB, does not arrive within 10 seconds of connecting, would be the session's
1269+
seventeenth distinct prompt, or repeats one prompt a fourth time. Each such
1270+
drop is logged as `vcs.authentication.request_rejected` with only its `reason`.
1271+
A session serves four helpers at a time; later ones wait to be accepted. A
1272+
prompt the host leaves unanswered for 180 seconds expires and its helper exits
1273+
with status 1, as after a cancel. Core zeroes the token, request frames and
1274+
answers when it drops them; copies outside Core, such as the child environment,
1275+
the host's JSON strings and operating system buffers, are not covered.
1276+
12601277
See `rust/fixtures/git/{fetch-plan,execution-events,execution-policy}-v1.json`
12611278
and [Git execution and project console](https://github.com/1lck/Lithe-IDEA/blob/main/.agents/notes/implemented/architecture/2026-09-12-git-execution-and-project-console.md).
12621279

‎rust/crates/core/src/runtime/helper_failures.rs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,33 @@ mod tests {
6060
fn helper_events_have_core_ownership_and_expected_channels() {
6161
install();
6262
install();
63-
let input = [
63+
let failure = [
6464
("stage", json!("test")),
6565
("error", json!("Helper operation failed")),
6666
("error_code", json!("PermissionDenied")),
6767
("error_domain", json!("io")),
6868
];
69+
// Rejections carry only their reason; every other helper event is a failure.
70+
let rejection = [("reason", json!("token"))];
6971
for (events, channel) in [
7072
(lithe_git_host::failure_log::EVENTS, "vcs/git"),
7173
(lithe_ide_host::failure_log::EVENTS, "app"),
7274
(lithe_remote::failure_log::EVENTS, "remote"),
7375
] {
7476
for id in events {
7577
assert_eq!(catalog::event_by_id(id).unwrap().owner, "lithe-core");
78+
let input: &[(&'static str, Value)] =
79+
if *id == "vcs.authentication.request_rejected" {
80+
&rejection
81+
} else {
82+
&failure
83+
};
7684
// Exercise the exact sink conversion/validation into an owned
7785
// queue, so parallel host drains cannot steal this assertion.
7886
let queue = RefCell::new(Vec::new());
7987
dispatch(
8088
id,
81-
&input,
89+
input,
8290
|event, map| {
8391
let prepared = core_events::prepare(event, map, None)?;
8492
queue.borrow_mut().push(prepared);

‎rust/crates/diagnostics/src/catalog_generated.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,18 @@ pub static EVENTS: &[EventMetadata] = &[
16161616
rate: 60,
16171617
owner: "Lithe",
16181618
},
1619+
EventMetadata {
1620+
id: "vcs.authentication.request_rejected",
1621+
channel: "vcs/git",
1622+
level: LogLevel::Warn,
1623+
message: "Git authentication request rejected",
1624+
fields: &[
1625+
FieldMetadata { name: "reason", field_type: FieldType::Token, required: true, description: "Why the AskPass channel refused a request: peer-identity (another account or unverifiable peer), token, malformed, oversized, timeout (no complete request before the deadline), prompt-limit or attempt-limit; never the prompt, token or peer input", reason: None },
1626+
],
1627+
span: None,
1628+
rate: 60,
1629+
owner: "lithe-core",
1630+
},
16191631
EventMetadata {
16201632
id: "vcs.authentication.response_failed",
16211633
channel: "vcs/git",

‎rust/crates/git-host/Cargo.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ description = "Native Git process adapter for Lithe hosts"
99
libc = "0.2"
1010

1111
[target.'cfg(windows)'.dependencies]
12-
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_System_Pipes", "Win32_System_JobObjects", "Win32_System_Diagnostics_ToolHelp", "Win32_System_Threading", "Win32_Security"] }
12+
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_System_Pipes", "Win32_System_JobObjects", "Win32_System_Diagnostics_ToolHelp", "Win32_System_Threading", "Win32_System_IO", "Win32_Security", "Win32_Security_Authorization", "Win32_Storage_FileSystem"] }
1313

1414
[dependencies]
1515
lithe-platform = { path = "../platform" }
1616
rand = "0.8"
1717
serde = { version = "1", features = ["derive"] }
1818
serde_json = "1"
19+
zeroize = "1.9"

0 commit comments

Comments
 (0)