Incorrect IP in contact header

This thread has recently become interesting to me, because of another thread where pjsip inappropriately sends Asterisk’s LAN address in the Contact header:

I suspect that there is a bug in Asterisk that may be affecting many users.

A few questions for the OP:

Can you cause this problem at will, for example by power cycling your modem or router? If not, does your external IP address change when you do this?

When the trouble occurs, does the request or response with the incorrect Contact header have an external address in the SDP? If so, is it the ‘new’ or the ‘old’ address?

When the trouble occurs, have you tried issuing commands (at the Asterisk command prompt) such as
pjsip show transports
pjsip show transport 0.0.0.0-udp
pjsip show endpoint (extension affected by the problem)
If so, please post those results.

Somewhat off topic: An IP address change will certainly drop any calls in progress, and will likely also prevent them from being quickly re-established. Does your system have any measures to prevent that from happening, for example forcing a router or modem restart at 3 AM every day?

Also, for a small system with external extensions, I would normally recommend using a cloud PBX, rather than on-site. Even without technical issues, that is generally more robust; in a power or internet outage, external extensions would continue to function normally. Why have you not considered that?