refactor(session): simplify traversal guard to a helper + logger, harden non-leading separators

Follow-up to the salvaged #9560 fix:
- Replace the _TRAVERSAL_RE regex with an explicit _is_path_unsafe() helper
  (drops the now-unused `import re`); catches a path separator ANYWHERE,
  not just leading, so a non-leading Windows backslash can't slip through.
- Switch the per-entry skip in _ensure_loaded_locked from print() to
  logger.warning to match the module's logging conventions.
- Add AUTHOR_MAP entry for the contributor.
- Add regression tests for the non-leading-separator case.
This commit is contained in:
teknium1 2026-06-21 14:00:19 -07:00 committed by Teknium
parent aa2aac68b0
commit 4d4ba0831e
3 changed files with 33 additions and 7 deletions

View file

@ -1095,6 +1095,15 @@ class TestSessionEntryFromDictTraversalValidation:
with pytest.raises(ValueError, match="session_id"):
SessionEntry.from_dict(self._entry(session_id="D:\\path\\to\\file"))
def test_session_id_non_leading_separator_raises(self):
"""A path separator anywhere — not just leading — must be rejected,
since a non-leading backslash is still a Windows traversal vector."""
from gateway.session import SessionEntry
with pytest.raises(ValueError, match="session_id"):
SessionEntry.from_dict(self._entry(session_id="good\\..\\bad"))
with pytest.raises(ValueError, match="session_key"):
SessionEntry.from_dict(self._entry(session_key="agent:main:good/sub"))
class TestEnsureLoadedSkipsInvalidEntries:
"""Regression: one bad sessions.json entry must not block valid entries from loading."""