T09 · Insecure Skill Coding Practices
- Location
amazon_competitor_analyzer.py:195- Finding
Spreadsheet Formula Injection in Generated CSV Reports
- Content
View full analysis
Vulnerability Details
File Location:
amazon_competitor_analyzer.py, lines 195-216
Vulnerability Type: CSV formula injection
Risk Level: MediumVulnerable Code
python with open(output_path, 'w', newline='', encoding='utf-8') as f: writer = csv.writer(f) writer.writerow([ 'ASIN', 'Product Title', 'Brand', 'Price ($)', 'Original Price ($)', 'Discount (%)', 'Rating', 'Reviews Count', 'Weight', 'Features' ]) for asin, data in products.items(): if data: try: product = data.get('results', {}).get('products', [{}])[0] writer.writerow([ asin, product.get('product_info', {}).get('title', 'N/A')[:100], product.get('product_info', {}).get('brand', 'N/A'), product.get('pricing', {}).get('current_price', 'N/A'), product.get('pricing', {}).get('original_price', 'N/A'), product.get('pricing', {}).get('discount_percent', 'N/A'), product.get('reviews', {}).get('average_rating', 'N/A'), product.get('reviews', {}).get('total_count', 'N/A'), product.get('specifications', {}).get('weight', 'N/A'), ', '.join(product.get('specifications', {}).get('features', [])[:5]) ])Technical Analysis
The report generator writes externally sourced Amazon product data directly into CSV cells without neutralizing spreadsheet formula prefixes. Fields such as the product title, brand, weight, and features may be influenced by marketplace sellers or by compromised upstream scraping results.
A value beginning with
=,+,-, or@can be treated as a formula when the CSV file is opened in spreadsheet software. Standard CSV quoting controls field boundaries but does not prevent formula evaluation.D ...[truncated 1383 chars]
- Remediation
View remediation
Remediation Suggestions
Introduce a centralized CSV-cell sanitizer and apply it to every string originating from user input or external services.
python def safe_csv_cell(value): if value is None: return "N/A" text = str(value) if text.startswith(("=", "+", "-", "@")): return "'" + text return textApply the function to the ASIN, product title, brand, weight, features, and any other value that may be represented as text:
python writer.writerow([ safe_csv_cell(asin), safe_csv_cell(product.get('product_info', {}).get('title', 'N/A')[:100]), safe_csv_cell(product.get('product_info', {}).get('brand', 'N/A')), safe_csv_cell(product.get('pricing', {}).get('current_price', 'N/A')), safe_csv_cell(product.get('pricing', {}).get('original_price', 'N/A')), safe_csv_cell(product.get('pricing', {}).get('discount_percent', 'N/A')), safe_csv_cell(product.get('reviews', {}).get('average_rating', 'N/A')), safe_csv_cell(product.get('reviews', {}).get('total_count', 'N/A')), safe_csv_cell(product.get('specifications', {}).get('weight', 'N/A')), safe_csv_cell(', '.join( product.get('specifications', {}).get('features', [])[:5] )) ])Also add tests covering all common formula prefixes, leading whitespace, tabs, carriage returns, and newline-prefixed formulas. Document that generated reports contain untrusted marketplace content.
