cornucopia icon indicating copy to clipboard operation
cornucopia copied to clipboard

AttributeError Vulnerabilities in convert.py

Open khushal-winner opened this issue 8 months ago • 1 comments

Describe the bug

Two AttributeError vulnerabilities exist in scripts/convert.py where string methods are called on potentially None values without type checking:

  1. Line 815: if k.strip() not in el_text: - Calls .strip() on key k without verifying it's a string
  2. Line 894: if convert_vars.args.layout.lower() == "all" - Calls .lower() on args.layout without null checking

These conditions will crash the script with AttributeError: 'NoneType' object has no attribute 'strip'/'lower' when the variables contain None values.

Expected behavior

The script should handle None values gracefully without crashing. String methods should only be called after verifying the variable is actually a string, or None values should be handled appropriately.

Desktop (please complete the following information)

  • OS: All operating systems (Windows, Linux, macOS)
  • Python Version: All versions supporting the codebase
  • Script Version: Current main branch

Additional context

Line 815 vulnerability scenario:

  • Occurs when replacement_values contains None keys from malformed YAML data
  • YAML files with null keys (using ~ or null syntax) can cause this
  • Example problematic YAML:
data:
  ~: "value with null key"  # Creates None key

Line 894 vulnerability scenario:

  • Occurs if convert_vars.args.layout is manually set to None
  • Cannot happen through normal argparse usage (defaults are strings)
  • Can occur during debugging, testing, or if args are modified by other code

Impact:

  • Script crashes with AttributeError
  • Prevents document generation
  • Affects robustness when processing user-provided or potentially corrupted data

Proposed fixes:

  • Line 815: if isinstance(k, str) and k.strip() not in el_text:
  • Line 894: if convert_vars.args.layout and convert_vars.args.layout.lower() == "all" or convert_vars.args.layout == ""

These fixes maintain existing functionality while adding defensive programming against edge cases.

khushal-winner avatar Mar 03 '26 15:03 khushal-winner

I have assigned you.

sydseter avatar Mar 19 '26 14:03 sydseter