Merge upstream/dev (1 commit: sec patch) [upstream-sync]
Changelog: Repeater, room server, sensor: an admin's CLI reply captured over the air can no longer be sent back to the node as a command (upstream security fix) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
22700192bd
15 files changed
+151
-12
No files matched your search
@@ -121,6 +121,7 @@ typedef uint32_t DispatcherAction;
|
||||
#ifndef MESH_TX_RETRIES
|
||||
#define MESH_TX_RETRIES 3
|
||||
#endif
|
||||
#define ERR_EVENT_DIAG1 (1 << 8) // role-specific error flag
|
||||
|
||||
/**
|
||||
* \brief The low-level task that manages detecting incoming Packets, and the queueing
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <helpers/BaseChatMesh.h>
|
||||
#include <Utils.h>
|
||||
#include <helpers/UTF8Helpers.h>
|
||||
|
||||
#ifndef SERVER_RESPONSE_DELAY
|
||||
#define SERVER_RESPONSE_DELAY 300
|
||||
@@ -247,7 +248,10 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
|
||||
// len can be > original length, but 'text' will be padded with zeroes
|
||||
data[len] = 0; // need to make a C string again, with null terminator
|
||||
|
||||
if (flags == TXT_TYPE_PLAIN) {
|
||||
size_t text_ofs = (flags == TXT_TYPE_SIGNED_PLAIN) ? 9 : 5; // signed text starts after 4-byte sender prefix
|
||||
if (len < text_ofs || !mesh::isValidUtf8TextAndPadding(&data[text_ofs], len - text_ofs)) {
|
||||
MESH_DEBUG_PRINTLN("onPeerDataRecv: invalid text payload!");
|
||||
} else if (flags == TXT_TYPE_PLAIN) {
|
||||
from.lastmod = getRTCClock()->getCurrentTime(); // update last heard time
|
||||
onMessageRecv(from, packet, sender_timestamp, (const char *) &data[5]); // let UI know
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ void ClientACL::loadTimestamps() {
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < num_clients; i++) {
|
||||
clients[i].last_timestamp = clients[i].saved_timestamp;
|
||||
clients[i].last_timestamp = clients[i].last_req_timestamp = clients[i].saved_timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ ClientInfo* ClientACL::putClient(const mesh::Identity& id, uint8_t init_perms) {
|
||||
c->out_path_len = OUT_PATH_UNKNOWN;
|
||||
for (int i = 0; i < _num_ts_orphans; i++) { // known before: its replay floor comes back
|
||||
if (memcmp(_ts_orphans[i].prefix, id.pub_key, ACL_TS_PREFIX) == 0) {
|
||||
c->saved_timestamp = c->last_timestamp = _ts_orphans[i].ts;
|
||||
c->saved_timestamp = c->last_timestamp = c->last_req_timestamp = _ts_orphans[i].ts;
|
||||
_num_ts_orphans--;
|
||||
memmove(&_ts_orphans[i], &_ts_orphans[i + 1], (_num_ts_orphans - i) * sizeof(TsOrphan));
|
||||
break;
|
||||
|
||||
@@ -20,6 +20,7 @@ struct ClientInfo {
|
||||
uint8_t shared_secret[PUB_KEY_SIZE];
|
||||
uint32_t last_timestamp; // by THEIR clock (restored from /s_acl_ts* on boot)
|
||||
uint32_t saved_timestamp; // last_timestamp as last written to /s_acl_ts*
|
||||
uint32_t last_req_timestamp; // REQ only (upstream split); restored from saved_timestamp too
|
||||
uint32_t last_activity; // by OUR clock (transient)
|
||||
union {
|
||||
struct {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* \brief Remembers the last CLI replies sent, as a hash of each reply's plaintext (timestamp, flags, text),
|
||||
* so the same bytes coming back as a command (hash bytes swapped, same shared secret) are refused.
|
||||
*/
|
||||
class ReplyEchoGuard {
|
||||
static const int SLOTS = 16;
|
||||
uint32_t _hash[SLOTS] = {};
|
||||
int _next = 0;
|
||||
|
||||
static uint32_t hash(const uint8_t* p, size_t len) { // FNV-1a, never zero (zero marks an empty slot)
|
||||
uint32_t h = 2166136261u;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
h = (h ^ p[i]) * 16777619u;
|
||||
}
|
||||
return h ? h : 1;
|
||||
}
|
||||
|
||||
public:
|
||||
void note(const uint8_t* plain, size_t len) {
|
||||
_hash[_next] = hash(plain, len);
|
||||
_next = (_next + 1) % SLOTS;
|
||||
}
|
||||
|
||||
bool matches(const uint8_t* plain, size_t len) const {
|
||||
uint32_t h = hash(plain, len);
|
||||
for (int i = 0; i < SLOTS; i++) {
|
||||
if (_hash[i] == h) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -53,4 +53,50 @@ inline size_t validUtf8PrefixLength(const char* text, size_t max_bytes) {
|
||||
return offset;
|
||||
}
|
||||
|
||||
inline bool isValidUtf8TextAndPadding(const uint8_t* data, size_t len) {
|
||||
size_t offset = 0;
|
||||
bool seen_null = false;
|
||||
size_t null_pos = 0;
|
||||
while (offset < len) {
|
||||
const uint8_t first = static_cast<uint8_t>(data[offset]);
|
||||
if (seen_null) {
|
||||
if (first == 0) { // OK, is zero padding
|
||||
offset++;
|
||||
} else if (offset == null_pos + 1 && first >= 4 && first != 0xFF) { // OK, extended attempt byte (see composeMsgPacket)
|
||||
offset++;
|
||||
} else {
|
||||
return false; // Error, non-zero padding encountered
|
||||
}
|
||||
} else {
|
||||
if (first == 0) {
|
||||
seen_null = true;
|
||||
null_pos = offset;
|
||||
offset++;
|
||||
} else {
|
||||
size_t sequence_length = 0;
|
||||
|
||||
if (first < 0x20 && first != '\t' && first != '\n' && first != '\r') {
|
||||
return false; // control character
|
||||
} else if (first <= 0x7F) {
|
||||
sequence_length = 1;
|
||||
} else if (first >= 0xC2 && first <= 0xDF) {
|
||||
sequence_length = 2;
|
||||
} else if (first >= 0xE0 && first <= 0xEF) {
|
||||
sequence_length = 3;
|
||||
} else if (first >= 0xF0 && first <= 0xF4) {
|
||||
sequence_length = 4;
|
||||
} else {
|
||||
return false; // unsupported UTF-8 encoding
|
||||
}
|
||||
if (offset + sequence_length > len) return false; // invalid UTF-8 encoding
|
||||
for (size_t i = 1; i < sequence_length; i++) {
|
||||
if (!isUtf8Continuation(data[offset + i])) return false; // invalid UTF-8 encoding
|
||||
}
|
||||
offset += sequence_length;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true; // is OK
|
||||
}
|
||||
|
||||
} // namespace mesh
|
||||
@@ -392,7 +392,7 @@ public:
|
||||
} else if (_page == HomePage::RECENT) {
|
||||
display.setColor(UIColor::primary_txt);
|
||||
int y = 20;
|
||||
for (int i = 0, k = recent_next_idx; i < UI_RECENT_LIST_SIZE; i++, y += 11, k = (k + 1) % UI_RECENT_LIST_SIZE) {
|
||||
for (int i = 0, k = recent_next_idx; i < UI_RECENT_LIST_SIZE; i++, k = (k + 1) % UI_RECENT_LIST_SIZE) {
|
||||
auto a = &recent[k];
|
||||
if (a->name[0] == 0) continue; // empty slot
|
||||
int secs = _rtc->getCurrentTime() - a->recv_timestamp;
|
||||
@@ -412,6 +412,10 @@ public:
|
||||
display.drawTextEllipsized(0, y, max_name_width, filtered_recent_name);
|
||||
display.setCursor(display.width() - timestamp_width - 1, y);
|
||||
display.print(tmp);
|
||||
y += 11;
|
||||
}
|
||||
if (y == 20) {
|
||||
display.drawTextCentered(display.width() / 2, 32, "No recent adverts");
|
||||
}
|
||||
} else if (_page == HomePage::RADIO) {
|
||||
display.setColor(UIColor::primary_txt);
|
||||
@@ -513,6 +517,11 @@ public:
|
||||
} else if (_page == HomePage::SENSORS) {
|
||||
int y = 18;
|
||||
refresh_sensors();
|
||||
if (sensors_nb == 0) {
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.drawTextCentered(display.width() / 2, 32, "No sensor readings");
|
||||
return 5000;
|
||||
}
|
||||
char buf[30];
|
||||
char name[30];
|
||||
LPPReader r(sensors_lpp.getBuffer(), sensors_lpp.getSize());
|
||||
|
||||
Reference in new issue
Block a user