Skip to content

fix(webserver): uncontrolled data used in path expression could lead path traversal #645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

odaysec
Copy link

@odaysec odaysec commented May 17, 2025

target_path = self.headers.get("x-pghoard-target-path")

shutil.copyfile(xlog_path, target_path)

Fix the issue need to ensure that target_path is validated before it is used in shutil.copyfile. The validation should:

  1. Normalize the path using os.path.normpath to remove any .. segments.
  2. Ensure that the normalized path is within a predefined safe directory (e.g., the PostgreSQL data directory or another controlled directory).

The _validate_target_path method should be updated (or implemented if missing) to perform these checks. Additionally, we should ensure that target_path is only used after it has been validated.


References

Path Traversal
werkzeug.utils.secure_filename
CWE-22
CWE-23
CWE-36
CWE-73
CWE-99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant