Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a893cee
fix(core): skip directories when reading GEMINI.md files
sontoriyama Jan 3, 2026
126884e
test: fix directory test logic per Gemini bot review
sontoriyama Jan 4, 2026
ad8fa98
refactor: use EAFP pattern for directory handling (EISDIR)
sontoriyama Jan 4, 2026
f072f28
fix: add NodeJS.ErrnoException type cast for stricter TypeScript comp…
sontoriyama Jan 4, 2026
4dc4add
test: update unit tests for antigravity fallback binary
sontoriyama Jan 6, 2026
88a327f
fix(core): add 'antigravity' as fallback binary name for Linux
sontoriyama Jan 3, 2026
e09bce0
Merge branch 'main' into fix/antigravity-linux-detection and resolve …
sontoriyama Jan 7, 2026
1c7a821
test(core): fix editor tests and update sandbox env handling
sontoriyama Jan 7, 2026
04fbf3d
fix(core): skip directories when reading GEMINI.md files
sontoriyama Jan 3, 2026
9e2bf51
fix(core): improve path validation for imports and resolve test logic…
sontoriyama Jan 7, 2026
70b9873
security: implement path traversal protection and fix linter diagnostics
sontoriyama Jan 7, 2026
1748c8d
fix: resolve IDE parameter mismatches and ensure memory tool security
sontoriyama Jan 7, 2026
7158cef
fix(core): strictly disallow '.' and '..' as memory filenames to prev…
sontoriyama Jan 7, 2026
646714b
fix(core): ensure robust filename validation in memory tool
sontoriyama Jan 7, 2026
1c23aee
Merge upstream/main into fix/antigravity-linux-detection
sontoriyama Jan 7, 2026
8305fe4
Merge upstream/main into fix-clean-history
sontoriyama Jan 7, 2026
390a33e
chore: ensure sensitive files are ignored
sontoriyama Jan 9, 2026
f07df7e
test: refactor openDiff tests to use parameterized tests and fix lint…
sontoriyama Jan 9, 2026
d93caca
test: add path traversal validation tests to memoryTool
sontoriyama Jan 9, 2026
0852115
test: refactor allowEditorTypeInSandbox tests with it.each to reduce …
sontoriyama Jan 9, 2026
6d4cf93
fix(core): ensure filePaths only contains successfully read files
sontoriyama Jan 9, 2026
f290c1f
fix: restore missing homedir and tmpdir to paths utility
sontoriyama Jan 9, 2026
17c750b
Merge branch 'main' into fix-clean-history
sontoriyama Jan 9, 2026
877b568
chore: remove duplicate homedir and tmpdir in paths.ts
sontoriyama Jan 9, 2026
f0284be
Merge branch 'fix/antigravity-linux-detection' to improve cross-platf…
sontoriyama Jan 9, 2026
0a6935b
docs: add utility comment to paths.ts
sontoriyama Jan 9, 2026
262ef11
Merge branch 'fix/gemini-md-directory-clean' and resolve conflicts
sontoriyama Jan 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ gha-creds-*.json
# Log files
patch_output.log

# Agent work and session notes
situacion-nuevo-agente.md
github-bot.md
esta-aceptada-del-todo-o-no-borrar-al-leer.md
*.txt

.genkit
.gemini-clipboard/
.eslintcache
104 changes: 104 additions & 0 deletions github-bot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
Open fix: improve path validation in memory discovery and resolve IDE errors
#16055 sontoriyama wants to merge 5 commits into google-gemini:main from
sontoriyama:fix-clean-history +261 −102 Conversation 3 Commits 5 Checks 2 Files
changed 7 Conversation @sontoriyama sontoriyama commented 23 minutes ago • 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. sontoriyama
added 5 commits 1 hour ago @sontoriyama fix(core): add 'antigravity' as fallback
binary name for Linux b727cd2 @sontoriyama fix(core): skip directories when
reading GEMINI.md files 30619af @sontoriyama fix(core): improve path validation
for imports and resolve test logic… d53c401 @sontoriyama security: implement
path traversal protection and fix linter diagnostics 88cced0 @sontoriyama fix:
resolve IDE parameter mismatches and ensure memory tool security 2c3c861
@sontoriyama sontoriyama requested a review from a team as a code owner 23
minutes ago @gemini-code-assist Contributor gemini-code-assist bot commented 23
minutes ago 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 Footnotes 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 20 minutes ago @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 17
minutes ago gemini-code-assist[bot] gemini-code-assist bot reviewed 15 minutes
ago Contributor gemini-code-assist bot left a comment 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.

