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

Function validate_session_id

atomic-agent/src/turn/session.rs:620–649  ·  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

618///
619/// Rejects IDs containing `..`, `/`, `\`, or null bytes.
620fn validate_session_id(session_id: &str) -> AgentResult<()> {
621 if session_id.is_empty() {
622 return Err(AgentError::SessionIdInvalid {
623 session_id: "(empty)".to_string(),
624 });
625 }
626
627 if session_id.contains("..")
628 || session_id.contains('/')
629 || session_id.contains('\\')
630 || session_id.contains('\0')
631 {
632 return Err(AgentError::SessionIdInvalid {
633 session_id: session_id.to_string(),
634 });
635 }
636
637 // Reject very long session IDs (filesystem path limits)
638 if session_id.len() > 255 {
639 return Err(AgentError::SessionIdInvalid {
640 session_id: format!(
641 "{}... (too long: {} chars)",
642 &session_id[..20],
643 session_id.len()
644 ),
645 });
646 }
647
648 Ok(())
649}
650
651// Tests
652

Callers 5

loadMethod · 0.85
saveMethod · 0.85
clearMethod · 0.85

Calls 3

is_emptyMethod · 0.45
containsMethod · 0.45
lenMethod · 0.45

Tested by 2