T09 · Insecure Skill Coding Practices
- Location
SKILL.py:80- Finding
Delta compression silently discards changes in four monitored dimensions
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.py, lines 80-104
Vulnerability Type: Incomplete state comparison causing loss of security-relevant timeline data
Risk Level: Highpython def inject_6_elements_timeline(unit_id, full_6_elements_state): """ ⏳ 环境六要素注入引擎:完全继承 Phase 1 的数据模型,并执行压缩法则 """ conn = sqlite3.connect(DB_PATH) cursor = conn.cursor() ts = datetime.now() # 提取六要素的 JSON 字符串以便对比与存储 e1 = json.dumps(full_6_elements_state.get("element_1_light", {})) e2 = json.dumps(full_6_elements_state.get("element_2_air_hvac", {})) e3 = json.dumps(full_6_elements_state.get("element_3_sound", {})) e4 = json.dumps(full_6_elements_state.get("element_4_electromagnetic", {})) e5 = json.dumps(full_6_elements_state.get("element_5_energy", {})) e6 = json.dumps(full_6_elements_state.get("element_6_visual", {})) # 模拟获取上一分钟状态进行 Delta 压缩比对 cursor.execute("SELECT element_1_light, element_2_air_hvac FROM env_timeline WHERE unit_id=? ORDER BY timestamp DESC LIMIT 1", (unit_id,)) last_state = cursor.fetchone() is_compressed = False if last_state: # 如果光和空气等核心要素的 JSON 完全一致,触发压缩折叠 if last_state[0] == e1 and last_state[1] == e2: is_compressed = True print(f" [Delta Compression] 6-Element payload is identical to previous minute in Unit {unit_id}. Folded. (六要素数据模型未变化,触发压缩)") conn.close() return "COMPRESSED_SKIP"Technical Analysis
The function receives and serializes six environmental dimensions, but its compression decision retrieves and compares only
element_1_lightandelement_2_air_hvac. Changes to sound, electromagnetic conditions, energy, or visual state are therefore ignored whenever light and HVAC remain unchanged.The function then returns
COMPRESSED_SKIPwithout writing the changed state to SQLite. This is a fail-open data-inte ...[truncated 1692 chars]- Remediation
View remediation
Remediation Suggestions
- Retrieve and compare all six stored dimensions before suppressing a write.
- Treat a change in any dimension as a state transition requiring a new record.
- Canonicalize JSON serialization with stable key ordering, such as
sort_keys=True, before comparison. - Use dimension-specific comparison logic for numeric measurements rather than raw JSON equality.
- Add automated tests that independently change each of the six dimensions and verify that every change creates a timeline record.
- Consider storing a canonical hash of the complete six-element state and comparing that hash only after validating that every expected dimension is present.
- Fail closed when required dimensions are missing or malformed instead of substituting an empty object without validation.
