saml2 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a2a3fe46968c45f6286e8d20892d5e450d7cd2d
4
- data.tar.gz: 38b77b60cfba7566d3de65ac158161cb238e56b5
3
+ metadata.gz: 5806ee95e988647a1593ddb8c9f833b1c0ae9064
4
+ data.tar.gz: 536f3c655fb7e81ff79003f46dbd1f3d9ec76d3e
5
5
  SHA512:
6
- metadata.gz: 5b669dcc2296c61d1fa14a51ef26b7152d529c4e78a2bc57875bfcc132e0c4623ed0ebc6e78616fd3c4d0f68eed3e51f6a9a5da3c85a89bf977287ccf40a0dd5
7
- data.tar.gz: 47ccb4ab69acf34047e79806ff37ea8dd5a114d798bac3544b62294bab07268574a66c217ea7ccd2a963291c6d0974b73141312e9f6dd3078ef707e3801e912d
6
+ metadata.gz: 487c35b7ae581c8dcc89140341cbb7d1513eac561c571b416c4b5a889b2010eacfae9250f7462837425487b90dec337e0c26456c085cf392b2f3c55bb0ab63ca
7
+ data.tar.gz: ac21dc27daa7f8297187dd7f7a2f9797fdb9fe3c4bb986d7d258edd296a9709ab1ec2a9b3fea0b89fd2b251fec4547ccef31b08c06352459f14ca79d6a49dfc4
data/lib/saml2.rb CHANGED
@@ -6,4 +6,9 @@ require 'saml2/version'
6
6
  require 'saml2/engine' if defined?(::Rails) && Rails::VERSION::MAJOR > 2
7
7
 
8
8
  module SAML2
9
+ class << self
10
+ def config
11
+ @config ||= { max_message_size: 1024 * 1024 }
12
+ end
13
+ end
9
14
  end
@@ -31,13 +31,13 @@ module SAML2
31
31
  ID: id,
32
32
  Version: '2.0',
33
33
  IssueInstant: issue_instant.iso8601
34
- ) do |builder|
35
- issuer.build(builder, element: 'Issuer')
34
+ ) do |assertion|
35
+ issuer.build(assertion, element: 'Issuer')
36
36
 
37
- subject.build(builder)
37
+ subject.build(assertion)
38
38
 
39
- conditions.build(builder)
40
- statements.each { |stmt| stmt.build(builder) }
39
+ conditions.build(assertion)
40
+ statements.each { |stmt| stmt.build(assertion) }
41
41
  end
42
42
  end.doc.root
43
43
  end
@@ -52,13 +52,13 @@ module SAML2
52
52
  end
53
53
 
54
54
  def build(builder)
55
- builder['saml'].Attribute('Name' => name) do |builder|
56
- builder.parent['FriendlyName'] = friendly_name if friendly_name
57
- builder.parent['NameFormat'] = name_format if name_format
55
+ builder['saml'].Attribute('Name' => name) do |attribute|
56
+ attribute.parent['FriendlyName'] = friendly_name if friendly_name
57
+ attribute.parent['NameFormat'] = name_format if name_format
58
58
  Array.wrap(value).each do |value|
59
59
  xsi_type, val = convert_to_xsi(value)
60
- builder['saml'].AttributeValue(val) do |builder|
61
- builder.parent['xsi:type'] = xsi_type if xsi_type
60
+ attribute['saml'].AttributeValue(val) do |attribute_value|
61
+ attribute_value.parent['xsi:type'] = xsi_type if xsi_type
62
62
  end
63
63
  end
64
64
  end
@@ -68,8 +68,8 @@ module SAML2
68
68
  @name = node['Name']
69
69
  @friendly_name = node['FriendlyName']
70
70
  @name_format = node['NameFormat']
71
- values = node.xpath('saml:AttributeValue', Namespaces::ALL).map do |node|
72
- convert_from_xsi(node.attribute_with_ns('type', Namespaces::XSI), node.content && node.content.strip)
71
+ values = node.xpath('saml:AttributeValue', Namespaces::ALL).map do |value|
72
+ convert_from_xsi(value.attribute_with_ns('type', Namespaces::XSI), value.content && value.content.strip)
73
73
  end
