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 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 02:59:27 +00:00
co-authored by Claude Opus 5.5
parent 907d439c7d
commit 33a020f15c
+5 -4
View File
@@ -41,15 +41,16 @@ router.onRadioInfo((station, band, freq) => {
});
function resolveClientIp(c: Parameters<typeof getConnInfo>[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);