Переглянути джерело

SHA256 hash the kid claim before fetching tokens

master
Sam Whited 8 роки тому
джерело
коміт
d8c4c0627a
1 змінених файлів з 7 додано та 1 видалено
  1. 7
    1
      prosody-plugins/mod_auth_token.lua

+ 7
- 1
prosody-plugins/mod_auth_token.lua Переглянути файл

@@ -9,6 +9,7 @@ local http = require "net.http";
9 9
 local json = require "cjson";
10 10
 local new_sasl = require "util.sasl".new;
11 11
 local sasl = require "util.sasl";
12
+local sha256 = require "util.hashes".sha256;
12 13
 local timer = require "util.timer";
13 14
 local token_util = module:require "token/util";
14 15
 
@@ -96,10 +97,15 @@ function get_public_key(keyId)
96 97
 			done();
97 98
 		end
98 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 105
 			headers = http_headers or {},
101 106
 			method = "GET"
102 107
 		}, cb);
108
+
103 109
 		-- TODO: Is the done() call racey? Can we cancel this if the request
104 110
 		--       succeedes?
105 111
 		local function cancel()

Завантаження…
Відмінити
Зберегти