Skip to content

Fix path injection in addons#5667

Merged
RongGu merged 1 commit intofluid-cloudnative:masterfrom
Pikabooboo:io_fix
Feb 15, 2026
Merged

Fix path injection in addons#5667
RongGu merged 1 commit intofluid-cloudnative:masterfrom
Pikabooboo:io_fix

Conversation

@Pikabooboo
Copy link
Collaborator

Ⅰ. Describe what this PR does

Fix path injection in addons

Ⅱ. Does this pull request fix one issue?

fixes #XXXX

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

CI pipeline

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Pikabooboo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces critical security improvements by adding comprehensive validation and normalization to the target_path variable within the GlusterFS addon's entrypoint script. These changes are designed to prevent malicious path injection attempts, ensuring that only safe and valid file system paths are processed, thereby enhancing the overall security posture of the system.

Highlights

  • Security Enhancement: Implemented robust path validation and normalization for target_path in the GlusterFS addon entrypoint to prevent path injection vulnerabilities.
  • Input Validation: Added checks to ensure target_path is an absolute path and contains only allowed characters (alphanumeric, '.', '_', '-').
  • Path Normalization: Utilized os.path.normpath to normalize the target_path, effectively mitigating directory traversal attacks.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • addons/glusterfs/docker/entrypoint.py
    • Added validation to ensure target_path is an absolute path.
    • Introduced character validation for target_path using a regular expression.
    • Applied os.path.normpath to target_path to prevent directory traversal.
Activity
  • No specific review comments or activity have been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to fix a path injection vulnerability. However, the current implementation is flawed as it uses the re module without importing it, which will cause a runtime error and a Denial of Service for the addon, preventing the security validation from being executed. Additionally, the path validation is not strict enough to prevent path traversal attacks.

print(f"Error: target_path must be absolute: {target_path}")
exit(1)

