feat(cli): add --session-id flag for deterministic session startup + validation #24976
feat(cli): add --session-id flag for deterministic session startup + validation #24976AmaanBilwar wants to merge 7 commits intogoogle-gemini:mainfrom
--session-id flag for deterministic session startup + validation #24976Conversation
6e3913f to
04c09b0
Compare
04c09b0 to
4c5eb46
Compare
--session-id flag for deterministic sessions + orchestration --session-id flag for deterministic session startup + validation
Summary of ChangesHello, 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 enhances the CLI tool by introducing a new Highlights
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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new --session-id flag to the CLI, allowing users to specify a session ID for deterministic orchestration. The changes include updating the CLI argument parsing, adding validation for the new flag, and integrating it into the main execution flow. A security review identified that the current validation for the session ID is susceptible to path traversal; a stricter validation regex has been suggested to restrict input to alphanumeric characters, hyphens, and underscores.
| if (trimmedSessionId === '.' || trimmedSessionId === '..') { | ||
| return 'Invalid --session-id value. "." and ".." are not allowed.'; | ||
| } |
There was a problem hiding this comment.
The current validation for the --session-id flag is vulnerable to path traversal attacks. While it correctly rejects . and .., it fails to block other path traversal sequences like / or \. The sessionId is used to construct file paths in critical areas such as the Storage class and during session cleanup (e.g., in deleteSessionArtifactsAsync). An attacker could exploit this by providing a malicious session ID (e.g., ../../etc/passwd) to read, write, or delete files outside the intended directory. To prevent this, implement a stricter validation that only permits safe characters, such as alphanumeric characters, hyphens, and underscores.
| if (trimmedSessionId === '.' || trimmedSessionId === '..') { | |
| return 'Invalid --session-id value. "." and ".." are not allowed.'; | |
| } | |
| if (!/^[a-zA-Z0-9_-]+$/.test(trimmedSessionId)) { | |
| return 'Invalid --session-id value. Only alphanumeric characters, hyphens, and underscores are allowed.'; | |
| } |
References
- Sanitize file paths extracted from untrusted sources, such as command output, to prevent path traversal (
..), null byte injection (\0), and other vulnerabilities. - Sanitize user-provided file paths used in file system operations to prevent path traversal vulnerabilities.
Summary
--session-idCLI flag so callers can start a new session with a deterministic ID (for orchestration use cases), and also resume them later with --resumeDetails
changes
--session-id <id>to CLI argument parsing (config.ts)sessionIdtoCliArgs--session-id-> trims whitespace, rejects empty values, rejects "." and ".." values--resumewith--session-idin same invocationtests
parseArguments:--session-id--session-id--session-id+--resumegemini.tsx:sessionIdis passed toloadCliConfigsessionIddocs
incompatibility with --resume.
Related Issues
Closes #20847
How to Validate
From repo root:
npm run test -w @google/gemini-cli -- src/config/config.test.ts--resume.
Pre-Merge Checklist