From 1dc0aa89df7adbf4e1873c8d2e55171ea277b771 Mon Sep 17 00:00:00 2001 From: jj Date: Mon, 13 Oct 2025 23:29:30 +0000 Subject: [PATCH] youtube: provide own JS interpreter since the data should be side-effect free, this should be fine for now, but maybe it might be a good idea to look into a proper sandboxed environment in the future. --- api/src/processing/services/youtube.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/api/src/processing/services/youtube.js b/api/src/processing/services/youtube.js index d44f8c03..e44a5e36 100644 --- a/api/src/processing/services/youtube.js +++ b/api/src/processing/services/youtube.js @@ -7,6 +7,23 @@ import { env } from "../../config.js"; import { getCookie } from "../cookie/manager.js"; import { getYouTubeSession } from "../helpers/youtube-session.js"; +// https://github.com/LuanRT/YouTube.js/pull/1052 +Platform.shim.eval = async (data, env) => { + const properties = []; + + if (env.n) { + properties.push(`n: exportedVars.nFunction("${env.n}")`) + } + + if (env.sig) { + properties.push(`sig: exportedVars.sigFunction("${env.sig}")`) + } + + const code = `${data.output}\nreturn { ${properties.join(', ')} }`; + + return new Function(code)(); +} + const PLAYER_REFRESH_PERIOD = 1000 * 60 * 15; // ms let innertube, lastRefreshedAt;