mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
fix(copilot): warn on path-traversal in delete_stale_cli_session_file
Self-review: the projects-base guard was returning silently. Mirror the warn-shape from `_write_cli_session_to_disk` so an out-of-base resolve surfaces as a Sentry-visible warning. Unreachable in normal operation (server-generated UUID + deterministic `cli_session_path`), but a hit would indicate a config or tampering issue worth seeing.
This commit is contained in:
@@ -1320,6 +1320,17 @@ def delete_stale_cli_session_file(
|
||||
"""
|
||||
real_path = os.path.realpath(cli_session_path(sdk_cwd, session_id))
|
||||
if not real_path.startswith(projects_base() + os.sep):
|
||||
# Mirror ``_write_cli_session_to_disk``'s defense-in-depth: log
|
||||
# rather than fail silently when the resolved path escapes the
|
||||
# projects base. In normal operation this is unreachable
|
||||
# (session_id is a server-generated UUID and ``cli_session_path``
|
||||
# is deterministic), so a hit indicates a config or tampering
|
||||
# issue that's worth surfacing.
|
||||
logger.warning(
|
||||
"%s CLI session delete path outside projects base: %s",
|
||||
log_prefix,
|
||||
os.path.basename(real_path),
|
||||
)
|
||||
return False
|
||||
# Direct unlink — no exists() check (avoids TOCTOU with the file being
|
||||
# deleted by another process between check and unlink).
|
||||
|
||||
Reference in New Issue
Block a user