Pārlūkot izejas kodu

SHA256 hash the kid claim before fetching tokens

master
Sam Whited 8 gadus atpakaļ
vecāks
revīzija
d8c4c0627a
1 mainītis faili ar 7 papildinājumiem un 1 dzēšanām
  1. 7
    1
      prosody-plugins/mod_auth_token.lua

+ 7
- 1
prosody-plugins/mod_auth_token.lua Parādīt failu

9
 local json = require "cjson";
9
 local json = require "cjson";
10
 local new_sasl = require "util.sasl".new;
10
 local new_sasl = require "util.sasl".new;
11
 local sasl = require "util.sasl";
11
 local sasl = require "util.sasl";
12
+local sha256 = require "util.hashes".sha256;
12
 local timer = require "util.timer";
13
 local timer = require "util.timer";
13
 local token_util = module:require "token/util";
14
 local token_util = module:require "token/util";
14
 
15
 
96
 			done();
97
 			done();
97
 		end
98
 		end
98
 		module:log("debug", "Fetching public key from: "..asapKeyServer..keyId);
99
 		module:log("debug", "Fetching public key from: "..asapKeyServer..keyId);
99
-		local request = http.request(asapKeyServer..keyId, {
100
+
101
+		-- We hash the key ID to work around some legacy behavior in the original
102
+		-- deployment and make deployment easier. It also helps prevent directory
103
+		-- traversal attacks (although path cleaning could have done this too).
104
+		local request = http.request(asapKeyServer..sha256(keyId)..'.pem', {
100
 			headers = http_headers or {},
105
 			headers = http_headers or {},
101
 			method = "GET"
106
 			method = "GET"
102
 		}, cb);
107
 		}, cb);
108
+
103
 		-- TODO: Is the done() call racey? Can we cancel this if the request
109
 		-- TODO: Is the done() call racey? Can we cancel this if the request
104
 		--       succeedes?
110
 		--       succeedes?
105
 		local function cancel()
111
 		local function cancel()

Notiek ielāde…
Atcelt
Saglabāt