Repository navigation
Conversation
Since 9c50b4e, rtpp_record_ctor() refuses to record (R, Rs, -a) when the Call-ID or from-tag used in the file name contains '/', which keeps recordings inside of the recording directory. '/' is a legal Call-ID character and some carriers use it routinely, so those calls end up not recorded at all for clients that still rely on R. Add an opt-in --record_fname_encode option. When it is given, '/' and '%' in the Call-ID and from-tag are percent-encoded as "%2F" and "%25" before the name is built, so the file is created inside of the recording directory, never contains '/', and the original value can be recovered by decoding the "%XX" sequences. The encoded value is bounded by the same PATH_MAX buffers and the snprintf() truncation checks are kept, so names that do not fit are still refused. The default behaviour is unchanged: without the option '/' is refused as before (the log message now points at the option). Names given explicitly with C are not affected. Add a recording/basic sub-test, badpath_enc, that records the traversal Call-IDs from badpath and a Call-ID with '%' under their encoded names with the option, and still refuses an over-long Call-ID.
|
Local test results, reproduced with the project's own CI recipe (
I also ran the PR binary as a systemd service (
Every recorded leg had all 100 packets, and |
Instead of percent-encoding '/' and '%' in the Call-ID, select how the
Call-ID is put into the recording file name built for R, Rs and -a:
raw the Call-ID as is (the default), '/' is refused as before;
sha256 SHA-256 digest of the Call-ID in lowercase hex, recommended
for its security properties; fixed length, so even Call-IDs
too long to be used as is can be recorded; needs OpenSSL;
b64url URL-safe base64 (RFC 4648 sec. 5) without padding, for when
the Call-ID has to be recovered from the file name.
Neither sha256 nor b64url can produce '/', so the result always stays
inside of the recording directory. The from-tag is used as is with any
method and '/' in it is still refused. Names given with C/Cs and remote
(udp:) recording are not affected.
An unknown method, or sha256 in a build without OpenSSL, is reported at
startup and rtpproxy exits with a non-zero code; usage() lists only the
methods available in the build. The option parsing, the RTPP_RCID_*
values and rtpp_record_callid_fname(), which builds and checks the
"<call-id>=<from-tag>" part of the file name and reports why it cannot,
live in a new rtpp_record_util.[ch] rather than in main.c and
rtpp_record.c.
configure gets a standalone libcrypto (EVP_Digest) check, independent
of libsrtp, that defines HAVE_LIBCRYPTO in config.h and sets an automake
conditional of the same name, under which ${LIB_CRYPTO} is linked into
rtpproxy_debug and librtpproxy (and so into rtpproxy). Generated files
(configure, Makefile.in, config.h.in) are not regenerated here.
Tests: badpath_enc is replaced with badpath_b64 and badpath_sha256. They
check that traversal Call-IDs are recorded under the expected names
inside of the recording directory, that '/' in the from-tag is still
refused, that an over-long Call-ID is refused with b64url but recorded
with sha256, and that an unknown method is rejected. badpath_sha256 runs
in builds with HAVE_LIBCRYPTO, which tests/Makefile.am now exports to
the tests, so a build with OpenSSL where the method does not work fails
the test.
…hash
badpath_b64 and badpath_sha256 now also:
- record with a spool directory (-S), with both R and Rs, and check
that the files end up in the recording directory under the encoded
name and nothing is left in the spool;
- record everything (-a) and check the file names, and that a session
whose from-tag contains '/' is still set up but not recorded;
- refuse '/' in the from-tag with -S as well.
The Call-IDs used cover all three base64 tail lengths.
badpath now checks that '/' in the from-tag is refused in the default
raw mode too.
In a build without OpenSSL (no HAVE_LIBCRYPTO), recording/basic now
checks that --record_callid_hash sha256 is refused with the explicit
error.
|
Thanks for this, and for the very thorough testing. The problem is real and worth fixing, but I've reworked the approach and pushed the result on top of your commit. Here's why. Why it was reworked
What it does now
In every mode, the from-tag is used as is and still refused if it contains Recommendation for your setup: use
Use Tests Your It would be great if you could run your carrier-traffic setup against this branch with |
7222f82 to
a6ce175
Compare
Follow-up to #179.
Since 9c50b4e,
rtpp_record_ctor()refuses to record (R,Rs,-a) when the Call-ID or from-tag used in the file name contains/. That closes the path traversal, and I agree thatCwith a name chosen by the client is the right long-term answer.In the meantime, clients that still send
Rlose those recordings completely./is legal in a Call-ID and some carriers use it routinely. Moving the client toCis not always possible soon, because it needs a config change in the proxy and in everything that later finds the recording by name.This PR adds an opt-in
--record_fname_encodeoption:/is still refused exactly as in Refuse '/' in Call-ID and bound recording paths in rtpp_record_ctor #179, and the existingbadpathsub-test passes unmodified. The only change on that path is that the log message now mentions the option./and%in the Call-ID and from-tag are percent-encoded as%2Fand%25before the name is built:/;%as well keeps the mapping reversible, soa/banda%2Fbcannot end up in the same file. That matters because the file is opened withO_TRUNC;%XX.PATH_MAXbuffers and thesnprintf()truncation checks from Refuse '/' in Call-ID and bound recording paths in rtpp_record_ctor #179 stay, so names that do not fit are still refused.C/Csare not affected. Explicit names are left alone, as in Refuse '/' in Call-ID and bound recording paths in rtpp_record_ctor #179.Tests: a new
recording/basicsub-test,badpath_enc. With the option it records the same traversal Call-IDs asbadpath, plus one with%, and checks they are created under their encoded names inside the recording directory and nowhere else. It also checks that an over-long Call-ID is still refused. Against master the new sub-test fails, because the option does not exist there (unrecognized option '--record_fname_encode'), whilebadpathpasses on both. Local results with the project's owndocker/Dockerfile.ci+scripts/do-test.share in the comment below.Docs:
usage(),doc/manpage.xmlandrtpproxy.8.If you would rather not have a global option for this, I am happy to rework it, for example as an
R/Rscommand modifier.