[OpenSIPS-Devel] [OpenSIPS/opensips] b3bf15: path: Add escaping logic for add_path_received()

Liviu Chircu liviu at opensips.org
Thu May 24 11:58:50 EDT 2018

  Branch: refs/heads/master
  Home:   https://github.com/OpenSIPS/opensips
  Commit: b3bf15646affe981d4b266381d59f210e6e882fd
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-05-24 (Thu, 24 May 2018)

  Changed paths:
    M lib/path.c
    M lib/path.h
    M lib/reg/path.c
    M modules/path/path.c

  Log Message:
  path: Add escaping logic for add_path_received()

Simply dumping a SIP URI as a ";received=" Path header field parameter
value is problematic and leads to two kinds of issues:

a. invalid SIP URIs, where the ";transport=" is specified twice:

Path: <sip:;transport=tcp;lr; ...
       ... received=sip:;transport=tcp>

b. in double Path scenarios (e.g. when switching protocols from, say,
TCP -> UDP), since the ";received=" is inserted as the
inbound Path header field value, this can lead to a strange
"protocol conversion" effect:

Path: <sip:;r2=on;lr ...
       ... ;received=sip:;transport=tcp>
Path: <sip:;transport=tcp;r2=on;lr>

^ notice how the inbound Path intended to advertise an UDP URI, but the
add_path_received() managed to "convert" it into a TCP URI because of
its inability to escape its token. nathelper is an easy first victim of
this conversion, as it will attempt to send pings using the incorrect
transport after reading the topmost Path (Route) header.

This patch adds escaping/unescaping logic for the ";received=" feature
of add_path_received() along with any code that makes use of this
feature. Example resulting URI for the above example:

Path: <sip:;r2=on;lr ...
       ... ;received=sip:>

  Commit: 71c7d75f66c8f0dc4ce411fd97d2dc867b39ce8d
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-05-24 (Thu, 24 May 2018)

  Changed paths:
    M lib/path.c
    M lib/reg/path.c

  Log Message:
  path: Fix "use_path_received" in double-Path scenarios

Due to the fact that run_rr_callbacks() returns the 2nd Route (Path)
header field value when previously having done protocol switching (thus
having inserted two Path headers), the "use_path_received" feature of
the path module would not work -- it wouldn't set the $du at all.

The reason for this is that add_path_received() appends its ";received="
to inside Path #1 (the outbound path of the registration / the inbound
path of future requests) when doing double-Path recording.

This patch simply moves the ";received=" append operation performed by
add_path_received() into Path #2 (inbound path of registration /
outbound path of future requests), and adapts other code that needs it
(e.g. save("location", "p1v")) to properly be able to fetch it.

Reported by @futsystems

Fixes #1358

Compare: https://github.com/OpenSIPS/opensips/compare/60b1e7005b22...71c7d75f66c8
      **NOTE:** This service been marked for deprecation: https://developer.github.com/changes/2018-04-25-github-services-deprecation/

      Functionality will be removed from GitHub.com on January 31st, 2019.

More information about the Devel mailing list