T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/main.py:48
- Finding
- Unsafe Fail-Open Chemical Classification Can Produce Hazardous Storage Guidance<![CDATA[ ## Vulnerability Details **File Location**: `scripts/main.py:48-75` **Vulnerability Type**: Unsafe fail-open classification and incomplete input validation **Risk Level**: High ### Complete Code Snippet ```python def classify_chemical(self, name): """Classify chemical into storage group.""" name_lower = name.lower() for group, data in self.COMPATIBILITY_GROUPS.items(): for example in data["examples"]: if example.lower() in name_lower: return group # Check keywords acid_keywords = ["acid", "hcl", "sulfuric", "nitric", "acetic"] base_keywords = ["hydroxide", "naoh", "koh", "ammonia", "amine"] flammable_keywords = ["ethanol", "methanol", "acetone", "ether", "hexane"] oxidizer_keywords = ["peroxide", "permanganate", "hypochlorite", "nitrate"] if any(k in name_lower for k in acid_keywords): return "acids" elif any(k in name_lower for k in base_keywords): return "bases" elif any(k in name_lower for k in flammable_keywords): return "flammables" elif any(k in name_lower for k in oxidizer_keywords): return "oxidizers" return "general" ``` ### Technical Analysis The classifier relies on case-insensitive substring matching and silently assigns every unrecognized chemical to the `general` storage group. In a safety-critical classification system, this is an unsafe fail-open behavior: absence of a recognized keyword is treated as evidence that a chemical is low risk. The implementation also returns the first matching group and therefore cannot represent multiple hazards or select the most restrictive applicable storage category. For example, nitric acid appears among the acid examples and is returned as `acids` before its oxidizing properties can be considered. Toxic-specific classification keywords are absent, meaning a name such as `Sodium cyanide` is not reliably assigned to `toxics` and can fall through to `general`. ...[truncated 1447 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Replace the `general` fallback with an explicit `unknown` or `manual_review` classification. 2. Do not issue storage recommendations for unknown chemicals until identity and hazards have been verified. 3. Use authoritative SDS or CAS-based hazard data rather than chemical-name substrings as the primary classification source. 4. Represent all applicable hazards for a chemical and implement a documented rule for choosing the most restrictive storage category. 5. Add explicit toxic, reducing-agent, sulfide, cyanide, halogenated-compound, water-reactive, and pyrophoric classifications where supported. 6. Normalize names carefully and require exact aliases or structured identifiers rather than unrestricted substring matches. 7. Validate input type, reject empty names, and flag malformed or ambiguous values. 8. Add regression tests for sodium cyanide, nitric acid, mixtures, alternate names, typographical errors, unknown chemicals, and chemicals with multiple hazards. 9. Clearly state that automated results require confirmation against the current SDS and institutional EHS rules. ]]>