74
74
  @value = case values.length
75
75
  when 0; nil
@@ -131,8 +131,8 @@ module SAML2
131
131
 
132
132
  def build(builder)
133
133
  builder['saml'].AttributeStatement('xmlns:xs' => Namespaces::XS,
134
- 'xmlns:xsi' => Namespaces::XSI) do |builder|
135
- @attributes.each { |attr| attr.build(builder) }
134
+ 'xmlns:xsi' => Namespaces::XSI) do |statement|
135
+ @attributes.each { |attr| attr.build(statement) }
136
136
  end
137
137
  end
138
138
  end
@@ -9,16 +9,28 @@ require 'saml2/schemas'
9
9
  require 'saml2/subject'
10
10
 
11
11
  module SAML2
12
+ class MessageTooLarge < RuntimeError
13
+ end
14
+
12
15
  class AuthnRequest
13
16
  def self.decode(authnrequest)
14
17
  begin
15
- zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
16
- authnrequest = zstream.inflate(Base64.decode64(authnrequest))
17
- zstream.finish
18
+ raise MessageTooLarge if authnrequest.bytesize > SAML2.config[:max_message_size]
19
+ authnrequest = Base64.decode64(authnrequest)
20
+ zstream = Zlib::Inflate.new
21
+ xml = ''
22
+ # do it in 1K slices, so we can protect against bombs
23
+ (0..authnrequest.bytesize / 1024).each do |i|
24
+ xml.concat(zstream.inflate(authnrequest.byteslice(i * 1024, 1024)))
25
+ raise MessageTooLarge if xml.bytesize > SAML2.config[:max_message_size]
26
+ end
27
+ xml.concat(zstream.finish)
28
+ raise MessageTooLarge if xml.bytesize > SAML2.config[:max_message_size]
29
+
18
30
  zstream.close
19
- rescue Zlib::BufError
31
+ rescue Zlib::DataError, Zlib::BufError
20
32
  end
21
- parse(authnrequest)
33
+ parse(xml)
22
34
  end
23
35
 
24
36
  def self.parse(authnrequest)
@@ -16,9 +16,9 @@ module SAML2
16
16
  attr_accessor :authn_instant, :authn_context_class_ref
17
17
 
18
18
  def build(builder)
19
- builder['saml'].AuthnStatement('AuthnInstant' => authn_instant.iso8601) do |builder|
20
- builder['saml'].AuthnContext do |builder|
21
- builder['saml'].AuthnContextClassRef(authn_context_class_ref) if authn_context_class_ref
19
+ builder['saml'].AuthnStatement('AuthnInstant' => authn_instant.iso8601) do |authn_statement|
20
+ authn_statement['saml'].AuthnContext do |authn_context|
21
+ authn_context['saml'].AuthnContextClassRef(authn_context_class_ref) if authn_context_class_ref
22
22
  end
23
23
  end
24
24
  end
data/lib/saml2/base.rb CHANGED
@@ -27,17 +27,17 @@ module SAML2
27
27
  end
28
28
 
29
29
  def self.load_string_array(node, element)
30
- node.xpath(element, Namespaces::ALL).map do |node|
31
- node.content && node.content.strip
30
+ node.xpath(element, Namespaces::ALL).map do |element_node|
31
+ element_node.content && element_node.content.strip
32
32
  end
33
33
  end
34
34
 
35
35
  def self.load_object_array(node, element, klass)
36
- node.xpath(element, Namespaces::ALL).map do |node|
36
+ node.xpath(element, Namespaces::ALL).map do |element_node|
37
37
  if klass.is_a?(Hash)
38
- klass[node.name].from_xml(node)
38
+ klass[element_node.name].from_xml(element_node)
39
39
  else
40
- klass.from_xml(node)
40
+ klass.from_xml(element_node)
41
41
  end
42
42
  end
43
43
  end
@@ -26,12 +26,12 @@ module SAML2
26
26
  end
27
27
 
28
28
  def build(builder)
