瀏覽代碼

change cjson to cjson.safe and cath error from decode function

j8
Wuriyanto 5 年之前
父節點
當前提交
1b8e5d0244
共有 1 個檔案被更改,包括 6 行新增3 行删除
  1. 6
    3
      resources/prosody-plugins/token/util.lib.lua

+ 6
- 3
resources/prosody-plugins/token/util.lib.lua 查看文件

@@ -7,7 +7,7 @@ local hex = require "util.hex";
7 7
 local jwt = require "luajwtjitsi";
8 8
 local http = require "net.http";
9 9
 local jid = require "util.jid";
10
-local json = require "cjson";
10
+local json_safe = require "cjson.safe";
11 11
 local path = require "util.paths";
12 12
 local sha256 = require "util.hashes".sha256;
13 13
 local timer = require "util.timer";
@@ -255,7 +255,10 @@ function Util:process_and_verify_token(session)
255 255
     if self.asapKeyServer and session.auth_token ~= nil then
256 256
         local dotFirst = session.auth_token:find("%.");
257 257
         if not dotFirst then return nil, "Invalid token" end
258
-        local header = json.decode(basexx.from_url64(session.auth_token:sub(1,dotFirst-1)));
258
+        local header, err = json_safe.decode(basexx.from_url64(session.auth_token:sub(1,dotFirst-1)));
259
+        if err then
260
+            return false, "not-allowed", "bad token format";
261
+        end
259 262
         local kid = header["kid"];
260 263
         if kid == nil then
261 264
             return false, "not-allowed", "'kid' claim is missing";
@@ -398,4 +401,4 @@ function Util:verify_room(session, room_address)
398 401
     end
399 402
 end
400 403
 
401
-return Util;
404
+return Util;

Loading…
取消
儲存