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

Function validate_session_id

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

Validate a session ID to prevent path traversal. Rejects IDs containing `..`, `/`, `\`, or null bytes.

(session_id: &str)

Source from the content-addressed store, hash-verified

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

Callers 11

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

Calls 3

is_emptyMethod · 0.45
containsMethod · 0.45
lenMethod · 0.45

Tested by 2