29
- builder['saml'].Conditions do |builder|
30
- builder.parent['NotBefore'] = not_before.iso8601 if not_before
31
- builder.parent['NotOnOrAfter'] = not_on_or_after.iso8601 if not_on_or_after
29
+ builder['saml'].Conditions do |conditions|
30
+ conditions.parent['NotBefore'] = not_before.iso8601 if not_before
31
+ conditions.parent['NotOnOrAfter'] = not_on_or_after.iso8601 if not_on_or_after
32
32
 
33
33
  each do |condition|
34
- condition.build(builder)
34
+ condition.build(conditions)
35
35
  end
36
36
  end
37
37
  end
@@ -55,9 +55,9 @@ module SAML2
55
55
  end
56
56
 
57
57
  def build(builder)
58
- builder['saml'].AudienceRestriction do |builder|
58
+ builder['saml'].AudienceRestriction do |audience_restriction|
59
59
  Array.wrap(audience).each do |single_audience|
60
- builder['saml'].Audience(single_audience)
60
+ audience_restriction['saml'].Audience(single_audience)
61
61
  end
62
62
  end
63
63
  end
data/lib/saml2/contact.rb CHANGED
@@ -34,15 +34,15 @@ module SAML2
34
34
  end
35
35
 
36
36
  def build(builder)
37
- builder['md'].ContactPerson('contactType' => type) do |builder|
38
- builder['md'].Company(company) if company
39
- builder['md'].GivenName(given_name) if given_name
40
- builder['md'].SurName(surname) if surname
37
+ builder['md'].ContactPerson('contactType' => type) do |contact_person|
38
+ contact_person['md'].Company(company) if company
39
+ contact_person['md'].GivenName(given_name) if given_name
40
+ contact_person['md'].SurName(surname) if surname
41
41
  email_addresses.each do |email|
42
- builder['md'].EmailAddress(email)
42
+ contact_person['md'].EmailAddress(email)
43
43
  end
44
44
  telephone_numbers.each do |tel|
45
- builder['md'].TelephoneNumber(tel)
45
+ contact_person['md'].TelephoneNumber(tel)
46
46
  end
47
47
  end
48
48
  end
data/lib/saml2/entity.rb CHANGED
@@ -120,9 +120,9 @@ module SAML2
120
120
  builder['md'].EntityDescriptor('entityID' => entity_id,
121
121
  'xmlns:md' => Namespaces::METADATA,
122
122
  'xmlns:dsig' => Namespaces::DSIG,
123
- 'xmlns:xenc' => Namespaces::XENC) do |builder|
123
+ 'xmlns:xenc' => Namespaces::XENC) do |entity_descriptor|
124
124
  roles.each do |role|
125
- role.build(builder)
125
+ role.build(entity_descriptor)
126
126
  end
127
127
 
128
128
  super
@@ -41,21 +41,21 @@ module SAML2
41
41
  end
42
42
 
43
43
  def build(builder)
44
- builder['md'].IDPSSODescriptor do |builder|
45
- super(builder)
44
+ builder['md'].IDPSSODescriptor do |idp_sso_descriptor|
45
+ super(idp_sso_descriptor)
46
46
 
47
- builder['WantAuthnRequestsSigned'] = want_authn_requests_signed? unless want_authn_requests_signed?.nil?
47
+ idp_sso_descriptor['WantAuthnRequestsSigned'] = want_authn_requests_signed? unless want_authn_requests_signed?.nil?
48
48
 
49
49
  single_sign_on_services.each do |sso|
50
- sso.build(builder, 'SingleSignOnService')
50
+ sso.build(idp_sso_descriptor, 'SingleSignOnService')
51
51
  end
52
52
 
53
53
  attribute_profiles.each do |ap|
54
- builder['md'].AttributeProfile(ap)
54
+ idp_sso_descriptor['md'].AttributeProfile(ap)
55
55
  end
56
56
 
57
57
  attributes.each do |attr|
58
- attr.build(builder)
58
+ attr.build(idp_sso_descriptor)
59
59
  end
60
60
  end
61
61
  end
data/lib/saml2/key.rb CHANGED
@@ -38,15 +38,15 @@ module SAML2
38
38
  end
39
39
 
