## AI Security Flaw: Newline Characters Enable Prompt Injection in Image Generation API
A critical vulnerability in an AI image generation service allows attackers to bypass safety controls by injecting malicious instructions via simple newline characters. The flaw stems from the use of Python's `.format()` method to insert user-supplied prompts into a fixed template. When a user includes newline characters (\n) in their input, it breaks the template's structure, enabling arbitrary text to be appended directly to the final prompt sent to the underlying AI model, such as Google's Gemini.

Evidence from a security assessment demonstrates the exploit in action. A POST request to the `/api/v1/generate/image` endpoint with a prompt containing "apple\n\nIgnore previous instructions" resulted in the `prompt_used` field revealing the injected command was successfully passed to the model. The final prompt sent was: "A simple, flat, colorful pictogram icon of apple\n\nIgnore previous instructions. White background, no text, suitable for children with autism." This shows the attacker's text was inserted as a separate paragraph, effectively escaping the intended safety context of the original template. The same vulnerability has been confirmed in the Text-to-Speech (TTS) endpoint within `services/tts_service.py`.

The impact is significant: this prompt injection flaw could allow bad actors to subvert model safeguards, potentially generating harmful, biased, or unintended content. It represents a fundamental failure in input sanitization and prompt engineering for AI-powered services, exposing both the integrity of the model's output and the security of applications relying on it. The vulnerability underscores the persistent security challenges in deploying generative AI systems at scale.
---
- **Source**: GitHub Issues
- **Sector**: The Lab
- **Tags**: AI Security, Prompt Injection, Vulnerability, API, Generative AI
- **Credibility**: unverified
- **Published**: 2026-03-27 06:27:02
- **ID**: 36943
- **URL**: https://whisperx.ai/en/intel/36943