PR #26385 opened by Martin Wimpress (flexiondotorg) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26385 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26385.patch
# Summary of changes In `listen` mode, `read_connect()` and `send_invoke_response()` already parse and compare the incoming RTMP `app` name and `playpath`, but only log a warning and accept the stream when they do not match. This adds an opt-in boolean option, `rtmp_strict_paths` (default `0`), that rejects missing or mismatched `app` fields and stream paths with `AVERROR(EACCES)` before entering `STATE_RECEIVING`, and documents it in `doc/protocols.texi`. Default behaviour stays unchanged and listen mode remains single-connection with no added authentication or credential handling. Verified with `tools/check_commit_msg.sh`, `tools/patcheck`, `make fate` (3,186 self-contained tests passed), and loopback tests using `ffmpeg -listen 1 -rtmp_strict_paths 1 -i rtmp://127.0.0.1:1941/expectedapp/expectedkey` against matching and mismatched `app` and `playpath` values. >From b18dab0903ea0d9862479fda8745ee7eb80ba055 Mon Sep 17 00:00:00 2001 From: Martin Wimpress <[email protected]> Date: Wed, 25 Nov 2026 19:31:19 +0000 Subject: [PATCH] avformat/rtmpproto: add rtmp_strict_paths option In listen mode, read_connect() and send_invoke_response() log warnings when the incoming RTMP app name or stream path does not match the configured URL, then accept the stream anyway. Add an opt-in boolean option, rtmp_strict_paths (default 0), that rejects missing or mismatched app fields and stream paths with AVERROR(EACCES) before entering STATE_RECEIVING. Document the option in doc/protocols.texi. Signed-off-by: Martin Wimpress <[email protected]> --- doc/protocols.texi | 6 ++++++ libavformat/rtmpproto.c | 27 ++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/doc/protocols.texi b/doc/protocols.texi index 4eb9e9a4c54..f2c492b5d98 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -1020,6 +1020,12 @@ value will be sent. Stream identifier to play or to publish. This option overrides the parameter specified in the URI. +@item rtmp_strict_paths +When set to 1 in @code{listen} mode, reject incoming connections whose +application name or published stream path does not match the configured +URL (or @code{rtmp_app} and @code{rtmp_playpath} options). Default value +is 0, which logs a warning and accepts the connection. + @item rtmp_subscribe Name of live stream to subscribe to. By default no value will be sent. It is only sent if the option is specified or if rtmp_live diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 392c5590904..008fd81155f 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -125,6 +125,7 @@ typedef struct RTMPContext { int tracked_methods_size; ///< size of the tracked methods buffer int listen; ///< listen mode flag int listen_timeout; ///< listen timeout to wait for new connections + int strict_paths; ///< reject mismatched app or stream path in listen mode int nb_streamid; ///< The next stream id to return on createStream calls double duration; ///< Duration of the stream in seconds as returned by the server (only valid if non-zero) int tcp_nodelay; ///< Use TCP_NODELAY to disable Nagle's algorithm if set to 1 @@ -538,11 +539,23 @@ static int read_connect(URLContext *s, RTMPContext *rt) ret = ff_amf_get_field_value(gbc.buffer, gbc.buffer + bytestream2_get_bytes_left(&gbc), "app", tmpstr, sizeof(tmpstr)); - if (ret) + if (ret) { + if (rt->strict_paths) { + av_log(s, AV_LOG_ERROR, "App field not found in connect\n"); + ff_rtmp_packet_destroy(&pkt); + return AVERROR(EACCES); + } av_log(s, AV_LOG_WARNING, "App field not found in connect\n"); - if (!ret && strcmp(tmpstr, rt->app)) + } else if (strcmp(tmpstr, rt->app)) { + if (rt->strict_paths) { + av_log(s, AV_LOG_ERROR, "App field does not match: %s <-> %s\n", + tmpstr, rt->app); + ff_rtmp_packet_destroy(&pkt); + return AVERROR(EACCES); + } av_log(s, AV_LOG_WARNING, "App field don't match up: %s <-> %s\n", tmpstr, rt->app); + } ff_rtmp_packet_destroy(&pkt); // Send Window Acknowledgement Size (as defined in specification) @@ -2023,7 +2036,14 @@ static int send_invoke_response(URLContext *s, RTMPPacket *pkt) return ret; } // check with url - if (s->filename) { + if (rt->strict_paths) { + if (!rt->playpath || strcmp(rt->playpath, filename)) { + av_log(s, AV_LOG_ERROR, + "Unexpected stream %s, expecting %s\n", + filename, rt->playpath ? rt->playpath : ""); + return AVERROR(EACCES); + } + } else if (s->filename) { pchar = strrchr(s->filename, '/'); if (!pchar) { av_log(s, AV_LOG_WARNING, @@ -3218,6 +3238,7 @@ static const AVOption rtmp_options[] = { {"recorded", "recorded stream", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, DEC, .unit = "rtmp_live"}, {"rtmp_pageurl", "URL of the web page in which the media was embedded. By default no value will be sent.", OFFSET(pageurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC}, {"rtmp_playpath", "Stream identifier to play or to publish", OFFSET(playpath), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, + {"rtmp_strict_paths", "Reject connections with mismatched app or stream path in listen mode", OFFSET(strict_paths), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC}, {"rtmp_subscribe", "Name of live stream to subscribe to. Defaults to rtmp_playpath.", OFFSET(subscribe), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC}, {"rtmp_swfhash", "SHA256 hash of the decompressed SWF file (32 bytes).", OFFSET(swfhash), AV_OPT_TYPE_BINARY, .flags = DEC}, {"rtmp_swfsize", "Size of the decompressed SWF file, required for SWFVerification.", OFFSET(swfsize), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC}, -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