40
40
  def build(builder)
41
- builder['md'].KeyDescriptor do |builder|
42
- builder.parent['use'] = use if use
43
- builder['dsig'].KeyInfo do |builder|
44
- builder['dsig'].X509Data do |builder|
45
- builder['dsig'].X509Certificate(x509)
41
+ builder['md'].KeyDescriptor do |key_descriptor|
42
+ key_descriptor.parent['use'] = use if use
43
+ key_descriptor['dsig'].KeyInfo do |key_info|
44
+ key_info['dsig'].X509Data do |x509_data|
45
+ x509_data['dsig'].X509Certificate(x509)
46
46
  end
47
47
  end
48
48
  encryption_methods.each do |method|
49
- builder['xenc'].EncryptionMethod('Algorithm' => method)
49
+ key_descriptor['xenc'].EncryptionMethod('Algorithm' => method)
50
50
  end
51
51
  end
52
52
  end
@@ -37,10 +37,10 @@ module SAML2
37
37
  end
38
38
 
39
39
  def build(builder)
40
- builder['md'].Organization do |builder|
41
- self.class.build(builder, @name, 'OrganizationName')
42
- self.class.build(builder, @display_name, 'OrganizationDisplayName')
43
- self.class.build(builder, @url, 'OrganizationURL')
40
+ builder['md'].Organization do |organization|
41
+ self.class.build(organization, @name, 'OrganizationName')
42
+ self.class.build(organization, @display_name, 'OrganizationDisplayName')
43
+ self.class.build(organization, @url, 'OrganizationURL')
44
44
  end
45
45
  end
46
46
 
@@ -77,17 +77,17 @@ module SAML2
77
77
  Version: '2.0',
78
78
  IssueInstant: issue_instant.iso8601,
79
79
  Destination: destination
80
- ) do |builder|
81
- builder.parent['InResponseTo'] = in_response_to if in_response_to
80
+ ) do |response|
81
+ response.parent['InResponseTo'] = in_response_to if in_response_to
82
82
 
83
- issuer.build(builder, element: 'Issuer', include_namespace: true) if issuer
83
+ issuer.build(response, element: 'Issuer', include_namespace: true) if issuer
84
84
 
85
- builder['samlp'].Status do |builder|
86
- builder['samlp'].StatusCode(Value: status_code)
85
+ response['samlp'].Status do |status|
86
+ status['samlp'].StatusCode(Value: status_code)
87
87
  end
88
88
 
89
89
  assertions.each do |assertion|
90
- builder.parent << assertion.to_xml
90
+ response.parent << assertion.to_xml
91
91
  end
92
92
  end
93
93
  end
data/lib/saml2/sso.rb CHANGED
@@ -2,8 +2,6 @@ require 'saml2/role'
2
2
 
3
3
  module SAML2
4
4
  class SSO < Role
5
- attr_reader :single_logout_services, :name_id_formats
6
-
7
5
  def initialize
8
6
  super
9
7
  @single_logout_services = []
data/lib/saml2/subject.rb CHANGED
@@ -14,9 +14,9 @@ module SAML2
14
14
  end
15
15
 
16
16
  def build(builder)
17
- builder['saml'].Subject do |builder|
18
- name_id.build(builder) if name_id
19
- confirmation.build(builder) if confirmation
17
+ builder['saml'].Subject do |subject|
18
+ name_id.build(subject) if name_id
19
+ confirmation.build(subject) if confirmation
20
20
  end
21
21
  end
22
22
 
@@ -30,16 +30,16 @@ module SAML2
30
30
  attr_accessor :method, :not_before, :not_on_or_after, :recipient, :in_response_to
31
31
 
32
32
  def build(builder)
33
- builder['saml'].SubjectConfirmation('Method' => method) do |builder|
33
+ builder['saml'].SubjectConfirmation('Method' => method) do |subject_confirmation|
34
34
  if in_response_to ||
35
35
  recipient ||
36
36
  not_before ||
37
37
  not_on_or_after
