diff --git a/services/mam-api/src/routes/recorders.js b/services/mam-api/src/routes/recorders.js index 47cf8c1..771cb67 100644 --- a/services/mam-api/src/routes/recorders.js +++ b/services/mam-api/src/routes/recorders.js @@ -993,10 +993,11 @@ router.post('/probe', async (req, res) => { // Validate URL up-front so we don't even let the capture service see junk. let parsed = null; + let proto = ''; if (url) { try { parsed = new URL(url); } catch { return res.status(400).json({ error: 'Invalid URL' }); } - const proto = (parsed.protocol || '').replace(':', '').toLowerCase(); + proto = (parsed.protocol || '').replace(':', '').toLowerCase(); if (!ALLOWED_PROBE_SCHEMES.has(proto)) { return res.status(400).json({ error: `Scheme "${proto}" is not permitted for probe (#104)` }); } @@ -1009,6 +1010,7 @@ router.post('/probe', async (req, res) => { if (parsed.hostname === 'mam-api' || parsed.hostname === 'localhost' || parsed.hostname === '127.0.0.1') { return res.status(403).json({ error: 'Internal probe target is not permitted' }); } + } // Try the capture service first (5s timeout) try { @@ -1033,7 +1035,6 @@ router.post('/probe', async (req, res) => { } const host = parsed.hostname; - const proto = (parsed.protocol || '').replace(':', '').toLowerCase(); const isUdp = proto === 'srt' || source_type === 'srt'; const port = parseInt(parsed.port, 10) || (isUdp ? 9000 : 1935);