diff options
author | Sebastian Arcila Valenzuela <sarcila@gitlab.com> | 2019-08-19 15:19:19 +0200 |
---|---|---|
committer | Yorick Peterse <yorick@yorickpeterse.com> | 2019-09-30 14:22:06 +0200 |
commit | 3692e9f8a23386c627942ca2a9edd8c00af7e904 (patch) | |
tree | 0d092bdbdfc954e1a9e2b520291a7244c0cd679e /lib/omni_auth/strategies | |
parent | 010e3c5ed41db96f68549e01373a9aacadd995d7 (diff) | |
download | gitlab-ce-3692e9f8a23386c627942ca2a9edd8c00af7e904.tar.gz |
Validate that SAML requests are originated from gitlab
If the request wasn't initiated by gitlab we shouldn't add the new
identity to the user, and instead show that we weren't able to link
the identity to the user.
This should fix: https://gitlab.com/gitlab-org/gitlab-ce/issues/56509
Diffstat (limited to 'lib/omni_auth/strategies')
-rw-r--r-- | lib/omni_auth/strategies/saml.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/omni_auth/strategies/saml.rb b/lib/omni_auth/strategies/saml.rb new file mode 100644 index 00000000000..ebe062f17e0 --- /dev/null +++ b/lib/omni_auth/strategies/saml.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module OmniAuth + module Strategies + class SAML + extend ::Gitlab::Utils::Override + + # NOTE: This method duplicates code from omniauth-saml + # so that we can access authn_request to store it + # See: https://github.com/omniauth/omniauth-saml/issues/172 + override :request_phase + def request_phase + authn_request = OneLogin::RubySaml::Authrequest.new + + store_authn_request_id(authn_request) + + with_settings do |settings| + redirect(authn_request.create(settings, additional_params_for_authn_request)) + end + end + + private + + def store_authn_request_id(authn_request) + Gitlab::Auth::Saml::OriginValidator.new(session).store_origin(authn_request) + end + end + end +end |