packages/core/src/tools/memoryTool.ts Comment on lines +75 to +79 if
(trimmed.includes('/') || trimmed.includes('\\')) { throw new Error(
`Invalid GEMINI.md filename: ${trimmed}. Filenames cannot contain path separators.`,
); } Contributor @gemini-code-assist gemini-code-assist bot 15 minutes ago
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 '..'.`,
); } @sontoriyama Reply... Merge info Review required Code owner review required
by reviewers with write access.

3 workflows awaiting approval This workflow requires approval from a maintainer.
Learn more about approving workflows.

pending checks CI CIExpected — Waiting for status to be reported Required E2E
(Chained) E2E (Chained)Expected — Waiting for status to be reported Required
successful checks cla/google cla/googleSuccessful in 1s — ✅ All contributors
are covered under a CLA with Google Required Gemini Automated PR Labeler /
label-pr (pull_request_target) Gemini Automated PR Labeler / label-pr
(pull_request_target)Successful in 1m Merging is blocked Waiting on code owner
review from google-gemini/gemini-cli-maintainers.
20 changes: 18 additions & 2 deletions packages/core/src/tools/memoryTool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,23 @@ describe('MemoryTool', () => {
it('should handle an array of filenames', () => {
const newNames = ['CUSTOM_CONTEXT.md', 'ANOTHER_CONTEXT.md'];
setGeminiMdFilename(newNames);
expect(getCurrentGeminiMdFilename()).toBe('CUSTOM_CONTEXT.md');
expect(getAllGeminiMdFilenames()).toEqual(newNames);
});

it('should throw an error if the new name contains path separators or is "." or ".."', () => {
expect(() => setGeminiMdFilename('path/to/file.md')).toThrow(
/Invalid GEMINI.md filename: path\/to\/file.md/,
);
expect(() => setGeminiMdFilename('path\\to\\file.md')).toThrow(
/Invalid GEMINI.md filename: path\\to\\file.md/,
);
expect(() => setGeminiMdFilename('.')).toThrow(
/Invalid GEMINI.md filename: \./,
);
expect(() => setGeminiMdFilename('..')).toThrow(
/Invalid GEMINI.md filename: \.\./,
);
});
});

describe('performAddMemoryEntry (static method)', () => {
Expand Down Expand Up @@ -200,6 +214,7 @@ describe('MemoryTool', () => {
});

describe('execute (instance method)', () => {
// Instance-level tests for MemoryTool
let memoryTool: MemoryTool;
let performAddMemoryEntrySpy: Mock<typeof MemoryTool.performAddMemoryEntry>;

Expand Down Expand Up @@ -305,7 +320,8 @@ describe('MemoryTool', () => {

beforeEach(() => {
const bus = createMockMessageBus();
getMockMessageBusInstance(bus).defaultToolDecision = 'ask_user';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(getMockMessageBusInstance(bus) as any).defaultToolDecision = 'ask_user';
memoryTool = new MemoryTool(bus);
// Clear the allowlist before each test
const invocation = memoryTool.build({ fact: 'mock-fact' });
Expand Down
20 changes: 18 additions & 2 deletions packages/core/src/tools/memoryTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,27 @@ export const MEMORY_SECTION_HEADER = '## Gemini Added Memories';
let currentGeminiMdFilename: string | string[] = DEFAULT_CONTEXT_FILENAME;

export function setGeminiMdFilename(newFilename: string | string[]): void {
const validateFilename = (name: string): string => {
const trimmed = name.trim();
if (
trimmed.includes('/') ||
trimmed.includes('\\') ||
trimmed === '.' ||
trimmed === '..'
) {
throw new Error(
`Invalid GEMINI.md filename: ${trimmed}. Filenames cannot contain path separators or be '.' or '..'.`,
);
}
return trimmed;
};

if (Array.isArray(newFilename)) {
if (newFilename.length > 0) {
currentGeminiMdFilename = newFilename.map((name) => name.trim());
currentGeminiMdFilename = newFilename.map(validateFilename);
}
} else if (newFilename && newFilename.trim() !== '') {
currentGeminiMdFilename = newFilename.trim();
currentGeminiMdFilename = validateFilename(newFilename);
}
}

Expand Down Expand Up @@ -299,6 +314,7 @@ export class MemoryTool
static readonly Name = MEMORY_TOOL_NAME;

constructor(messageBus: MessageBus) {
// Initialize the tool with its specific properties
super(
MemoryTool.Name,
'SaveMemory',
Expand Down
Loading