T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/main.py:57
- Finding
- Solid-component quantities are inflated by a factor of 1,000<![CDATA[ ## Vulnerability Details **File Location**: `scripts/main.py`, lines 57–64 **Vulnerability Type**: Incorrect unit conversion in safety-relevant calculations **Risk Level**: High ### Vulnerable Code ```python if unit == "mM": # Calculate grams needed moles = conc * final_volume_ml / 1000 # mmol to mol grams = moles * mw results.append({ "component": component, "amount_mg": round(grams * 1000, 2), "amount_g": round(grams, 3), ``` ### Technical Analysis The conversion from millimolar concentration and milliliter volume is incorrect. Multiplying `mM` by `mL` and dividing by 1,000 produces millimoles, not moles. The value must be divided by 1,000,000 before it can be multiplied by molecular weight in grams per mole. For example, 137 mM NaCl in 1,000 mL should require approximately 8.006 g: ```text 137 mM × 1,000 mL × 58.44 g/mol ÷ 1,000,000 = 8.006 g ``` The implementation instead reports approximately 8,006 g, which is 1,000 times too large. This affects every solid component represented in millimolar units. ### Attack Path 1. A user requests a routine recipe such as 1X PBS. 2. The calculator processes each solid component using the incorrect conversion. 3. Millimoles are treated as moles. 4. The generated mass is inflated by a factor of 1,000. 5. The calculator presents the result as a valid preparation instruction. 6. A user relying on the output may attempt to weigh or use the incorrect quantity. No attacker gains operating-system privileges through this defect. The exploitation path concerns the integrity and safety of laboratory calculations. ### Impact Assessment The defect can generate unusable formulations, cause significant reagent waste, exceed solubility or equipment limits, and expose users to unexpectedly large chemical quantities. It affects all PBS, RIPA, and TAE solid components calculated by the program. The scope is limited to calculation integrity and downstream laboratory activity. ...[truncated 100 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Correct the conversion so that millimolar concentration and milliliter volume are converted to moles: ```python moles = conc * final_volume_ml / 1_000_000 grams = moles * mw ``` Alternatively, calculate millimoles explicitly and convert them to grams: ```python millimoles = conc * final_volume_ml / 1000 grams = millimoles * mw / 1000 ``` Add automated tests using independently verified formulations, including: - 1 L of 1X PBS - 500 mL of 1X RIPA - 1 L of 1X and 10X TAE - Scaling checks confirming that doubling volume doubles every quantity - Unit tests checking both `amount_g` and `amount_mg` For safety-relevant output, include a warning when a calculated quantity is implausibly large relative to the requested final volume. ]]>
