T09 · Insecure Skill Coding Practices
- Location
scripts/main.py:14- Finding
Empty Contact Name Causes an Unhandled IndexError
- Content
View full analysis
Vulnerability Details
File Location:
scripts/main.py:14-17,scripts/main.py:31-34, andscripts/main.py:45-50
Vulnerability Type: Improper input validation and unhandled exception
Risk Level: LowThe command-line parser requires the
--contactoption to be present but does not ensure that its value contains a non-whitespace name. The formal email and LinkedIn code paths index the result ofcontact_name.split()without first confirming that the resulting list contains an element.Relevant formal-email code:
python def draft_email(self, contact_name, conference, topic, your_name, tone="professional"): """Draft a follow-up email.""" if tone == "formal": greeting = f"Dear Dr. {contact_name.split()[-1]},"Relevant LinkedIn-message code:
python def draft_linkedin_connect(self, contact_name, conference, topic): """Draft LinkedIn connection message.""" message = f"""Hi {contact_name.split()[0]}, it was great meeting you at {conference}. I'd love to stay connected and continue our discussion about {topic}.""" return messageRelevant argument declaration:
python parser.add_argument("--contact", "-c", required=True, help="Contact name") parser.add_argument("--conference", "-conf", required=True, help="Conference name") parser.add_argument("--topic", "-t", required=True, help="Discussion topic") parser.add_argument("--name", "-n", default="[Your Name]", help="Your name") parser.add_argument("--tone", choices=["formal", "casual", "professional"], default="professional", help="Email tone") parser.add_argument("--linkedin", action="store_true", help="Generate LinkedIn message")Technical Analysis
In Python, calling
split()on an empty or whitespace-only string returns an empty list. Accessing either index[-1]or[0]on that list raisesIndexError.The
required=Truesetting only verifies that ...[truncated 1642 chars]- Remediation
View remediation
Remediation Suggestions
Normalize and validate all required text inputs before constructing a draft:
python def non_empty_text(value): normalized = value.strip() if not normalized: raise argparse.ArgumentTypeError("value must not be empty") return normalized parser.add_argument( "--contact", "-c", required=True, type=non_empty_text, help="Contact name", )Apply equivalent validation to
--conferenceand--topic, and consider applying it to--namewhen explicitly supplied.As defense in depth, avoid indexing split results without validation:
python name_parts = contact_name.split() if not name_parts: raise ValueError("Contact name must not be empty")Convert validation failures into concise command-line errors through
ArgumentParser.error()orArgumentTypeErrorrather than exposing a traceback. Add automated tests covering:- Empty contact names
- Whitespace-only contact names
- Formal email generation
- Casual email generation
- LinkedIn message generation
- Valid single-component and multi-component names
