Conversation
Summary of ChangesHello @Tomas2D, 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 significantly enhances the AgentStack SDK by integrating an fsspec-compatible filesystem extension. This integration allows agents to interact with the AgentStack Files API using a unified and flexible interface, streamlining data access and manipulation. The changes encompass adding essential dependencies, implementing the core filesystem logic, and providing a clear demonstration agent to showcase its utility. This improvement aims to provide a more robust and developer-friendly experience for agents requiring file operations within the AgentStack ecosystem. Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
The pull request introduces a Virtual File System (VFS) extension for AgentStack, enabling fsspec-compatible access to the Files API. While this is a valuable feature, it contains a high-severity path traversal vulnerability in the path normalization logic, allowing for bypassing the prefix restriction and potentially leading to unauthorized file access or modification. Furthermore, several code-related issues need addressing, such as a version regression in the SDK's pyproject.toml, missing imports and invalid method calls in the example agent, and potential performance bottlenecks in the VFS implementation due to eager file loading and inefficient async-to-sync bridging.
| path = path.lstrip("/") | ||
| return f"{self._prefix}/{path}" if self._prefix else path |
There was a problem hiding this comment.
The _normalize_path method is vulnerable to path traversal. It prepends a prefix to a user-supplied path but only strips leading slashes, failing to handle .. components. An attacker or a malicious LLM agent could use paths like ../../etc/passwd to escape the intended _prefix and access, modify, or delete unauthorized files in the AgentStack platform.
To fix this, use os.path.normpath to resolve relative path components and verify that the resulting path still starts with the allowed prefix.
| path = path.lstrip("/") | |
| return f"{self._prefix}/{path}" if self._prefix else path | |
| import os | |
| path = path.lstrip("/") | |
| if not self._prefix: | |
| return path | |
| full_path = os.path.normpath(os.path.join(self._prefix, path)) | |
| if not full_path.startswith(self._prefix): | |
| raise ValueError("Access denied: path is outside the allowed prefix") | |
| return full_path |
| [project] | ||
| name = "agentstack-sdk" | ||
| version = "0.6.3" | ||
| version = "0.6.1" |
| df = pd.read_csv(f, sep="|", header=None) | ||
| yield df.text() |
| self._platform = platform | ||
| self._agentstack_fs = fs # Store reference for our use | ||
|
|
||
| data = self._load_content() if "r" in mode else None |
There was a problem hiding this comment.
The current implementation eagerly loads the entire file content into memory upon opening in read mode. For large files, this will lead to high memory consumption and potential MemoryError. Consider implementing lazy loading or a buffered reader by inheriting from fsspec.spec.AbstractBufferedFile instead of MemoryFile.
|
|
||
| async def _commit(): | ||
| async with platform.use_client() as client: | ||
| ct = "text/plain" if self.path.endswith(".txt") else "text/csv" if self.path.endswith(".csv") else "application/json" if self.path.endswith(".json") else "application/octet-stream" |
There was a problem hiding this comment.
Hardcoding mimetypes based on a few extensions is fragile. It's better to use the standard mimetypes library to determine the content type dynamically.
| ct = "text/plain" if self.path.endswith(".txt") else "text/csv" if self.path.endswith(".csv") else "application/json" if self.path.endswith(".json") else "application/octet-stream" | |
| import mimetypes | |
| ct, _ = mimetypes.guess_type(self.path) | |
| ct = ct or "application/octet-stream" |
| if loop and loop.is_running(): | ||
| import concurrent.futures | ||
|
|
||
| with concurrent.futures.ThreadPoolExecutor() as executor: |
There was a problem hiding this comment.
Summary
Linked Issues
Documentation
If this PR adds new feature or changes existing. Make sure documentation is adjusted accordingly. If the docs is not needed, please explain why.