"""Scenario 5: HTML injection defense in chat messages.""" import pytest from helpers import SEL XSS_PAYLOAD = ( 'Here is some content: and ' ' and ' ' end of content.' ) async def test_html_injection_sanitized(page): """XSS vectors in assistant messages should be sanitized by renderMarkdown.""" # Inject an assistant message with XSS vectors directly via JS. # This tests the sanitization pipeline (renderMarkdown → sanitizeRenderedHtml) # without depending on the full LLM round-trip. await page.evaluate( "content => addMessage('assistant', content)", XSS_PAYLOAD ) assistant_msg = page.locator(SEL["message_assistant"]).last await assistant_msg.wait_for(state="visible", timeout=5000) inner_html = await assistant_msg.inner_html() # Script tags must be stripped assert "