Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-8391

Regex for addSensitiveElementNames is replace only the last element

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.4.2
    • 3.4.3
    • logging
    • Novice

    Description

      Regex Template (MATCH_PATTERN_XML_TEMPLATE) used in MaskSensitiveHelper class for replace all ocurrs of element in XML is getting always only one ocurrs when you have a list of elements to replace.

      In this sample of xml

      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      	<soap:Body>
      		<ns1:listResponse xmlns:ns1="http://acme.org/">
      			<return xmlns:ns2="http://acme.org/">
      				<description>Winter fruit</description>
      				<name>Apple1</name>
      			</return>
      			<return xmlns:ns2="http://acme.org/">
      				<description>Tropical fruit</description>
      				<name>Pineapple1</name>
      			</return>
      		</ns1:listResponse>
      	</soap:Body>
      </soap:Envelope>
      

       if you need to replace the content of element <description>, the regex used for

      "(<description.*>)(.*?)(</description>)"
      

       will started at '<description>Winter fruit' and end at

      'Tropical fruit</description>' , because of this the replaceAll will replace the last occurs in XML.

      To fix it we have to change the match pattern xml template.

      The correct value for it has to be 

        private static final String MATCH_PATTERN_XML_TEMPLATE = "(<-ELEMENT_NAME-*.?>)(.*?)(</-ELEMENT_NAME->)";
      

      not

        private static final String MATCH_PATTERN_XML_TEMPLATE = "(<-ELEMENT_NAME-.*>)(.*?)(</-ELEMENT_NAME->)";
      

       

      Attachments

        Activity

          People

            ashakirin Andrei Shakirin
            carlospanarello Carlos Eduardo Panarello
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Remaining Estimate - 2h
                2h
                Logged:
                Time Spent - Not Specified
                Not Specified