T09 · Insecure Skill Coding Practices
- Location
scripts/car_maintenance.py:253- Finding
Malformed Service History Entry Causes an Unhandled Exception
- Content
View full analysis
Vulnerability Details
File Location:
scripts/car_maintenance.py, lines 253–258
Vulnerability Type: Improper input validation leading to denial of service
Risk Level: LowVulnerable Code
python if not isinstance(entries, list): raise ValueError("--history must be a JSON list of {task, km, date} objects") resolved: dict[str, dict[str, Any]] = {} for entry in entries: raw_id = str(entry.get("task", "")).strip()Technical Analysis
The
resolve_historyfunction verifies that the decoded top-level JSON value is a list, but it does not verify that each member of that list is an object.Consequently, valid JSON inputs such as
[null],[1],["value"], or[[]]pass the top-level validation. The code then invokesentry.get(...)on a value that does not implement the dictionarygetmethod, causing anAttributeError.The exception is not converted into a controlled validation error. The
mainfunction only catchesValueError, so the process exits unexpectedly and can expose a Python traceback to the caller.Attack Path
-
An attacker or malformed upstream integration controls the value passed to
--history. -
The attacker supplies a syntactically valid JSON list containing a non-object value, for example:
bash python3 scripts/car_maintenance.py status \ --km 84500 \ --in-service 2021-03-10 \ --history '[null]' -
json.loads()successfully decodes the input as a list. -
The top-level
isinstance(entries, list)check succeeds. -
The loop assigns
Nonetoentry. -
entry.get("task", "")raises an unhandledAttributeError. -
The command terminates without producing the requested maintenance report.
Impact Assessment
Exploitation causes denial of service for the affected local CLI invocation. This can interrupt an automated Agent workflow that forwards untrusted or malformed service-history data t ...[truncated 237 chars]
-
- Remediation
View remediation
Remediation Suggestions
Validate every history-list member before accessing dictionary methods. Reject invalid entries with a controlled
ValueErrorthat identifies the offending array index:python resolved: dict[str, dict[str, Any]] = {} for index, entry in enumerate(entries): if not isinstance(entry, dict): raise ValueError( f"--history entry at index {index} must be an object " "containing task, km, and date fields" ) raw_id = str(entry.get("task", "")).strip()Additional hardening should include:
- Validate that
taskis a non-empty string. - Validate
kmas a non-negative integer and reject booleans, negative values, and unreasonable magnitudes. - Validate that history dates are not before the in-service date or after the effective current date, where appropriate.
- Convert expected input-conversion failures into controlled
ValueErrormessages without tracebacks. - Add regression tests for
[null],[1],["value"],[[]], and mixed valid/invalid arrays. - Verify that all malformed cases return exit code
2and a concise error on standard error.
- Validate that
