CY0-001 practice question 14 of 35

Security logs from a Python-based Jupyter environment indicate that a generative AI assistant used by developers is generating code snippets that…

Full set: 484 questions
Security logs from a Python-based Jupyter environment indicate that a generative AI assistant used by developers is generating code snippets that include unvalidated strings from the model's output. An attacker successfully manipulated the model into generating a payload that, when rendered in the developer's web-based IDE, executed a malicious script to steal session cookies. Which of the following actions represents the MOST eeective compensating control to mitigate this specific vulnerability?
Answer options
A: Implement Strict Input Sanitization for developer prompts
B: Apply context-aware output encoding on the application side Correct answer
C: Increase the Model Temperature to improve output diversity
D: Deploy a Vector Database to store approved responses
Correct Answer:
B. Apply context-aware output encoding on the application side
Explanation

The described attack is a form of Cross-Site Scripting (XSS), where the LLM is the delivery vector for the malicious script. The vulnerability lies in the web-based IDE trusting the LLM's output and rendering it without proper validation. The most effective compensating control is to apply context-aware output encoding on the application (IDE) side before rendering the content. This process converts potentially executable characters (e.g., , ") into their HTML entity equivalents (e.g., <, >, "), ensuring the browser treats the LLM's output as plain text to be displayed, not as code to be executed.

Why Incorrect

A. Input sanitization targets the prompt sent to the model. While important for preventing prompt injection, it does not fix the unsafe handling of the model's output.
C. Adjusting model temperature affects the randomness of the output but is not a security control and does not prevent the generation of malicious code.
D. A vector database is used for grounding responses via RAG, not for sanitizing arbitrary generative output to prevent XSS.

References

1. OWASP Foundation. (2023). Cross Site Scripting (XSS) Prevention Cheat Sheet. Retrieved from https://cheatsheetseries.owasp.org/cheatsheets/CrossSiteScriptingPreventionCheatSheet.html. Rule #1 is "Encode Data on Output," which is the principle of context-aware output encoding and the primary defense against XSS.

2. OWASP Foundation. (2023). OWASP Top 10 for Large Language Model Applications. (Version 1.1). The mitigation strategies for "LLM02: Insecure Output Handling" recommend treating model output as untrusted user input and applying robust sanitization and encoding, which directly supports option B.

3. Bates, D., et al. (2024). Security Best Practices for Building Applications with Large Language Models. Stanford University HAI (Human-Centered Artificial Intelligence). This paper emphasizes in its "Secure Output Handling" section that all LLM outputs should be sanitized and encoded before being used in downstream functions, especially in web contexts.

Scroll to Top