From 6847e9ca301d98e86aa64d7bb57fae243bf600cc Mon Sep 17 00:00:00 2001 From: efiten Date: Wed, 19 Aug 2026 15:20:26 +0200 Subject: [PATCH] fix: trim AES block padding from a regions reply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ANON_REQ reply payload is encrypted with a block cipher (Utils::encryptThenMAC -> AES), so the plaintext arrives NUL-padded to a 16-byte boundary, and the firmware's own length is not carried through to us. We stored the padding verbatim. Measured in production: 48 of 65 stored rows carry it. The padding lands inside the LAST region name, so "belml" is stored as "belml\0\0\0..." — which matches no observed scope and therefore reads as a region the repeater declares but never forwards. A systematic false finding, on the last entry of nearly every list. A wildcard-only answer is the worst shape: 0x2A plus seven NULs is exactly one block, so even `regions_csv = '*'` compares false in SQL, and the audit can miss the wildcard entirely and report a contradiction that is not there. Trim before splitting. Padding is also excluded from the truncation measure — it is not part of the repeater's answer and must not count toward the byte ceiling. --- package.json | 2 +- public/sw.js | 2 +- src/regionreq.js | Bin 9329 -> 10063 bytes test/regionreq.test.mjs | 27 +++++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 11b29c1..7dcd5e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coredrive-rx", - "version": "1.10.1", + "version": "1.10.2", "private": false, "license": "GPL-3.0-or-later", "type": "module", diff --git a/public/sw.js b/public/sw.js index 63cb6d7..1597bc4 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,7 +1,7 @@ // Minimal service worker: makes the app installable and lets the shell load // offline. Network-first (always fresh online), cache fallback (offline). // Only the static app assets go through fetch; MQTT runs over WSS (not cached). -const CACHE = 'coredrive-rx-v33'; +const CACHE = 'coredrive-rx-v34'; self.addEventListener('install', () => self.skipWaiting()); self.addEventListener('activate', (e) => e.waitUntil((async () => { diff --git a/src/regionreq.js b/src/regionreq.js index 62cab6723a2e273bb1a602b8c6438921ee80ea4d..c591d7365624ab68e22256113a7520c8986bb398 100644 GIT binary patch delta 818 zcmYjQ!HN?>5RDf_Po4t7%Ol{LKqi}jE)q%DxCo+g6?WH)c4=9K-1 z^&313d-Wguhy4Tp!0OBdg*jDMz4z+Xn?G-VpZ;ujwugr}&j^kRy+I*1+KLp)gN$^W zB2bD-g$x3(7avdFL#iSphu%d{+D|4;7bBPt^AjYqM*t(v-<`@hy;vmMLZm5^lm&uimhn-t+yuhXmL?T$GmPqL(3Ns|B^*8Tu$6%(vu0t8 zV{CvF&MC$TnX~0Oi(sYyCxJHj*sXX8E3@=2m4k|zklX@uQRZ2VYi}~3( zo3mEdz=)hC=q^d;y2~)q=HzQ_b+OfI-Ch6a4p3!EvIceqxd<|&C=zz*$z3v`m$o1< z72K8t6AJ$JEId_X@<~VpHajJ$d2f$p8DQv=ODpTxiqsGBnVee1&6PpnY+A~|S|@n^ z5_W~77x2M4N*hR9`Twk9?{@yPHA8ODd>dj>Q^XVaVeRlMe&KyIp%))#7>{spP`7-E zl?3Cjm`fKkZSko&Rt({l z)Mbpv-Szi)9u@80B`n^&5H7?eW61VqaX5tW6U-G0Y4WRQvd(} diff --git a/test/regionreq.test.mjs b/test/regionreq.test.mjs index ce24124..bf65508 100644 --- a/test/regionreq.test.mjs +++ b/test/regionreq.test.mjs @@ -314,3 +314,30 @@ test('an evaluation that asks nobody must not consume the airtime budget', () => assert.equal(heardAskEligible(A, null, r, t0 + 19_000), false, 'but 19s after a real ask the budget is genuinely spent'); }); + +test('AES block padding is trimmed — it must not land inside the last region name', () => { + // The reply is encrypted with a block cipher, so the plaintext arrives NUL-padded + // to a 16-byte boundary. Production carried this into storage in 48 of 65 rows: + // "belml" became "belml\0\0\0…", which matches no observed scope and reads as a + // region the repeater declares but never forwards — a false finding, every time. + const csv = 'be,be-vli,belml'; + const padded = new Uint8Array([ + 0x8c, 0, ...le32(1), ...le32(2), ...ascii(csv), 0, 0, 0, 0, 0, 0, 0, 0, + ]); + const r = parseRegionsResponse(padded); + assert.deepEqual(r.regions, ['be', 'be-vli', 'belml'], + 'the last name must not carry NUL bytes'); + assert.equal(r.regions[2].length, 5, 'no trailing NULs survive into the name'); +}); + +test('a wildcard-only reply survives padding as exactly "*"', () => { + // 0x2A followed by seven NULs is one full AES block; this is the shape that made + // regions_csv = '*' compare false in SQL and could mask the wildcard entirely. + const padded = new Uint8Array([0x8c, 0, ...le32(1), ...le32(2), 0x2a, 0, 0, 0, 0, 0, 0, 0]); + assert.deepEqual(parseRegionsResponse(padded).regions, ['*']); +}); + +test('a reply that is only padding yields no regions, not one empty name', () => { + const padded = new Uint8Array([0x8c, 0, ...le32(1), ...le32(2), 0, 0, 0, 0, 0, 0, 0, 0]); + assert.deepEqual(parseRegionsResponse(padded).regions, []); +});