Error in log because PJSIP removing header when none exist

This is definitely a bug in FreePBX core.

The line that generates the ERROR message is line 10687 from /etc/asterisk/extensions_additional.conf (see below).

The logic is flawed which is why it generates an ERROR for 100% of every PJSIP call made.

It says: If any entry in SIPHEADERS array is “unset” for a PJSIP channel call, attempt to remove that header from the (not yet populated) out going SIP header.

But, this is part of func-apply-sipheaders which is supposed be adding headers. At this point in the call setup, the SIPHEADERS have not been added, so they can’t be removed with PJSIP_HEADER(remove, header).

Luckily, there is only one entry in the SIPHEADERS array. If there were more, it would generate an ERROR message for each header for every single PJSIP call. :face_vomiting:

It’s funny because line 10690, three lines after, says: If the entry is not “unset” for a PJSIP channel, go ahead and call PJSIP_HEADER() to add it to the out going SIP header.

In other words an “unset” PJSIP header won’t be added any way.

FWIW, the other two lines (10688 & 10689) make a feeble attempt to fix malformed Alert-Info header values by changing them to: <http://172.0.0.1>;info=malformed-header-value The two lines are only included if the Enforce RFC7462 option is set to Yes under Settings > Advanced Settings.

The logic is seriously flawed, and should probably just generate an ERROR message and drop the malformed header by setting its value to “unset”. But, that’s not what’s causing the ERROR messages.

The workaround for this until it gets fixed in core is to copy the func-apply-sipheaders block (lines 10680 to 10694) into /etc/asterisk/extensions_override_freepbx.conf and then comment out or delete what was line 19687. Then run sudo rasterisk -x 'dialplan reload' to regenerate the dial plan.

@lgaetz, you mentioned that @sorvani should open a ticket somewhere. Where is the best place to report this issue? It definitely needs to be fixed.

/etc/asterisk/extensions_additional.conf:

 10680  [func-apply-sipheaders]
 10681  include => func-apply-sipheaders-custom
 10682  exten => s,1,Noop(Applying SIP Headers to channel ${CHANNEL})
 10683  exten => s,n,Set(TECH=${CUT(CHANNEL,/,1)})
 10684  exten => s,n,Set(SIPHEADERKEYS=${HASHKEYS(SIPHEADERS)})
 10685  exten => s,n,While($["${SET(sipkey=${SHIFT(SIPHEADERKEYS)})}" != ""])
 10686  exten => s,n,Set(sipheader=${HASH(SIPHEADERS,${sipkey})})
 10687  exten => s,n,ExecIf($["${sipheader}" = "unset" & "${TECH}" = "PJSIP"]?Set(PJSIP_HEADER(remove,${sipkey})=))
 10688  exten => s,n,ExecIf($["${sipheader}" != "unset" & "${sipkey}" = "Alert-Info" & ${REGEX("^<[^>]*>" ${sipheader})} != 1 & ${REGEX("\;info=" ${sipheader})} != 1]?Set(sipheader=<http://127.0.0.1>\;info=${sipheader}))
 10689  exten => s,n,ExecIf($["${sipheader}" != "unset" & "${sipkey}" = "Alert-Info" & ${REGEX("^<[^>]*>" ${sipheader})} != 1]?Set(sipheader=<http://127.0.0.1>${sipheader}))
 10690  exten => s,n,ExecIf($["${TECH}" = "PJSIP" & "${sipheader}" != "unset"]?Set(PJSIP_HEADER(add,${sipkey})=${sipheader}))
 10691  exten => s,n,EndWhile
 10692  exten => s,n,Return()
 10693
 10694  ;--== end of [func-apply-sipheaders] ==--;```