T09 · Insecure Skill Coding Practices
Error
- Location
scripts/quantum_nav.py:50- Finding
Non-Finite Sensor Input Causes the Safety Decision to Fail Open
- Content
View full analysis
bright, port 2 -> dark (depending on BS phase) # We assume standard BS where equal inputs -> port 0 activates. diff = intensities[0] - intensities[1] # Derived physics: diff = 2 * sin(phi_a - phi_b) # We want Kernel = 1 when diff = 0 (identical phases) # We use a linear decay based on the interference contrast # Range of diff is [-2, 2]. similarity = 1.0 - (0.5 * np.abs(diff)) kernel_sum += similarity return kernel_sum / len(vec_a) ``` ```python def decide_action(self, sensor_input): scores = self.classify_terrain(sensor_input) best_match = max(scores, key=scores.get) confidence = scores[best_match] print("\n--- Quantum Kernel Analysis ---") for t, s in scores.items(): print(f" {t}: {s:.4f}") print(f"\nBest Match: {best_match} (Confidence: {confidence:.4f})") # SAFETY FAILSAFE if confidence < self.safety_threshold: return ">>> TRIGGERING FAILSAFE: SAFE MODE (UNCERTAIN TERRAIN) <<<" if "SAFE" in best_match: return f"Action: PROCEED (Terrain is {best_match})" else: return f"Action: AVOID / HALT (Detected {b ...[truncated 3000 chars]- Remediation
View remediation
>> TRIGGERING FAILSAFE: SAFE MODE (INVALID CLASSIFICATION) <<<" ``` 3. Make the safety check explicitly fail closed: ```python if not math.isfinite(float(confidence)) or confidence < self.safety_threshold: return ">>> TRIGGERING FAILSAFE: SAFE MODE (UNCERTAIN TERRAIN) <<<" ``` 4. Use exact terrain-state comparisons rather than substring matching: ```python if best_match == "SAFE_FLAT": return f"Action: PROCEED (Terrain is {best_match})" return f"Action: AVOID / HALT (Detected {best_match})" ``` 5. Treat parsing, dimensional, simulation, and scoring errors as safety events. Catch relevant exceptions at the application boundary and return safe mode or halt rather than continuing or crashing. 6. Add regression tests for `nan`, `inf`, `-inf`, empty input, vectors of incorrect length, out-of-range values, and non-finite intermediate scores. Every invalid or anomalous case should deterministically produce a halt or safe-mode decision. ]]>
