Skip to content

Commit aebf214

Browse files
feat(security): enhance path validation in WorkspaceManager
- Add symlink resolution with strict=True to prevent symlink attacks - Blacklist sensitive directories (.ssh, .aws, .gnupg, .config) - Improve exception handling to catch all path-related errors - Update docstring with comprehensive security policy Co-authored-by: Frank Bria <frankbria@users.noreply.github.com>
1 parent cd59474 commit aebf214

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

codeframe/workspace/manager.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,11 @@ def _init_from_local(self, workspace_path: Path, local_path: str) -> None:
206206
def _is_safe_path(self, path: Path) -> bool:
207207
"""Check if path is safe to access.
208208
209-
Security policy: Only allow paths under user's home directory.
210-
This prevents access to system files, other users' files, etc.
209+
Security policy:
210+
- Must be under user's home directory
211+
- Must be a real path (resolve symlinks)
212+
- Cannot contain sensitive directories
213+
- No path traversal attempts
211214
212215
Args:
213216
path: Path to validate (must be absolute)
@@ -216,14 +219,22 @@ def _is_safe_path(self, path: Path) -> bool:
216219
True if path is safe to access
217220
"""
218221
try:
219-
# Get user's home directory
222+
# Resolve symlinks and normalize (strict=True requires path to exist)
223+
resolved_path = path.resolve(strict=True)
220224
home_dir = Path.home().resolve()
221225

222226
# Check if path is under home directory
223-
path.relative_to(home_dir)
227+
resolved_path.relative_to(home_dir)
228+
229+
# Blacklist sensitive directories
230+
sensitive_dirs = {'.ssh', '.aws', '.gnupg', '.config'}
231+
for part in resolved_path.parts:
232+
if part in sensitive_dirs:
233+
return False
234+
224235
return True
225-
except ValueError:
226-
# Path is not under home directory
236+
except (ValueError, RuntimeError, OSError):
237+
# Path is not under home directory, doesn't exist, or other error
227238
return False
228239

229240
def _init_from_upload(self, workspace_path: Path, upload_filename: str) -> None:

0 commit comments

Comments
 (0)