MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / validate_session_id

Function validate_session_id

atomic-agent/src/turn/session.rs:1415–1444  ·  view source on GitHub ↗

Validate a session ID to prevent path traversal. Rejects blank IDs, IDs containing `..`, `/`, `\` or null bytes, and IDs longer than 255 UTF-8 bytes (the filesystem component limit).

(session_id: &str)

Source from the content-addressed store, hash-verified

1413/// Rejects blank IDs, IDs containing `..`, `/`, `\` or null bytes, and IDs
1414/// longer than 255 UTF-8 bytes (the filesystem component limit).
1415pub fn validate_session_id(session_id: &str) -> AgentResult<()> {
1416 if session_id.trim().is_empty() {
1417 return Err(AgentError::SessionIdInvalid {
1418 session_id: "(empty)".to_string(),
1419 });
1420 }
1421
1422 if session_id.contains("..")
1423 || session_id.contains('/')
1424 || session_id.contains('\\')
1425 || session_id.contains('\0')
1426 {
1427 return Err(AgentError::SessionIdInvalid {
1428 session_id: session_id.to_string(),
1429 });
1430 }
1431
1432 // Reject very long session IDs (filesystem path limits)
1433 if session_id.len() > 255 {
1434 return Err(AgentError::SessionIdInvalid {
1435 session_id: format!(
1436 "{}... (too long: {} bytes)",
1437 session_id.chars().take(20).collect::<String>(),
1438 session_id.len()
1439 ),
1440 });
1441 }
1442
1443 Ok(())
1444}
1445
1446/// Whether a writer pid is still alive (CB-13D ::24 R6): a claim file
1447/// whose writer is gone belongs to a crashed consumer and is replayed.

Callers 12

bind_turn_intentMethod · 0.85
turn_intent_bindingMethod · 0.85
freeze_turn_intentMethod · 0.85
loadMethod · 0.85
saveMethod · 0.85
clearMethod · 0.85
write_watch_noticeMethod · 0.85
take_watch_noticeMethod · 0.85
capture_dirFunction · 0.85
typed_turn_eventFunction · 0.85

Calls 3

is_emptyMethod · 0.45
containsMethod · 0.45
lenMethod · 0.45

Tested by 2