From 767acf32d4c568103bfb74746886050095cf90ef Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 27 Oct 2022 10:14:58 +0200 Subject: [PATCH] luci-base: dispatcher.uc: update uci session ID in Lua context Make sure that the uci session ID of the `luci.model.uci` module within the Lua context is updated once we acquire the login session information. In case legacy themes are used, the probing of the theme header template might indirectly load the Lua runtime and the Lua side `luci.dispatcher` module which in turn will load the `luci.model.uci` and set the session ID there which is not yet initialized at this point in time. This results in broken uci change handling within legacy Lua applications when a legacy theme is loaded. Fixes: #6060 Signed-off-by: Jo-Philipp Wich --- modules/luci-base/ucode/dispatcher.uc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/luci-base/ucode/dispatcher.uc b/modules/luci-base/ucode/dispatcher.uc index 1d10d7876d..805abc4ce0 100644 --- a/modules/luci-base/ucode/dispatcher.uc +++ b/modules/luci-base/ucode/dispatcher.uc @@ -925,6 +925,14 @@ dispatch = function(_http, path) { resolved.ctx.authtoken ??= session.data?.token; resolved.ctx.authuser ??= session.data?.username; resolved.ctx.authacl ??= session.acls; + + /* In case the Lua runtime was already initialized, e.g. by probing legacy + * theme header templates, make sure to update the session ID of the uci + * module. */ + if (runtime.L) { + runtime.L.invoke('require', 'luci.model.uci'); + runtime.L.get('luci', 'model', 'uci').invoke('set_session_id', session.sid); + } } if (length(resolved.ctx.acls)) {