Skip to content

Conversation

@sontoriyama
Copy link

@sontoriyama sontoriyama commented Jan 7, 2026

This PR improves the robustness of the memory discovery logic and resolves systemic IDE diagnostic errors.

Key changes:

  • Enhanced path validation and boundary checks in memory discovery.
  • Resolved constructor parameter mismatches in DeclarativeTool.
  • Verified stability with existing test suites.
  • General cleanup of temporary diagnostic files.

When a GEMINI.md filename matches a directory (e.g., user has
.gemini/gemini.md/ as a folder), the code attempted to read it as
a file, causing unnecessary warnings.

This change adds an lstat check before readFile to silently skip
directories with a debug log message.

Fixes #4760
- Remove unused validGeminiMdFile (GEMINI.md.md not discovered)
- Update assertions to match actual behavior of loadServerHierarchicalMemory
- Add clear comments explaining expected behavior
Replace lstat() pre-check with try/catch for EISDIR error based on
code review feedback. This approach:

- Handles symlinks correctly (fs.stat follows links, lstat does not)
- Avoids TOCTOU race conditions
- More efficient (no double syscall)
- More idiomatic Node.js pattern (EAFP)

Fixes #4760

Ref: #15866 (comment)
On non-Debian/Ubuntu Linux distributions, the Antigravity IDE binary is installed as 'antigravity' instead of 'agy'. This commit adds 'antigravity' as a fallback in the editorCommands mapping to enable proper detection on these distributions.

Fixes #15553
@sontoriyama sontoriyama requested a review from a team as a code owner January 7, 2026 06:41
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @sontoriyama, 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 security and reliability of the memory management system by introducing robust path traversal prevention for GEMINI.md files and imports. It also improves the memory discovery process by gracefully handling misnamed directories. Additionally, the PR includes important dependency updates and minor fixes for IDE compatibility and editor command aliases, contributing to a more stable and secure codebase.

Highlights

  • Enhanced Security for Memory Tools: Implemented robust path traversal prevention for GEMINI.md filenames and imports, ensuring that memory files cannot access sensitive data outside designated project or global directories.
  • Improved Memory Discovery Robustness: Added logic to silently skip directories that are mistakenly named GEMINI.md during memory discovery, preventing errors and improving user experience.
  • Dependency Updates and Cleanup: Updated several core dependencies, including express, qs, and type-is, and refined the NOTICES.txt file to reflect these changes and remove outdated entries.
  • IDE Compatibility Fixes: Addressed a TypeScript type assertion issue in MemoryTool tests to resolve potential IDE false positives.
  • Expanded Editor Support: Added 'antigravity' as an alias for the 'agy' command in the editor utility.
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.

@sontoriyama sontoriyama changed the title fix: resolve IDE false positives and validate memory tool security security: prevent path traversal in GEMINI.md imports and fix IDE errors Jan 7, 2026
@sontoriyama sontoriyama changed the title security: prevent path traversal in GEMINI.md imports and fix IDE errors fix: improve path validation in memory discovery and resolve IDE errors Jan 7, 2026
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 introduces important security enhancements and bug fixes, primarily focused on the MemoryTool. The changes effectively add path traversal validation for memory file names and memory imports, which is a significant improvement. The accompanying tests are thorough and cover critical security scenarios, such as preventing imports from outside the project root. The handling of directories named like memory files also adds to the robustness of the memory discovery process.

I have found one critical security vulnerability that remains in the setGeminiMdFilename function, where the validation is incomplete and still allows for path traversal using . or .. as filenames. My review includes a specific suggestion to address this.

Overall, this is a valuable contribution to the security and stability of the tool. Once the identified issue is resolved, this PR will be in great shape.

Comment on lines 75 to 79
if (trimmed.includes('/') || trimmed.includes('\\')) {
throw new Error(
`Invalid GEMINI.md filename: ${trimmed}. Filenames cannot contain path separators.`,
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The validation for newFilename is a good security measure, but it's incomplete. It currently checks for path separators (/ and \\) but fails to prevent the use of . or .. as a filename. This allows for a path traversal vulnerability. For instance, setting newFilename to '..' would cause functions like getGlobalMemoryFilePath to construct a path that traverses up one directory, enabling file writes outside the intended .gemini directory. To mitigate this, the validation should also explicitly disallow . and .. as filenames.

Suggested change
if (trimmed.includes('/') || trimmed.includes('\\')) {
throw new Error(
`Invalid GEMINI.md filename: ${trimmed}. Filenames cannot contain path separators.`,
);
}
if (trimmed.includes('/') || trimmed.includes('\\') || trimmed === '.' || trimmed === '..') {
throw new Error(
`Invalid GEMINI.md filename: ${trimmed}. Filenames cannot contain path separators or be '.' or '..'.`,
);
}

@jacob314 jacob314 added the status/need-issue Pull requests that need to have an associated issue. label Jan 7, 2026
When a GEMINI.md filename matches a directory (e.g., user has
.gemini/gemini.md/ as a folder), the code attempted to read it as
a file, causing unnecessary warnings.

This change adds an lstat check before readFile to silently skip
directories with a debug log message.

Fixes #4760
@sontoriyama
Copy link
Author

Fixes #16104

@sontoriyama sontoriyama closed this by deleting the head repository Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants