If you do want to write an
external_replaces externsion extension, the first thing you want to do is determine if you want to perform the remote attended transfer.
SIPREFERTOHDR, and values provided by the
CHANNEL() dialplan function can help you to decide if you want to allow the transfer. For instance, you might use
CHANNEL(endpoint) to see which PJSIP endpoint is performing the transfer, and you can inspect
SIPREFERTOHDR to determine if the transfer is destined for a trusted domain.