3434module XMLSecurity
3535
3636 class BaseDocument < REXML ::Document
37+ REXML ::Document ::entity_expansion_limit = 0
3738
3839 C14N = "http://www.w3.org/2001/10/xml-exc-c14n#"
3940 DSIG = "http://www.w3.org/2000/09/xmldsig#"
41+ NOKOGIRI_OPTIONS = Nokogiri ::XML ::ParseOptions ::STRICT |
42+ Nokogiri ::XML ::ParseOptions ::NONET
4043
4144 def canon_algorithm ( element )
4245 algorithm = element
@@ -106,7 +109,9 @@ def uuid
106109 #<Object />
107110 #</Signature>
108111 def sign_document ( private_key , certificate , signature_method = RSA_SHA1 , digest_method = SHA1 )
109- noko = Nokogiri . parse ( self . to_s )
112+ noko = Nokogiri . parse ( self . to_s ) do |options |
113+ options = XMLSecurity ::BaseDocument ::NOKOGIRI_OPTIONS
114+ end
110115
111116 signature_element = REXML ::Element . new ( "ds:Signature" ) . add_namespace ( 'ds' , DSIG )
112117 signed_info_element = signature_element . add_element ( "ds:SignedInfo" )
@@ -128,7 +133,10 @@ def sign_document(private_key, certificate, signature_method = RSA_SHA1, digest_
128133 reference_element . add_element ( "ds:DigestValue" ) . text = compute_digest ( canon_doc , algorithm ( digest_method_element ) )
129134
130135 # add SignatureValue
131- noko_sig_element = Nokogiri . parse ( signature_element . to_s )
136+ noko_sig_element = Nokogiri . parse ( signature_element . to_s ) do |options |
137+ options = XMLSecurity ::BaseDocument ::NOKOGIRI_OPTIONS
138+ end
139+
132140 noko_signed_info_element = noko_sig_element . at_xpath ( '//ds:Signature/ds:SignedInfo' , 'ds' => DSIG )
133141 canon_string = noko_signed_info_element . canonicalize ( canon_algorithm ( C14N ) )
134142
@@ -178,7 +186,10 @@ class SignedDocument < BaseDocument
178186 def initialize ( response , errors = [ ] )
179187 super ( response )
180188 @errors = errors
181- extract_signed_element_id
189+ end
190+
191+ def signed_element_id
192+ @signed_element_id ||= extract_signed_element_id
182193 end
183194
184195 def validate_document ( idp_cert_fingerprint , soft = true , options = { } )
@@ -221,7 +232,9 @@ def validate_signature(base64_cert, soft = true)
221232 # check for inclusive namespaces
222233 inclusive_namespaces = extract_inclusive_namespaces
223234
224- document = Nokogiri . parse ( self . to_s )
235+ document = Nokogiri . parse ( self . to_s ) do |options |
236+ options = XMLSecurity ::BaseDocument ::NOKOGIRI_OPTIONS
237+ end
225238
226239 # create a working copy so we don't modify the original
227240 @working_copy ||= REXML ::Document . new ( self . to_s ) . root
0 commit comments