38
- builder['saml'].SubjectConfirmationData do |builder|
39
- builder.parent['NotBefore'] = not_before.iso8601 if not_before
40
- builder.parent['NotOnOrAfter'] = not_on_or_after.iso8601 if not_on_or_after
41
- builder.parent['Recipient'] = recipient if recipient
42
- builder.parent['InResponseTo'] = in_response_to if in_response_to
38
+ subject_confirmation['saml'].SubjectConfirmationData do |subject_confirmation_data|
39
+ subject_confirmation_data.parent['NotBefore'] = not_before.iso8601 if not_before
40
+ subject_confirmation_data.parent['NotOnOrAfter'] = not_on_or_after.iso8601 if not_on_or_after
41
+ subject_confirmation_data.parent['Recipient'] = recipient if recipient
42
+ subject_confirmation_data.parent['InResponseTo'] = in_response_to if in_response_to
43
43
  end
44
44
  end
45
45
  end
data/lib/saml2/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SAML2
2
- VERSION = '1.0.8'
2
+ VERSION = '1.0.9'
3
3
  end
@@ -119,7 +119,7 @@ module SAML2
119
119
  attr.value = 'value'
120
120
  acs.requested_attributes << attr
121
121
  stmt = acs.create_statement({})
122
- stmt.must_equal nil
122
+ assert_nil(stmt)
123
123
  end
124
124
 
125
125
  end
@@ -4,9 +4,9 @@ module SAML2
4
4
  describe Attribute do
5
5
  def serialize(attribute)
6
6
  doc = Nokogiri::XML::Builder.new do |builder|
7
- builder['saml'].Root('xmlns:saml' => Namespaces::SAML) do |builder|
8
- attribute.build(builder)
9
- builder.parent.child['xmlns:saml'] = Namespaces::SAML
7
+ builder['saml'].Root('xmlns:saml' => Namespaces::SAML) do |root|
8
+ attribute.build(root)
9
+ root.parent.child['xmlns:saml'] = Namespaces::SAML
10
10
  end
11
11
  end.doc
12
12
  doc.root.child.to_s
@@ -15,6 +15,11 @@ module SAML2
15
15
  authnrequest = AuthnRequest.decode('abc')
16
16
  authnrequest.valid_schema?.must_equal false
17
17
  end
18
+
19
+ it "doesn't allow deflate bombs" do
20
+ bomb = Base64.encode64(Zlib::Deflate.deflate("\0" * 2 * 1024 * 1024))
21
+ -> { AuthnRequest.decode(bomb) }.must_raise MessageTooLarge
22
+ end
18
23
  end
19
24
 
20
25
  it "should be valid" do
@@ -9,12 +9,12 @@ module SAML2
9
9
 
10
10
  it "should return nil when not valid schema" do
11
11
  entity = Entity.parse("<xml></xml>")
12
- entity.must_equal nil
12
+ assert_nil(entity)
13
13
  end
14
14
 
15
15
  it "should return nil on non-XML" do
16
16
  entity = Entity.parse("garbage")
17
- entity.must_equal nil
17
+ assert_nil(entity)
18
18
  end
19
19
 
20
20
  describe "valid schema" do
@@ -27,7 +27,7 @@ module SAML2
27
27
  it "should parse the organization" do
28
28
  entity.organization.display_name.must_equal 'Canvas'
29
29
  entity.organization.display_name('en').must_equal 'Canvas'
30
- entity.organization.display_name('es').must_equal nil
30
+ assert_nil(entity.organization.display_name('es'))
31
31
  entity.organization.display_name(:all).must_equal en: 'Canvas'
32
32
  end
33
33
 
@@ -16,7 +16,7 @@ module SAML2
16
16
  acses.map(&:location).must_equal ['a', 'b']
17
17
  acses[1].location.must_equal 'a'
18
18
  acses[3].location.must_equal 'b'
19
- acses[0].must_equal nil
19
+ assert_nil(acses[0])
20
20
  end
21
21
 
22
22
  describe "#default" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saml2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-06 00:00:00.000000000 Z
11
+ date: 2017-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  requirements: []
195
195
  rubyforge_project:
196
- rubygems_version: 2.6.10
196
+ rubygems_version: 2.6.11
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: SAML 2.0 Library