Description
When the CORTEX_AUTH_TOKEN environment variable is set to a value containing non-ASCII UTF-8 characters where byte position 8 falls inside a multi-byte character, cortex login status panics immediately.
The safe_format_key() function in cortex-login/src/utils.rs checks if key.len() <= 13 and then slices &key[..8] as a raw byte slice. If byte 8 is inside a multi-byte UTF-8 character, this panics.
Steps to Reproduce
$env:CORTEX_AUTH_TOKEN = "aaaaaaa" + [char]233 + "aaaaa"
& "C:\...\cortex.exe" login status
The token is 7 ASCII chars + é (U+00E9, 2 UTF-8 bytes at positions 7-8) + 5 ASCII chars = 14 bytes. This passes the <= 13 guard, then &key[..8] slices mid-character.
Actual Behavior
Panic in thread 'main' at src\cortex-login\src\utils.rs:11:22
thread 'main' (27028) panicked at src\cortex-login\src\utils.rs:11:22:
byte index 8 is not a char boundary; it is inside 'é' (bytes 7..9) of `aaaaaaaéaaaaa`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expected Behavior
Should safely mask the token without panicking, even if it contains non-ASCII characters.
Root Cause
In src/cortex-login/src/utils.rs:11:
pub fn safe_format_key(key: &str) -> String {
if key.len() <= 13 {
return "***".to_string();
}
let prefix = &key[..8]; // panics if byte 8 is inside a multi-byte char
let suffix = &key[key.len() - 5..];
format!("{prefix}***{suffix}")
}
Should use key.floor_char_boundary(8) or iterate via char_indices() for safe slicing.
Screenshot

Environment
- Cortex version: v0.0.7
- OS: Windows 11
- Shell: PowerShell
Description
When the
CORTEX_AUTH_TOKENenvironment variable is set to a value containing non-ASCII UTF-8 characters where byte position 8 falls inside a multi-byte character,cortex login statuspanics immediately.The
safe_format_key()function incortex-login/src/utils.rschecksif key.len() <= 13and then slices&key[..8]as a raw byte slice. If byte 8 is inside a multi-byte UTF-8 character, this panics.Steps to Reproduce
The token is 7 ASCII chars +
é(U+00E9, 2 UTF-8 bytes at positions 7-8) + 5 ASCII chars = 14 bytes. This passes the<= 13guard, then&key[..8]slices mid-character.Actual Behavior
Expected Behavior
Should safely mask the token without panicking, even if it contains non-ASCII characters.
Root Cause
In
src/cortex-login/src/utils.rs:11:Should use
key.floor_char_boundary(8)or iterate viachar_indices()for safe slicing.Screenshot
Environment