Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5118134
fix(security): char-safe truncation in sanitize_system_prompt Fixes #…
May 19, 2026
f490a41
trigger: rebuild after repo cleanup
May 19, 2026
7218d53
fix(clippy): remaining field-reassign-with-default and unnecessary ca…
May 19, 2026
952b7e4
trigger: rebuild with clean repo
May 19, 2026
9dee7d0
trigger: rebuild webhook test
May 19, 2026
2d66e2c
trigger: full-clone pipeline test Refs #1721
May 19, 2026
5958b2a
trigger: pipeline test with full clone Refs #1721
May 19, 2026
b58044f
trigger: depth=1 fetch pipeline test Refs #1721
May 19, 2026
b0b43dd
ci: e2e pipeline test from local Refs #1721
May 19, 2026
83c114d
ci: selective refspec pipeline test Refs #1721
May 19, 2026
58c6a57
ci: final pipeline test with webhook ready Refs #1721
May 19, 2026
f65d8b9
style: cargo fmt for role_llm_api_key test Refs #1721
May 19, 2026
bdd1156
fix: remove accidentally committed project.rs Refs #1721
May 19, 2026
85b19a5
ci: fresh clone pipeline test Refs #1721
May 19, 2026
0b1ebf9
fix(build-runner): tee output to file and fix BUILD.md parsing
May 19, 2026
26f5b87
feat(config): implement project-level config discovery for .terraphim/
May 19, 2026
59cd233
feat(config): implement project-level config discovery for .terraphim/
May 19, 2026
82c7467
fix(config): remove needless borrows in project.rs clippy warnings
May 19, 2026
af9f0f5
Merge remote-tracking branch 'origin/push-1721' into push-1721
May 19, 2026
64136b2
docs: update project-level config discovery documentation
May 19, 2026
6fea5ad
fix(security): char-safe truncation in sanitize_system_prompt and bui…
May 19, 2026
9a4a83a
docs: add release announcement for v2026.05.19
May 19, 2026
2f3ada1
Merge remote-tracking branch 'origin/push-1721' into push-1721
May 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(security): char-safe truncation in sanitize_system_prompt Fixes #…
…1721

Replace byte-slice truncation prompt[..MAX_PROMPT_LENGTH] with
prompt.chars().take(MAX_PROMPT_LENGTH).collect() to prevent panic
when MAX_PROMPT_LENGTH falls inside a multi-byte UTF-8 character.

Adds test_sanitize_multibyte_boundary to verify correct behaviour.
  • Loading branch information
forge-admin committed May 19, 2026
commit 51181347951e11dcb7370f4948eb84e15978bdd2
15 changes: 13 additions & 2 deletions crates/terraphim_multi_agent/src/prompt_sanitizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn sanitize_system_prompt(prompt: &str) -> SanitizedPrompt {
}

let content = if prompt.len() > MAX_PROMPT_LENGTH {
prompt[..MAX_PROMPT_LENGTH].to_string()
prompt.chars().take(MAX_PROMPT_LENGTH).collect::<String>()
} else {
prompt.to_string()
};
Expand Down Expand Up @@ -204,7 +204,18 @@ mod tests {
let prompt = "a".repeat(MAX_PROMPT_LENGTH + 1000);
let result = sanitize_system_prompt(&prompt);
assert!(result.was_modified);
assert_eq!(result.content.len(), MAX_PROMPT_LENGTH);
assert_eq!(result.content.chars().count(), MAX_PROMPT_LENGTH);
}

#[test]
fn test_sanitize_multibyte_boundary() {
// MAX_PROMPT_LENGTH+1 chars: 9999 ASCII + 2 CJK (3 bytes each)
// After char-safe truncation: 9999 ASCII + 1 CJK = 10000 chars, 10002 bytes
let prompt: String = "a".repeat(MAX_PROMPT_LENGTH - 1) + "中中";
let result = sanitize_system_prompt(&prompt);
assert!(result.was_modified);
assert_eq!(result.content.chars().count(), MAX_PROMPT_LENGTH);
assert!(result.content.len() > MAX_PROMPT_LENGTH);
}

#[test]
Expand Down