meetecho / janus-gateway

Janus WebRTC Server
https://janus.conf.meetecho.com
GNU General Public License v3.0
8.17k stars 2.47k forks source link

[1.x] SIP plugin: possibility of inconsistent session mapping in 'callids' hash table #3404

Open ycherniavskyi opened 2 months ago

ycherniavskyi commented 2 months ago

What version of Janus is this happening on? 1.2.4 (195bac04d431301f6efb84156a5eaf8a4f06d8ea)

Have you tested a more recent version of Janus too? Yes. I am testing with latest master branch.

Was this working before? No.

Is there a gdb or libasan trace of the issue?

Additional context In case of call between two SIP handlers registered within one Janus (so when outgoing and incoming legs of one call going via the same Janus) the callids hash table will hold reference to latter initiated SIP call session of such call (incoming one, because it is follow outgoing one). This occurs because callids uses the callid as a key, which remains the same for both legs of the call.

This issue leads to incorrect functionality during attended transfers of such call, specifically in composing the Refer-To header (incorrect order of from-tag and to-tag), as it uses the incoming leg instead of the outgoing one. (And yes if SIP handlers registered within different Janus all transfers functionality works as expected.)

Upon reviewing the usage of the callids hash table, it appears that the Sofia-SIP logger functionality also behaves incorrectly in scenarios where both legs of the same call traverse a single Janus instance, because all SIP out events will be associate with an incoming leg of such call.

lminiero commented 2 months ago

That's a good catch, and one I hadn't thought about. I'm not exactly sure how to address this, though, as I'm not that familiar with SIP: not sure if there's another header that may be better suited for the job, or if we should use a combination of call-ID with something else (which could make lookups problematic, though, depending on whether or not whatever we use for that combo is always available). Suggestions are welcome!