Skip to content
Snippets Groups Projects
Unverified Commit f6279c56 authored by David Taylor's avatar David Taylor Committed by GitHub
Browse files

FIX: Simplify data to store in `extra` column (#63)

In production, the SAML omniauth strategy returns some very complex data structures in the `extra` data. These have circular references, and can cause a "stack level too deep" error when serializing to JSON. This commit simplifies thing so we only try to store the attributes hash.
parent 1d8bfdb6
No related branches found
No related tags found
No related merge requests found
...@@ -89,8 +89,7 @@ class SamlAuthenticator < ::Auth::ManagedAuthenticator ...@@ -89,8 +89,7 @@ class SamlAuthenticator < ::Auth::ManagedAuthenticator
end end
def primary_email_verified?(auth_token) def primary_email_verified?(auth_token)
attributes = OneLogin::RubySaml::Attributes.new(auth_token.extra&.[](:raw_info) || {})
attributes = auth_token.extra&.[](:raw_info) || OneLogin::RubySaml::Attributes.new
group_attribute = setting(:groups_attribute) group_attribute = setting(:groups_attribute)
if setting(:validate_email_fields).present? && attributes.multi(group_attribute).present? if setting(:validate_email_fields).present? && attributes.multi(group_attribute).present?
...@@ -121,6 +120,7 @@ class SamlAuthenticator < ::Auth::ManagedAuthenticator ...@@ -121,6 +120,7 @@ class SamlAuthenticator < ::Auth::ManagedAuthenticator
auth.info[:nickname] = uid.to_s auth.info[:nickname] = uid.to_s
end end
auth.extra = { "raw_info" => attributes.attributes }
result = super result = super
if setting(:log_auth) if setting(:log_auth)
......
...@@ -114,7 +114,7 @@ describe SamlAuthenticator do ...@@ -114,7 +114,7 @@ describe SamlAuthenticator do
result = @authenticator.after_authenticate(hash) result = @authenticator.after_authenticate(hash)
SiteSetting.saml_request_attributes.split("|").each do |name| SiteSetting.saml_request_attributes.split("|").each do |name|
expect(result.user.custom_fields["saml_#{name}"]).to eq(hash.extra.raw_info.multi(name).join(",")) expect(result.user.custom_fields["saml_#{name}"]).to eq(hash.extra.raw_info[name].join(","))
end end
end end
...@@ -131,7 +131,7 @@ describe SamlAuthenticator do ...@@ -131,7 +131,7 @@ describe SamlAuthenticator do
SiteSetting.saml_user_field_statements.split("|").each do |statement| SiteSetting.saml_user_field_statements.split("|").each do |statement|
key, id = statement.split(":") key, id = statement.split(":")
expect(result.user.custom_fields["user_field_#{id}"]).to eq(attrs.multi(key).join(",")) expect(result.user.custom_fields["user_field_#{id}"]).to eq(attrs[key].join(","))
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment