Skip to content

Security: Validate targetPath in IsPathSafe utility #4

@CoderSerio

Description

@CoderSerio

Vulnerability\nThe IsPathSafe function in src/utils/agent.ts only checks if targetPath starts with safeRange. This is insufficient against path traversal attacks using relative paths (e.g., safeRange = '/tmp/project', targetPath = '/tmp/project/../secret').\n\n## Impact\nAn attacker could potentially read files outside the intended directory if this function is used for access control.\n\n## Recommendation\nUse path.resolve() to normalize both paths before comparison:\n\nts\nexport const IsPathSafe = (props: {\n safeRange: string;\n targetPath: string;\n}) => {\n const { safeRange, targetPath } = props;\n const resolvedSafe = path.resolve(safeRange);\n const resolvedTarget = path.resolve(targetPath);\n return resolvedTarget.startsWith(resolvedSafe + path.sep) || resolvedTarget === resolvedSafe;\n};\n\n\n## References\n- OWASP Path Traversal

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions