mod_http_oauth2: Remove authorization codes after use
RFC 6749 section 4.1.2 says:
> The client MUST NOT use the authorization code more than once.
Thus we clear it from the cache after use.
--- a/mod_http_oauth2/mod_http_oauth2.lua Mon Mar 06 16:49:43 2023 +0100
+++ b/mod_http_oauth2/mod_http_oauth2.lua Mon Mar 06 16:53:27 2023 +0100
@@ -265,6 +265,9 @@
end
local code, err = codes:get(params.client_id .. "#" .. params.code);
if err then error(err); end
+ -- MUST NOT use the authorization code more than once, so remove it to
+ -- prevent a second attempted use
+ codes:set(params.client_id .. "#" .. params.code, nil);
if not code or type(code) ~= "table" or code_expired(code) then
module:log("debug", "authorization_code invalid or expired: %q", code);
return oauth_error("invalid_client", "incorrect credentials");