From d774122023801492b2fcac0b2b4893cd560205ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 23 Jun 2021 12:14:17 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20Protect=20against=20invalid=20bi?= =?UTF-8?q?trate=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/server/api/settings.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 0641c0532..b16099eb0 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -6,6 +6,7 @@ __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agp __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License" import logging +import re from flask import abort, jsonify, request from flask_login import current_user @@ -23,6 +24,7 @@ from octoprint.settings import settings, valid_boolean_trues FOLDER_TYPES = ("uploads", "timelapse", "timelapse_tmp", "logs", "watched") FOLDER_MAPPING = {"timelapseTmp": "timelapse_tmp"} +TIMELAPSE_BITRATE_PATTERN = re.compile(r"\d+[KMGTPEZY]?i?B?", flags=re.IGNORECASE) def _lastmodified(): @@ -585,8 +587,14 @@ def _saveSettings(data): abort(400, description="Invalid webcam.ffmpegCommandline setting") else: s.set(["webcam", "ffmpegCommandline"], commandline) - if "bitrate" in data["webcam"]: - s.set(["webcam", "bitrate"], data["webcam"]["bitrate"]) + if "bitrate" in data["webcam"] and data["webcam"]["bitrate"]: + bitrate = str(data["webcam"]["bitrate"]) + if not TIMELAPSE_BITRATE_PATTERN.match(bitrate): + abort( + 400, + description="Invalid webcam.bitrate setting, needs to be a valid ffmpeg bitrate", + ) + s.set(["webcam", "bitrate"], bitrate) if "ffmpegThreads" in data["webcam"]: s.setInt(["webcam", "ffmpegThreads"], data["webcam"]["ffmpegThreads"]) if "ffmpegVideoCodec" in data["webcam"] and data["webcam"][