T09 · Insecure Skill Coding Practices
- Location
scripts/get_google_maps_leads.py:83- Finding
CSV Formula Injection Through Unsanitized Google Maps Listing Data
- Content
View full analysis
Vulnerability Details
File Location:
scripts/get_google_maps_leads.py, lines 49–69 and 83–88
Vulnerability Type: CSV formula injection
Risk Level: MediumVulnerable Code
python name = name_elem.get_attribute('data-item-title') if name_elem else '' info = {'name': name, 'phone': '', 'address': '', 'website': '', 'email': ''} try: phone = driver.find_element(By.CSS_SELECTOR, 'button[data-item-phone]') info['phone'] = phone.get_attribute('data-item-phone') if phone else '' except Exception: pass try: address = driver.find_element(By.CSS_SELECTOR, 'div[data-item-address]') info['address'] = address.get_attribute('data-item-address') if address else '' except Exception: pass try: website = driver.find_element(By.CSS_SELECTOR, 'a[data-item-website]') info['website'] = website.get_attribute('data-item-website') if website else '' except Exception: passpython def save_to_csv(results, filename='leads.csv'): with open(filename, 'w', newline='', encoding='utf-8') as f: writer = csv.DictWriter(f, fieldnames=['name', 'phone', 'address', 'website', 'email']) writer.writeheader() writer.writerows(results) print(f"Saved {len(results)} rows to {filename}")Technical Analysis
Business names, phone numbers, addresses, and website values are obtained from Google Maps and written directly into a CSV file without spreadsheet-oriented sanitization. These values are externally controlled because a Google Maps listing owner can influence the contents of the listing.
Python's
csv.DictWritercorrectly handles CSV quoting, but CSV quoting does not prevent spreadsheet formula interpretation. Spreadsheet applications may treat a cell beginning with=,+,-, or@as a formula when the generated file is opened.An attacker could therefore place a formula-like value in a listing field. If that listing ...[truncated 1595 chars]
- Remediation
View remediation
Remediation Suggestions
Sanitize every externally sourced value before writing it to CSV. In particular:
- Convert values to strings and check their first non-whitespace character.
- Prefix values beginning with
=,+,-, or@with an apostrophe or another safe neutralizing character. - Consider tab and carriage-return prefixes because some spreadsheet applications ignore leading control characters before evaluating formulas.
- Apply the protection to all exported columns, not only the business name.
- Document that the output contains untrusted third-party data.
Example hardening:
python def sanitize_csv_cell(value): value = '' if value is None else str(value) if value.lstrip().startswith(('=', '+', '-', '@')): return "'" + value return value def save_to_csv(results, filename='leads.csv'): safe_results = [ {key: sanitize_csv_cell(value) for key, value in row.items()} for row in results ] with open(filename, 'w', newline='', encoding='utf-8') as f: writer = csv.DictWriter( f, fieldnames=['name', 'phone', 'address', 'website', 'email'] ) writer.writeheader() writer.writerows(safe_results)
