T09 · Insecure Skill Coding Practices
- Location
cronexplain.py:8- Finding
Unbounded Cron Field Expansion Allows Local Denial of Service
- Content
View full analysis
Vulnerability Details
File Location:
cronexplain.py:8-30and identical copyscripts/cronexplain.py:8-30
Vulnerability Type: Unvalidated numeric ranges and steps causing resource exhaustion or process crashes
Risk Level: MediumVulnerable Code
python def parse_field(field, name, min_val, max_val): """Parse a cron field into a set of values.""" values = set() for part in field.split(","): if "/" in part: range_part, step = part.split("/", 1) step = int(step) if range_part == "*": start, end = min_val, max_val elif "-" in range_part: start, end = map(int, range_part.split("-", 1)) else: start, end = int(range_part), max_val values.update(range(start, end + 1, step)) elif "-" in part: start, end = map(int, part.split("-", 1)) values.update(range(start, end + 1)) elif part == "*": values.update(range(min_val, max_val + 1)) else: values.add(int(part)) return sorted(values)Technical Analysis
parse_field()accepts numeric values, range endpoints, and step values directly from command-line input without enforcing the field-specific bounds supplied throughmin_valandmax_val.For example, a minute field is expected to remain between
0and59, but an expression such as0-1000000000 * * * *causes the program to iterate over the entire attacker-controlled range and insert its values into a set. This can consume excessive CPU and memory until the process or host terminates it.Step values are also not validated. A step of zero, such as
*/0, reachesrange(..., step)and raises an uncaughtValueError. Negative steps and reversed or out-of-bounds ranges are likewise not handled through controlled validation.Both executable copies contain th ...[truncated 1543 chars]
- Remediation
View remediation
Remediation Suggestions
- Validate every parsed value against the field-specific
min_valandmax_valbefore constructing or expanding a range. - Require range endpoints to be ordered and contained within the permitted field bounds.
- Require step values to be positive integers and reject zero or negative steps.
- Reject empty list components, malformed integers, multiple separators, and excessively long expressions with controlled error messages.
- Avoid expanding any range until its expected size has been checked against a small fixed limit.
- Catch
ValueErrorand related parsing exceptions at the command-line boundary and exit with a nonzero status instead of exposing a traceback. - Apply the same fix to both script copies, or remove the duplicate implementation and maintain a single canonical executable.
- Add regression tests covering huge endpoints,
*/0, negative steps, reversed ranges, out-of-bounds individual values, and malformed list elements.
A hardened range check should follow this pattern:
python def validate_range(start, end, step, min_val, max_val): if step <= 0: raise ValueError("step must be a positive integer") if not (min_val <= start <= end <= max_val): raise ValueError( f"range must be between {min_val} and {max_val}" )Validation must occur before calling
range()or adding values to the set.- Validate every parsed value against the field-specific
