T09 · Insecure Skill Coding Practices
- Location
generate-book-article.py:104- Finding
Stored HTML and JavaScript Injection in Generated Articles and Bookshelf Pages
- Content
View full analysis
str: """为单张卡片生成 HTML。""" number = card.get('number', '') book_title = card.get('book_title', '') book_info = card.get('book_info', '') quotes = card.get('quotes', []) # 构建金句列表 quote_parts = [] for j, q in enumerate(quotes): idx = q.get('index', f'{j + 1:02d}') text = q.get('text', '') quote_parts.append( QUOTE_ITEM_TEMPLATE.replace('{INDEX}', idx).replace('{TEXT}', text) ) if j < len(quotes) - 1: quote_parts.append(QUOTE_SEPARATOR) quotes_html = '\n'.join(quote_parts) if quote_parts else '' return (CARD_TEMPLATE .replace('{NUMBER}', number) .replace('{BOOK_TITLE}', book_title) .replace('{BOOK_INFO}', book_info) .replace('{QUOTES}', quotes_html)) ``` Additional direct substitutions in `generate-book-article.py:190-248` include: ```python title = data.get('title', '') if data.get('title_line2'): line2 = data['title_line2'] line2 = (line2 .replace('{count}', str(total_cards)) .replace('{all_quotes}', str(total_all_quotes)) .replace('{quotes}', str(total_quotes))) title += '
' + line2 html = html.replace('{{TITLE}}', title) html = html.replace('{{SUBTITLE}}', data.get('subtitle', '')) intro = data.get('intro_paragraphs', []) html = html.replace('{{INTRO_PARAGRAPH_1}}', intro[0] if len(intro) > 0 else '') html = html.replace('{{INTRO_PARAGRAPH_2}}', intro[1] if len(intro) > 1 else '') if gq_0: html = html.replace('{{GOLD_QUOTE_1}}', gq_0.get('text', '')) html = html.replace('{{GOLD_QUOTE_1_SOUR ...[truncated 4011 chars]- Remediation
View remediation
` must be supported, sanitize input with a strict allowlist rather than exempting the entire value from escaping. 5. Validate the JSON schema and reject unexpected objects, arrays, markup-bearing values, and excessively large strings. 6. Remove inline event handlers where possible and attach events from static JavaScript. 7. Add a restrictive Content Security Policy that blocks inline scripts and event handlers, for example through an appropriate `` policy for local HTML. 8. Add regression tests using payloads in every rendered field and verify that payloads appear as text rather than executable markup. ]]>
