T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/create_inbox.py:34
- Finding
- Mailbox credentials are generated using a non-cryptographic pseudorandom generator<![CDATA[ ## Vulnerability Details **File Location**: `scripts/create_inbox.py:34-38,44-47`; `scripts/e2e_otp.py:37-41,47-50` **Vulnerability Type**: Predictable credential generation **Risk Level**: Medium ### Vulnerable Code `scripts/create_inbox.py:34-38,44-47` ```python def random_local_part(): word1 = random.choice(WORDS) word2 = random.choice(WORDS) digits = "".join(random.choices(string.digits, k=4)) return f"{word1}.{word2}.{digits}" domain = domains[0]["domain"] local = random_local_part() requested_address = f"{local}@{domain}" password = "Tmp!" + "".join(random.choices(string.ascii_letters + string.digits, k=12)) ``` `scripts/e2e_otp.py:37-41,47-50` ```python def random_local_part(): word1 = random.choice(WORDS) word2 = random.choice(WORDS) digits = "".join(random.choices(string.digits, k=4)) return f"{word1}.{word2}.{digits}" domain = domains[0]["domain"] local = random_local_part() requested_address = f"{local}@{domain}" password = "Tmp!" + "".join(random.choices(string.ascii_letters + string.digits, k=12)) ``` ### Technical Analysis Both scripts use Python's `random` module to generate mailbox passwords and address components. This module implements a deterministic pseudorandom number generator and is explicitly unsuitable for passwords, authentication tokens, or other security-sensitive values. If an attacker can recover or sufficiently constrain the generator state through another exposure in the same process or execution environment, subsequent values may be predictable. The generated password protects access to messages that may contain verification links and one-time passwords. The address also has limited entropy because it consists of two words from a fixed list and four decimal digits. Address predictability alone does not grant mailbox access, but it can make targeted account discovery easier. ### Attack Path 1. A victim runs `create_inbox.py` or `e2e_otp.py`, generating a mailbox password with ...[truncated 1139 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Replace all security-sensitive uses of `random` with Python's `secrets` module. - Generate passwords with sufficient entropy, for example: ```python import secrets import string alphabet = string.ascii_letters + string.digits password = "Tmp!" + "".join(secrets.choice(alphabet) for _ in range(20)) ``` - Use `secrets.choice()` for address components if address unpredictability is desired. - Alternatively, use `secrets.token_urlsafe()` to generate both the local address component and password. - Keep the address human-readable only if required; human-readable word lists reduce the address search space. - Add tests that prevent future credential-generation code from using `random`, timestamps, process identifiers, or other predictable values. ]]>
