Skip to content

Commit f60b2b2

Browse files
committed
fix(asterisk): extract incoming DID/CallerID via AGI instead of broken REGEX()
Asterisk's REGEX() dialplan function only tests for a match (returns 1/0); it cannot extract a substring. The regex DID and CallerID parsers relied on it, so didNum/fromCid were set to "1" instead of the captured value and inbound calls mis-routed. - Add shared extract_did_cid.php AGI: applies PCRE to a source channel variable and writes the captured value into a destination variable (didNum / fromCid). Regex is passed base64-encoded so dialplan-special characters ({10,11} comma, ';', quotes) survive the extensions.conf parser; the header is read inside the AGI to avoid argv splitting. - Harden the AGI against attacker-controlled headers: cap input length (ReDoS), whitelist the result to the inbound-extension charset with the /D modifier (rejects embedded comma/newline), and fall back to the whole match when an optional capture group matches empty. - Replace the runtime ${CUT(CONTEXT,-,1-2)} Goto target (broke for provider ids with >2 dash segments) with the literal {providerId}-incoming, and guard every redirect Goto with a FILTER() charset check so a crafted value cannot split the Goto arguments. - SIPConf: in the shared-context path, build the cid-did context with $context_id (not a provider uniqid) so it is reachable by Gosub(${CONTEXT}-cid-did,...) and its Goto returns to the correct context. - Add unit tests covering both DID and CallerID branches.
1 parent fec5a3c commit f60b2b2

4 files changed

Lines changed: 435 additions & 100 deletions

File tree

0 commit comments

Comments
 (0)