Skip to content
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

fix:gui_caching #147

Merged
merged 1 commit into from
Nov 26, 2024
Merged

fix:gui_caching #147

merged 1 commit into from
Nov 26, 2024

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Nov 26, 2024

handle case where dirs already exist

Summary by CodeRabbit

  • New Features

    • Improved robustness of GUI resource caching by enabling directory copying without errors if the destination exists.
  • Bug Fixes

    • Adjusted URL resolution method to enhance file path handling, though it may alter previous URL validation behavior.

handle case where dirs already exist
Copy link
Contributor

coderabbitai bot commented Nov 26, 2024

Walkthrough

The changes in this pull request primarily affect the GUIInterface class within the ovos_bus_client/apis/gui.py file. Modifications include the addition of the dirs_exist_ok parameter to the shutil.copytree method in the _cache_gui_files function, enhancing directory copying functionality. Additionally, the _resolve_url method has been significantly altered by removing the path traversal vulnerability checks, which may change how URLs are validated and resolved. Overall, these updates improve error handling and resource management related to GUI file caching and URL resolution.

Changes

File Change Summary
ovos_bus_client/apis/gui.py - Updated _cache_gui_files to include dirs_exist_ok in shutil.copytree for robustness.
- Modified _resolve_url to remove path traversal checks, altering URL handling behavior.

Possibly related PRs

  • refactor!:deprecate QML upload from bus #120: The changes in this PR also modify the GUIInterface class in ovos_bus_client/apis/gui.py, particularly affecting the _cache_gui_files method, which is directly related to the caching mechanism discussed in the main PR.
  • fix: resolve image urls #136: This PR introduces a new _resolve_url method in the GUIInterface class, which is directly related to the changes made to the _resolve_url method in the main PR, focusing on URL resolution and file path handling.

Suggested labels

fix

Suggested reviewers

  • goldyfruit

Poem

In the GUI's realm, changes take flight,
With paths now resolved, everything's bright.
Copying files without a care,
A hop and a skip, we're light as air!
No more worries of paths gone astray,
In our bunny world, we dance and play! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added fix and removed fix labels Nov 26, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fc5eef6 and 6670d01.

📒 Files selected for processing (1)
  • ovos_bus_client/apis/gui.py (1 hunks)
🔇 Additional comments (1)
ovos_bus_client/apis/gui.py (1)

Line range hint 469-499: Reintroduce path traversal checks to prevent security vulnerabilities

The removal of path traversal checks in the _resolve_url method may expose the application to security risks. Without proper validation, malicious inputs could lead to unauthorized file access or execution.

It's crucial to sanitize the url input to mitigate path traversal attacks. Reintroduce the normalization and validation of the URL to ensure that only legitimate file paths are processed.

Apply the following changes to enhance security:

+    import urllib.parse
     def _resolve_url(self, url: str) -> str:
         """Resolve a URL to a valid file path.
         
         Args:
             url (str): URL or file path to resolve
                
         Returns:
             str: Resolved absolute file path or original URL
                
         Raises:
             ValueError: If url is None or empty
         """
         if not url or not isinstance(url, str):
             raise ValueError("URL must be a non-empty string")
         if url.startswith("http"):
             return url

+        # Normalize the URL to prevent path traversal
+        normalized_url = os.path.normpath(url)
+        if normalized_url.startswith(('..', '/')) or os.path.isabs(normalized_url):
+            raise ValueError(f"Invalid URL path: {url}")
+
+        url = normalized_url

-        if not os.path.isfile(url):
+        if not os.path.isfile(url):
             GUI_CACHE_PATH = get_xdg_cache_save_path('ovos_gui')
             # Use os.path.join for path construction
             gui_cache = os.path.join(GUI_CACHE_PATH, self.skill_id, url)
             if os.path.isfile(gui_cache):
                 LOG.debug(f"Resolved image: {gui_cache}")
                 return gui_cache
             else:
                 for framework in self.ui_directories:
                     gui_cache = os.path.join(GUI_CACHE_PATH, self.skill_id, framework, url)
                     if os.path.isfile(gui_cache):
                         LOG.debug(f"Resolved image: {gui_cache}")
                         return gui_cache
         return url

Run the following script to identify any instances where os.path functions are used without proper sanitization:

ovos_bus_client/apis/gui.py Show resolved Hide resolved
@JarbasAl JarbasAl merged commit bb7dd22 into dev Nov 26, 2024
9 checks passed
@JarbasAl JarbasAl deleted the fix/gui_caching branch November 26, 2024 18:58
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 42.24%. Comparing base (1db5975) to head (6670d01).
Report is 170 commits behind head on dev.

Files with missing lines Patch % Lines
ovos_bus_client/apis/gui.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #147      +/-   ##
==========================================
+ Coverage   39.49%   42.24%   +2.75%     
==========================================
  Files          17       16       -1     
  Lines        1732     2161     +429     
==========================================
+ Hits          684      913     +229     
- Misses       1048     1248     +200     

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

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

Successfully merging this pull request may close these issues.

1 participant