T09 · Insecure Skill Coding Practices
- Location
scripts/settle_up.py:42- Finding
Documented Inline Comments Are Parsed as Expense Participants
- Content
View full analysis
list[Expense]: expenses = [] for lineno, raw in enumerate(text.splitlines(), 1): line = raw.strip() if not line or line.startswith("#"): continue parts = [p.strip() for p in line.split(",") if p.strip()] if len(parts) < 3: raise ValueError(f"line {lineno}: need payer,amount,participants — got {line!r}") payer, amount = parts[0], parse_amount(parts[1]) # participants: space-separated within one field, or extra CSV fields people = [p for chunk in parts[2:] for p in chunk.split()] if not people: raise ValueError(f"line {lineno}: no participants in {line!r}") if len(set(people)) != len(people): raise ValueError(f"line {lineno}: duplicate participant in {line!r}") expenses.append(Expense(payer, amount, people)) if not expenses: raise ValueError("ledger is empty") return expenses ``` The README explicitly recommends input containing inline comments: ```text Ana,450,Ana Ben Cho Dan # hotel Ben,120,Ben Cho # taxi Cho,80,Ana Ben Cho Dan # groceries Dan,60,Ben Cho Dan # gas ``` ### Technical Analysis The parser ignores a comment only when the entire trimmed line begins with `#`. It does not remove an inline comment before splitting the participant field. For the documented line: ```text Ana,450,Ana Ben Cho Dan # hotel ``` the participant expression is split on whitespace and becomes: ```text Ana, Ben, Cho, Dan, #, hotel ``` The tokens `#` and `hotel` are therefore treated as real participants and receive shares of the expense. This changes every legitimate participant ...[truncated 1488 chars]- Remediation
View remediation
