feat: add current date and time to system instructions in the sample travel app#713
feat: add current date and time to system instructions in the sample travel app#713juan-vgv wants to merge 1 commit intoflutter:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds the current date and time to the system prompt to provide the LLM with better context for relative date queries. While this is a good feature, a high-severity Prompt Injection vulnerability has been identified where user input is sent to the LLM without sanitization, potentially allowing attackers to override instructions. Additionally, the current date implementation determines the date only once at app startup, which can lead to stale date information in long-running sessions.
|
|
||
| final prompt = | ||
| ''' | ||
| Today is ${DateTime.timestamp()} |
There was a problem hiding this comment.
This line is part of a broader context vulnerable to Prompt Injection. User-provided input from the chat is passed directly to the LLM without sanitization (see _sendPrompt and _triggerInference), allowing attackers to override instructions. Remediation includes implementing input sanitization on user-provided text and considering instruction defense. Furthermore, the prompt is a final top-level variable, causing DateTime.timestamp() to be evaluated only once. This means the date can become stale in long-running app sessions, potentially leading to incorrect responses for relative date queries. Consider changing prompt to a getter to ensure the date is fresh if the widget state is recreated.
Description
Add current date and time to the system instructions in the sample travel app.
This provides the LLM with relevant context when processing user messages with relative date / time information such "Show me available options for a family trip to London next Easter".
Noticed this when running the app and the LLM was returning dates set in 2024.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-devrel channel on Discord.