You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Path Validation Bypass in Authenticated Project File Operations #329
Gerapy contains a path validation flaw in is_in_curdir() that may allow paths outside the intended working directory to pass validation.
The function uses os.path.realpath(filepath).startswith(os.path.realpath(os.getcwd())) to verify path containment. Since startswith() does not enforce directory boundaries, a sibling directory with a matching path prefix can incorrectly pass the check.
Affected Components
gerapy/server/core/utils.py — is_in_curdir()
gerapy/server/core/views.py — project_file_read, project_file_update, project_file_create, project_file_delete, and project_file_rename
These endpoints require authentication and rely on the vulnerable helper before performing file operations.
Proof of Concept
For example, if the intended directory is:
/home/user/gerapy
A sibling path such as:
/home/user/gerapy-backup/marker.txt
may pass the validation because its string representation starts with /home/user/gerapy, even though it is outside that directory.
A local test reproduced this behavior:
Old validation accepts: True
Correct containment check: False
Potential Impact
An authenticated user may be able to read, modify, create, delete, or rename files outside the intended directory, depending on the supplied path, application behavior, and filesystem permissions.
Note: The path-validation bypass has been reproduced locally. Successful exploitation through the actual API endpoints has not yet been verified.
Recommended Fix
Replace the string-prefix check with a path-component-aware containment check, such as os.path.commonpath(), and validate paths against the intended project directory.
Classification
CWE-22 — Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Activity