T09 · Insecure Skill Coding Practices
- Location
scripts/roll.py:11- Finding
Unbounded Dice Count Permits Resource Exhaustion
- Content
View full analysis
Vulnerability Details
File Location:
scripts/roll.py, lines 11–26
Vulnerability Type: Uncontrolled resource consumption
Risk Level: MediumVulnerable Code:
python count, sides = int(m.group(1)), int(m.group(2)) sign = m.group(3) mod = int(m.group(4)) if m.group(4) else 0 if sign == "-": mod = -mod keep = int(m.group(5)) if m.group(5) else None if count < 1 or sides < 2: raise ValueError("Need at least 1 die and 2 sides.") if keep and keep > count: raise ValueError("Cannot keep more dice than rolled.") rng = random.Random(seed) rolls = [rng.randint(1, sides) for _ in range(count)]Technical Analysis
The dice count is derived directly from user-controlled notation and has no upper bound. Although the code verifies that at least one die is requested, it does not impose a practical maximum before using
countto construct therollslist.A sufficiently large count causes the list comprehension to perform excessive iterations and allocate substantial memory. Extremely long numeric fields may also consume computational resources during integer conversion before the rolling loop begins. This creates a local denial-of-service condition through uncontrolled CPU and memory consumption.
Attack Path
- An attacker submits dice notation containing an extremely large count, such as a value conceptually equivalent to
999999999d6. - The regular expression accepts the count because
\d+has no maximum length. - The application converts the captured value to an integer without enforcing an upper bound.
- The list comprehension attempts to generate and retain
countrandom values. - The process experiences excessive CPU and memory consumption and may become unresponsive or be terminated by the operating system.
Impact Assessment
Exploitation does not grant additional privileges, access to sensitive data, or code execution. Its impact is limit ...[truncated 229 chars]
- An attacker submits dice notation containing an extremely large count, such as a value conceptually equivalent to
- Remediation
View remediation
Remediation Suggestions
Enforce explicit limits before allocating or iterating. The limits should reflect the legitimate use case and execution environment. For example:
python MAX_SPEC_LENGTH = 100 MAX_DICE = 10_000 MAX_SIDES = 1_000_000 if len(spec) > MAX_SPEC_LENGTH: raise ValueError("Dice notation is too long.") if not 1 <= count <= MAX_DICE: raise ValueError(f"Dice count must be between 1 and {MAX_DICE}.") if not 2 <= sides <= MAX_SIDES: raise ValueError(f"Die sides must be between 2 and {MAX_SIDES}.")Apply the input-length check before regular-expression matching and integer conversion. Also consider execution-level CPU and memory limits as defense in depth when the Skill is exposed to untrusted requests. Add tests confirming that oversized counts, side values, and notation strings are rejected without starting roll generation.
