fix: audit fixes — add checksum_ok to params parse, passthrough control in command-sync

- parseVendorStatus: add checksum_ok verification for 34-byte and 33-byte params
- command-sync.js: passthrough control, current_gain, hold_time from server payload
- Mark buildVendorCommand33 as deprecated alias
这个提交包含在:
Guoguo
2026-06-12 09:02:43 -07:00
父节点 36f12e098e
当前提交 8a4f9382e4
修改 2 个文件,包含 9 行新增1 行删除
+5
查看文件
@@ -206,6 +206,7 @@ function buildVendorCommand(options) {
return bytes return bytes
} }
// deprecated: alias kept for backward compat, actually outputs 34 bytes
function buildVendorCommand33(options) { function buildVendorCommand33(options) {
return buildVendorCommand(options) return buildVendorCommand(options)
} }
@@ -259,6 +260,7 @@ function parseVendorStatus(buffer) {
gain: (bytes[off34 + 4] << 8) | bytes[off34 + 5] gain: (bytes[off34 + 4] << 8) | bytes[off34 + 5]
}) })
} }
var expected34 = xorChecksum(bytes.slice(0, 33))
return { return {
type: 'params', type: 'params',
is_heartbeat: false, is_heartbeat: false,
@@ -266,6 +268,7 @@ function parseVendorStatus(buffer) {
hold_time: (bytes[30] << 8) | bytes[31], hold_time: (bytes[30] << 8) | bytes[31],
control: bytes[32], control: bytes[32],
checksum: bytes[33], checksum: bytes[33],
checksum_ok: expected34 === bytes[33],
raw_hex: bytesToHex(bytes) raw_hex: bytesToHex(bytes)
} }
} }
@@ -279,6 +282,7 @@ function parseVendorStatus(buffer) {
gain: (bytes[off + 4] << 8) | bytes[off + 5] gain: (bytes[off + 4] << 8) | bytes[off + 5]
}) })
} }
var expected33 = xorChecksum(bytes.slice(0, 32))
return { return {
type: 'params', type: 'params',
is_heartbeat: false, is_heartbeat: false,
@@ -286,6 +290,7 @@ function parseVendorStatus(buffer) {
hold_time: (bytes[30] << 8) | bytes[31], hold_time: (bytes[30] << 8) | bytes[31],
control: -1, control: -1,
checksum: bytes[32], checksum: bytes[32],
checksum_ok: expected33 === bytes[32],
raw_hex: bytesToHex(bytes) raw_hex: bytesToHex(bytes)
} }
} }
+4 -1
查看文件
@@ -16,7 +16,10 @@ function execute(command) {
wavelength: payload.wavelength, wavelength: payload.wavelength,
brightness: payload.brightness, brightness: payload.brightness,
duration_ms: payload.duration_ms, duration_ms: payload.duration_ms,
mode: payload.mode mode: payload.mode,
control: payload.control,
current_gain: payload.current_gain,
hold_time: payload.hold_time
}) })
case ble.CMD.START: case ble.CMD.START:
return ble.startTreatment(payload.region_mask) return ble.startTreatment(payload.region_mask)