Read-only mirror of github.com/ondeinference/ed.
Mirrored from https://github.com/ondeinference/ed.git
Synced Nov 23, 01:00 UTC
Reject a model name that spans lines
store_in checked the API key for newlines but not the model, so a model like "x\nED_CLAUDE_API_KEY=..." wrote extra lines into the env file. It now fails the same way the key does, and nothing is written. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: siGit Code v1.7.6 <noreply@sigit.si>
Seto Elkahfi committed
Nov 1, 2026 at 19:48 UTC
96dd1b1ae4f127f88246b1c251f06799ad187e7a
1 file changed
+13
-1
crates/ed-claude/src/credentials.rs
+13
-1
@@ -70,9 +70,13 @@ pub(crate) fn store_in(dir: &Path, api_key: &str, model: Option<&str>) -> Result
70
if api_key.is_empty() || api_key.contains(['\n', '\r']) {
71
return Err("the API key is empty or spans lines".to_string());
72
}
73
+ let model = model.map(str::trim).filter(|m| !m.is_empty());
74
+ if model.is_some_and(|m| m.contains(['\n', '\r'])) {
75
+ return Err("the model name spans lines".to_string());
76
+ }
77
std::fs::create_dir_all(dir).map_err(|e| format!("create {dir:?}: {e}"))?;
78
let mut body = format!("{KEY_VAR}={api_key}\n");
75
- if let Some(model) = model.map(str::trim).filter(|m| !m.is_empty()) {
79
+ if let Some(model) = model {
80
body.push_str(&format!("{MODEL_VAR}={model}\n"));
81
}
82
let path = dir.join(FILE);
@@ -154,6 +158,14 @@ mod tests {
158
assert!(store_in(&dir, "a\nED_CLAUDE_MODEL=x", None).is_err());
159
}
160
161
+ #[test]
162
+ fn rejects_a_model_that_would_inject_a_line() {
163
+ let dir = scratch("reject-model");
164
+ assert!(store_in(&dir, "sk-ant-1", Some("x\nED_CLAUDE_API_KEY=sk-other")).is_err());
165
+ assert!(store_in(&dir, "sk-ant-1", Some("x\r\ny")).is_err());
166
+ assert_eq!(load_from(&dir), None, "nothing was written");
167
+ }
168
+
169
#[cfg(unix)]
170
#[test]
171
fn the_file_is_private() {