if not re.match(r'^[/a-zA-Z0-9._-]+$', target_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

The re module is used here (e.g., re.match() for target_path validation) but is not imported. This will cause a NameError: name 're' is not defined at runtime, leading to a crash and a Denial of Service (DoS) for the addon. Consequently, the intended security validation is never performed. Please add import re at the beginning of the file.

@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.29%. Comparing base (bf382a2) to head (198939c).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5667   +/-   ##
=======================================
  Coverage   61.29%   61.29%           
=======================================
  Files         444      444           
  Lines       30540    30540           
=======================================
  Hits        18721    18721           
  Misses      10276    10276           
  Partials     1543     1543           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Pikabooboo Pikabooboo force-pushed the io_fix branch 2 times, most recently from c6caeb2 to 0be335e Compare February 12, 2026 12:12
@cheyang
Copy link
Collaborator

cheyang commented Feb 13, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances security by adding validation for target_path to prevent path injection vulnerabilities. The checks for an absolute path, against path traversal components ('..'), and for allowed characters are good security practices.

However, I've identified a potential issue where the target_path could resolve to the root directory ('/') after normalization, which could lead to mounting on the root filesystem. I've added a review comment with a suggestion to prevent this. This is a high-severity issue that should be addressed.

exit(1)
# Normalize to prevent traversal attacks
target_path = os.path.normpath(target_path)
os.makedirs(target_path, exist_ok=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The normalized target_path could become the root directory / (for example, if the input was /. or //). Mounting on the root directory is dangerous and should be explicitly prevented. Please add a check for this case before creating the directory.

if target_path == '/':
    print("Error: target_path resolves to the root directory '/' and is not allowed.")
    exit(1)
os.makedirs(target_path, exist_ok=True)

Copy link
Member

@RongGu RongGu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds path validation to the GlusterFS addon's entrypoint script to prevent path injection vulnerabilities. The validation checks that the target_path from the configuration JSON is an absolute path, doesn't contain path traversal sequences (..), contains only allowed characters, and is normalized before use.

Changes:

  • Added regex import for path validation
  • Implemented three-stage validation: absolute path check, path traversal prevention, and character whitelist validation
  • Added path normalization before directory creation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 20 to 24
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of validation operations is incorrect. The regex check on line 20 is performed before os.path.normpath on line 24, which means paths like "//path" or "/path//subdir" would fail the regex check even though they normalize to valid paths. Additionally, os.path.normpath should be called before any validation checks to ensure all subsequent checks operate on the normalized path. Move the normpath call to immediately after line 9, before all validation checks.

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +18
if '..' in target_path.split('/'):
print(f"Error: Path traversal using '..' is not allowed in target_path: {target_path}")
exit(1)
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path traversal check for '..' is performed before normalization. This creates a gap where paths like '/path/./subdir' or paths with multiple slashes would pass this check but might represent the same file system location as a path with '..'. While not directly a '..' bypass, checking before normalization means you're not validating the canonical form of the path. If normalization is moved to occur first (as suggested in another comment), this check can serve as a post-normalization safety check to catch any remaining '..' components, which should not exist in a properly normalized absolute path.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After normalization on line 24, there should be an additional check to ensure the normalized path still starts with '/' and is an absolute path. The os.path.normpath function could potentially reduce a path like '/../../../etc/passwd' to '/etc/passwd' (depending on the input), and while the initial check on line 12 prevents this specific case, having a post-normalization validation ensures the path remains absolute and within expected boundaries.

Suggested change
target_path = os.path.normpath(target_path)
target_path = os.path.normpath(target_path)
# Ensure the normalized path is still absolute and starts with '/'
if not os.path.isabs(target_path) or not target_path.startswith('/'):
print(f"Error: Normalized target_path is not an absolute POSIX path: {target_path}")
exit(1)

Copilot uses AI. Check for mistakes.
Signed-off-by: pikabooboo <pikabooboo777@gmail.com>
@sonarqubecloud
Copy link

@RongGu
Copy link
Member

RongGu commented Feb 15, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to fix a path injection vulnerability in the glusterfs addon by adding validation for the target_path. However, critical vulnerabilities remain. The current validation can be bypassed, specifically through the use of os.path.normpath preserving double leading slashes (//), which allows bypassing the root directory check, and the regex validation using the $ anchor, which can be bypassed by a trailing newline. Additionally, the current checks do not prevent mounting volumes over sensitive system directories by specifying arbitrary absolute paths. It is recommended to enforce that all mounts occur within a designated safe base directory, use re.fullmatch, and apply additional path normalization to fully mitigate these risks.

Comment on lines +12 to +32
target_path = os.path.normpath(target_path)

# Validate that the normalized path is an absolute POSIX path
if not os.path.isabs(target_path) or not target_path.startswith('/'):
print(f"Error: target_path must be absolute: {target_path}")
exit(1)

# Safety check: ensure no '..' components remain after normalization
if '..' in target_path.split('/'):
print(f"Error: Path traversal using '..' is not allowed in target_path: {target_path}")
exit(1)

# Validate that the path contains only safe characters
if not re.match(r'^[/a-zA-Z0-9._-]+$', target_path):
print(f"Error: target_path contains invalid characters: {target_path}")
exit(1)

# Prevent mounting on the root directory
if target_path == '/':
print("Error: target_path resolves to the root directory '/' and is not allowed.")
exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

This section has critical vulnerabilities. The current root directory check can be bypassed using paths with double leading slashes (e.g., //), as os.path.normpath preserves these, allowing // to resolve to root despite not matching /. Additionally, the regex validation using the $ anchor can be bypassed by a trailing newline. Beyond these bypasses, the current checks do not prevent users from specifying arbitrary absolute paths like /etc or /usr/bin for target_path, which could lead to mounting volumes over sensitive system directories and potential container escapes. It is crucial to implement robust normalization, use re.fullmatch, and enforce that target_path is restricted to a designated safe base directory.

target_path = os.path.normpath(target_path)
if target_path.startswith('//') and not target_path.startswith('///'):
    target_path = '/' + target_path.lstrip('/')

# Validate that the normalized path is an absolute POSIX path
if not os.path.isabs(target_path) or not target_path.startswith('/'):
    print(f"Error: target_path must be absolute: {target_path}")
    exit(1)

# Safety check: ensure no '..' components remain after normalization
if '..' in target_path.split('/'):
    print(f"Error: Path traversal using '..' is not allowed in target_path: {target_path}")
    exit(1)

# Validate that the path contains only safe characters
if not re.fullmatch(r'^[/a-zA-Z0-9._-]+$', target_path):
    print(f"Error: target_path contains invalid characters: {target_path}")
    exit(1)

# Prevent mounting on the root directory
if target_path == '/':
    print("Error: target_path resolves to the root directory '/' and is not allowed.")
    exit(1)

Copy link
Member

@RongGu RongGu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@fluid-e2e-bot fluid-e2e-bot bot added the lgtm label Feb 15, 2026
@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Feb 15, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RongGu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@RongGu RongGu merged commit eafa053 into fluid-cloudnative:master Feb 15, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments