From fd31477739df198366ee9cb80051bd30a82b91a2 Mon Sep 17 00:00:00 2001 From: DanyLE Date: Fri, 19 Aug 2022 20:01:05 +0200 Subject: [PATCH] Support URLsafe base 64 encoding in API gateway --- os/controllers/SystemController.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/os/controllers/SystemController.lua b/os/controllers/SystemController.lua index 5abe390..bba2250 100644 --- a/os/controllers/SystemController.lua +++ b/os/controllers/SystemController.lua @@ -194,7 +194,14 @@ function SystemController:apigateway(...) data = JSON.decodeString(REQUEST.json) exec_with_user_priv(data) elseif args and #args > 0 then - local decoded = std.b64decode(args[1]) + -- data is encoded in url safe base64 + local encoded = args[1]:gsub('_', '/'):gsub('-', '+') + if #encoded % 4 == 2 then + encoded = encoded.."==" + elseif #encoded %4 == 3 then + encoded = encoded.."=" + end + local decoded = std.b64decode(encoded) data = JSON.decodeString(bytes.__tostring(decoded)) if data and data.path then exec_with_user_priv(data)