feat: enhance safety filters for shell commands by normalizing ANSI-C quoting

This commit is contained in:
asepharyana
2026-07-13 04:10:08 +07:00
parent a080957c26
commit d09e440e7e
14 changed files with 383 additions and 85 deletions
+12 -4
View File
@@ -202,10 +202,18 @@ impl LspClient {
break;
}
if let Some(len_str) = trimmed.strip_prefix("Content-Length: ") {
content_length = Some(
len_str.trim().parse::<usize>()
.map_err(|e| anyhow::anyhow!("invalid Content-Length '{}': {}", len_str.trim(), e))?,
);
let length: usize = len_str.trim().parse::<usize>()
.map_err(|e| anyhow::anyhow!("invalid Content-Length '{}': {}", len_str.trim(), e))?;
// Cap Content-Length at 64 MiB to prevent OOM from a
// malicious or misconfigured LSP server (CWE-400).
const MAX_CONTENT_LENGTH: usize = 64 * 1024 * 1024;
if length > MAX_CONTENT_LENGTH {
anyhow::bail!(
"Content-Length {} exceeds maximum allowed size of {} bytes",
length, MAX_CONTENT_LENGTH,
);
}
content_length = Some(length);
}
}