Changeset

6060:c7c17fac41b3

mod_sasl2_fast: Only copy SASL handler internals from util.sasl instance Prevents traceback in case the session sasl handler is missing the profile table, as may be the case with non-core sasl handlers. Thanks taba for reporting
author Kim Alvefur <zash@zash.se>
date Sun, 24 Nov 2024 14:42:59 +0100
parents 6059:25b091cbb471
children 6061:26bfcb442138
files mod_sasl2_fast/mod_sasl2_fast.lua
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_sasl2_fast/mod_sasl2_fast.lua	Fri Nov 22 19:09:10 2024 +0000
+++ b/mod_sasl2_fast/mod_sasl2_fast.lua	Sun Nov 24 14:42:59 2024 +0100
@@ -8,6 +8,11 @@
 local now = require "util.time".now;
 local hash = require "util.hashes";
 
+local sasl_mt = getmetatable(sasl.new("", { mechanisms = {} }));
+local function is_util_sasl(sasl_handler)
+	return getmetatable(sasl_handler) == sasl_mt;
+end
+
 module:depends("sasl2");
 
 -- Tokens expire after 21 days by default
@@ -113,9 +118,11 @@
 	local sasl_handler = get_sasl_handler(username);
 	if not sasl_handler then return; end
 	sasl_handler.fast_auth = true; -- For informational purposes
-	-- Copy channel binding info from primary SASL handler
-	sasl_handler.profile.cb = session.sasl_handler.profile.cb;
-	sasl_handler.userdata = session.sasl_handler.userdata;
+	-- Copy channel binding info from primary SASL handler if it's compatible
+	if is_util_sasl(session.sasl_handler) then
+		sasl_handler.profile.cb = session.sasl_handler.profile.cb;
+		sasl_handler.userdata = session.sasl_handler.userdata;
+	end
 	-- Store this handler, in case we later want to use it for authenticating
 	session.fast_sasl_handler = sasl_handler;
 	local fast = st.stanza("fast", { xmlns = xmlns_fast });