From 33a020f15c88af30d6e34f93be24aad10203fb77 Mon Sep 17 00:00:00 2001 From: ericek111 Date: Sat, 14 Nov 2026 02:59:27 +0000 Subject: [PATCH] reject empty or non-integer azimuths, use first X-Forwarded-For hop An empty ROT field became Number('') === 0 and turned the rotator north. Co-Authored-By: Claude Opus 5.5 --- src/index.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index a2dbed8..cc1ac96 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,15 +41,16 @@ router.onRadioInfo((station, band, freq) => { }); function resolveClientIp(c: Parameters[0]): string { - const rawIp = c.req.header('x-forwarded-for') ?? getConnInfo(c).remote.address ?? 'unknown'; + const forwarded = c.req.header('x-forwarded-for')?.split(',')[0]?.trim(); + const rawIp = forwarded || getConnInfo(c).remote.address || 'unknown'; return rawIp.startsWith('::ffff:') ? rawIp.slice(7) : rawIp; } app.post('/turn/:label', async (c) => { const label = c.req.param('label'); - const body = await c.req.parseBody(); - const az = Number(body['ROT']); - if (isNaN(az)) return c.text('Invalid azimuth', 400); + const rot = (await c.req.parseBody())['ROT']; + const az = typeof rot === 'string' && rot.trim() !== '' ? Number(rot) : NaN; + if (!Number.isInteger(az) || az < 0) return c.text('Invalid azimuth', 400); const sourceIp = resolveClientIp(c); const ok = router.turn(label, az, sourceIp); return ok ? c.text(`Turning ${label} to ${az}`) : c.text('Unknown rotator', 404);