mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 07:55:44 +08:00
SECURITY: Add CSRF protections to OpenID callback
This commit is contained in:
@ -85,6 +85,19 @@ class Auth::OpenIdAuthenticator < Auth::Authenticator
|
|||||||
setup: lambda { |env|
|
setup: lambda { |env|
|
||||||
strategy = env["omniauth.strategy"]
|
strategy = env["omniauth.strategy"]
|
||||||
strategy.options[:store] = OpenID::Store::Redis.new($redis)
|
strategy.options[:store] = OpenID::Store::Redis.new($redis)
|
||||||
|
|
||||||
|
# Add CSRF protection in addition to OpenID Specification
|
||||||
|
def strategy.query_string
|
||||||
|
session["omniauth.state"] = state = SecureRandom.hex(24)
|
||||||
|
"?state=#{state}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def strategy.callback_phase
|
||||||
|
stored_state = session.delete("omniauth.state")
|
||||||
|
provided_state = request.params["state"]
|
||||||
|
return fail!(:invalid_credentials) unless provided_state == stored_state
|
||||||
|
super
|
||||||
|
end
|
||||||
},
|
},
|
||||||
name: name,
|
name: name,
|
||||||
identifier: identifier,
|
identifier: identifier,
|
||||||
|
Reference in New Issue
Block a user