Conversation
Summary of ChangesHello @andrewwhitecdw, 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 session management capabilities by introducing the ability to name sessions and providing a dedicated tool to list and filter them. These changes aim to improve user experience by making sessions easier to identify and organize, especially when dealing with multiple concurrent or historical sessions. 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
This pull request introduces a valuable feature for naming sessions, enhancing usability, and adds the session_list tool. However, critical security concerns exist due to Markdown Injection and Prompt Injection vulnerabilities. User-supplied session names and agent names are not properly sanitized when embedded into markdown tables and tool response messages, potentially allowing attackers to spoof tool outputs or manipulate the agent's behavior. Beyond security, there are opportunities to improve session forking efficiency, and the session_list tool has discrepancies between its documentation and implementation, along with a bug in its date filtering logic.
- Update session_list docs to match implementation output - Sanitize markdown table cells (| and newlines) to prevent injection - Sanitize session/agent names in return messages to prevent prompt injection - Fix to_date filtering to include full day (set to 23:59:59.999)
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds a useful feature for naming sessions and a new tool for listing them. However, the implementation is vulnerable to markdown injection. The session_list tool constructs a markdown table, but the sanitizeForMarkdown function does not escape all special characters, potentially allowing an attacker to inject malicious links or formatting. This could lead to XSS or phishing attacks if the output is rendered in a web-based UI. Additionally, there are minor issues such as code duplication, a performance improvement opportunity, and a bug in the date filtering logic. Addressing these points will improve the code's maintainability, correctness, and security.
| sessions = sessions.filter((s) => { | ||
| const created = s.time?.created | ||
| ? new Date(s.time.created).getTime() | ||
| : 0 | ||
| return created >= fromDate | ||
| }) |
There was a problem hiding this comment.
When a session lacks a time.created property, you're defaulting its creation timestamp to 0. This can lead to incorrect filtering, as these sessions will be treated as if they were created at the Unix epoch (1970-01-01). It would be more robust to exclude sessions that don't have a creation date when filtering by date.
sessions = sessions.filter((s) => {
if (!s.time?.created) {
return false;
}
const created = new Date(s.time.created).getTime();
return created >= fromDate;
})| sessions = sessions.filter((s) => { | ||
| const created = s.time?.created | ||
| ? new Date(s.time.created).getTime() | ||
| : 0 | ||
| return created <= toTimestamp | ||
| }) |
There was a problem hiding this comment.
Similar to the from_date filter, you're defaulting to a timestamp of 0 for sessions without a creation date. This can cause incorrect filtering. These sessions should be excluded from the results when a date filter is applied.
sessions = sessions.filter((s) => {
if (!s.time?.created) {
return false;
}
const created = new Date(s.time.created).getTime();
return created <= toTimestamp;
})| const sanitizeForMarkdown = (str: string) => | ||
| str.replace(/\|/g, "\\|").replace(/\n/g, " ") |
There was a problem hiding this comment.
The sanitizeForMarkdown function is vulnerable to markdown injection. It currently only escapes the pipe character (|) and newlines, but fails to escape other critical markdown special characters such as brackets ([ and ]) or parentheses (( and )). Since session titles are user-controlled, an attacker could inject malicious markdown, potentially leading to XSS or phishing attacks if rendered in a web-based UI. Additionally, for better performance, this function should be defined once outside the map loop, rather than being redefined on every iteration.
| const sanitizeForMarkdown = (str: string) => | |
| str.replace(/\|/g, "\\|").replace(/\n/g, " ") | |
| const sanitizeForMarkdown = (str: string) => | |
| str.replace(/[\\`*_{}\[\]()#+-.!|]/g, "\\$&").replace(/\n/g, " ") |
| }) | ||
|
|
||
| return `Forked session with ${args.agent || "build"} agent - history preserved (ID: ${forkedSession.data.id})` | ||
| const sanitizeFork = (str: string) => str.replace(/\n/g, " ") |
There was a problem hiding this comment.
new feature to name sessions