# ESPHome API组件拒绝服务漏洞
## 概述
ESPHome 的 API 组件在处理未加密通信时,由于 Protobuf 解码器中存在整数溢出漏洞,可导致拒绝服务攻击。
## 影响版本
受影响版本为 ESPHome 2025.9.0 至 2025.12.6。
## 细节
漏洞位于 `components/api/proto.cpp` 文件中,对 `ptr + field_length > end` 的边界检查在 `field_length` 值过大时会发生整数溢出。攻击者可通过发送特制的大量 `field_length` 值绕过边界检查,导致设备读取非法内存并崩溃。该漏洞影响所有 ESPHome 设备平台,包括 ESP32、ESP8266、RP2040 和 LibreTiny。
## 影响
- 未启用 API 加密时:攻击者可在无需认证的情况下触发崩溃,造成拒绝服务。
- 启用 Noise 加密时:需掌握加密密钥才能利用。
- 所有使用受影响版本且未加密 API 的设备均面临风险。
是否为 Web 类漏洞: 未知
判断理由:
| # | POC 描述 | 源链接 | 神龙链接 |
|---|
标题: [api] Use subtraction for protobuf bounds checking by bdraco · Pull Request #13306 · esphome/esphome · GitHub -- 🔗来源链接
标签:x_refsource_MISC
神龙速读:
## 关键信息
- **漏洞描述**:该PR对protobuf解码器中的边界检查进行了重构,改为使用减法代替加法。这是一种防御性编码的改进,可以避免在32位平台上可能出现的算术问题。
- **修改类型**:
- 代码质量改进对现有代码或测试的添加。
- **测试环境**:
- 支持的平台:ESP32, ESP32 IDF, RP2040。
- **相关文件**:
- PR修改了`proto.cpp`文件。
- **改进点**:
- 将四个边界检查从加法(`ptr + length > end`)改为减法(`length > end - ptr`或`end - ptr < length`)。
- 通过避免指针算术溢出带来的未定义行为,提高了安全性。
- 与同一文件中其他地方使用的现有模式对齐(例如`ProtoVarInt::parse`调用)。
- **内存影响分析**:
- 对`api`组件的`esp8266-ard`平台进行分析显示,RAM和Flash的使用没有变化。
- `[esphome]api`组件的Flash大小减少了4字节。
- **Codecov报告**:
- 所有修改和可覆盖的行都由测试覆盖。
- 项目覆盖率为73.76%。
标题: Security Best Practices - ESPHome - Smart Home Made Simple -- 🔗来源链接
标签:x_refsource_MISC
神龙速读:
从网页截图中可以获取以下关于漏洞的关键信息:
### Threat Model
- **Deploy on Trusted Networks**: ESPHome devices should be deployed on trusted networks like home or office networks.
- **Network Perimeter Security**: Devices are protected by network perimeter security (firewalls, segmentation, VLANs).
- **Physical Access Control**: Physical access to devices should be controlled.
### Core Security Features
1. **API Encryption**:
- Always enable API encryption.
- Generate a unique encryption key for each device.
- Store keys in `secrets.yaml`.
- Regenerate keys immediately if a device is compromised.
2. **Web Server Authentication**:
- Enable web server authentication with strong, unique passwords.
- Store credentials in `secrets.yaml`.
- Consider disabling the web server if not needed.
3. **OTA Password Protection**:
- Protect OTA updates with a password.
- Use strong, unique passwords.
- Rotate passwords periodically.
### Network Security
- **Network Segmentation**: Isolate networks for advanced users.
- **WiFi Security**:
- Prefer Ethernet for better security.
- Use strong WiFi passwords.
- Avoid WEP-encrypted networks.
- Disable WPS on routers.
- **mDNS Security**: Be aware of mDNS security implications.
### Physical Security
- **Device Access**:
- Install devices in secure, hard-to-access locations.
- Use tamper-evident seals.
- **USB/Serial Protection**: Be cautious when accessing devices via USB/serial.
### Secrets Management
- **Using secrets.yaml**: Store sensitive information in `secrets.yaml`.
- **Version Control**: Follow version control best practices.
### Update Management
- **Keep ESPHome Updated**: Regularly update ESPHome for security fixes.
- **Firmware Updates**: Verify updates and maintain an inventory of devices.
### Logging and Monitoring
- **Sensitive Data in Logs**: Avoid logging sensitive data.
- **Log Review**: Regularly review logs for unusual activity.
### Specific Component Security
- **WiFi Fallback Hotspot**: Always set a strong, unique password.
- **MQTT**: Enable MQTT authentication and use TLS encryption.
### External Components
- **Risks**: External components may contain vulnerabilities.
- **Best Practices**: Use trusted sources and review code before use.
### Secure Configuration Examples
- **Minimal Secure Configuration**: Basic security settings.
- **Production-Grade Secure Configuration**: Advanced security settings.
### Compliance and Regulations
- Consider GDPR, CCPA, HIPAA, etc., depending on jurisdiction.
### Incident Response
- If a compromise is suspected, isolate the device, document observations, investigate other devices, rotate credentials, flash firmware, and monitor for continued suspicious activity.
### Reporting Security Vulnerabilities
- Follow the ESPHome Security Policy for reporting vulnerabilities.
标题: Denial-of-service via out-of-bounds check bypass in the API component · Advisory · esphome/esphome · GitHub -- 🔗来源链接
标签:x_refsource_CONFIRM
神龙速读:
### 关键漏洞信息
- **漏洞标题**: Denial-of-service via out-of-bounds check bypass in the API component
- **CVE ID**: CVE-2026-23833
- **严重性**: 低
- **受影响的版本**: ESPHome 2025.9.0 及之后至 2025.12.6
- **已修复的版本**: 2025.12.7
- **漏洞描述**:
- API组件的protobuf解码器中的整数溢出,当未使用API加密时允许拒绝服务攻击。
- 恶意客户端发送大`field_length`值时,`components/api/proto.cpp`中的边界检查`ptr + field_length > end`会发生溢出,影响所有ESPHome设备平台(ESP32, ESP8266, RP2040, LibreTiny)。
- 溢出会绕过边界检查,导致设备读取无效内存并崩溃。
- **漏洞影响**:
- 拒绝服务。具有对6053端口网络访问的攻击者可以导致设备崩溃和重启。
- 使用明文API协议时,无需认证即可执行此攻击。启用噪声加密时,需要知道加密密钥。
- **缓解措施**:
- 升级到ESPHome 2025.12.7或更高版本(或2026.1.0b3或更高版本)。
- 使用每个设备唯一的密钥启用API加密。
- 遵循安全最佳实践。
- **参考**:
- #13306
- **致谢**:
- 感谢@Mat931负责地报告此漏洞。
标题: [api] Use subtraction for protobuf bounds checking (#13306) · esphome/esphome@69d7b6e · GitHub -- 🔗来源链接
标签:x_refsource_MISC
神龙速读:
关键信息:
- **漏洞类型**: Bounds checking issue in protobuf decoding.
- **修复方法**: 使用减法来进行边界检查,替换原有的加法边界检查。
- **关键代码更改**:
- 在 `proto.cpp` 文件中,将原有的加法边界检查 `if (ptr + field_length > end)` 替换为更加健壮的减法检查 `if (field_length > static_cast<size_t>(end - ptr))`。
- 类似地,对于固定长度的字段(如 `FIXED32`),将 `if (ptr + 4 > end)` 改为 `if (end - ptr < 4)`。
- **安全提升**: 这些更改避免了潜在的溢出或越界访问,增强了代码的安全性和稳定性。
暂无评论