Diff

mod_http_oauth2/mod_http_oauth2.lua @ 6308:e1c54de06905

mod_http_oauth2: Handle case of device state having expired If for some reason the `code` was nil, it would have thrown an error attempting to index it.
author Kim Alvefur <zash@zash.se>
date Fri, 13 Jun 2025 21:57:38 +0200
parent 6307:aae94f82c56e
child 6309:342f88e8d522
child 6317:8108aec64fb9
line wrap: on
line diff
--- a/mod_http_oauth2/mod_http_oauth2.lua	Fri Jun 13 21:30:56 2025 +0200
+++ b/mod_http_oauth2/mod_http_oauth2.lua	Fri Jun 13 21:57:38 2025 +0200
@@ -796,9 +796,11 @@
 		if is_device then
 			local device_code = b64url(hashes.hmac_sha256(verification_key, device_state.user_code));
 			local code = codes:get("device_code:" .. params.client_id .. "#" .. device_code);
-			code.error = err;
-			code.expires = os.time() + 60;
-			codes:set("device_code:" .. params.client_id .. "#" .. device_code, code);
+			if type(code) == "table" then
+				code.error = err;
+				code.expires = os.time() + 60;
+				codes:set("device_code:" .. params.client_id .. "#" .. device_code, code);
+			end
 		end
 		return render_error(err);
 	end