mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-19 09:05:46 +00:00
TRA-3311 validate xml before parsing
TRA-3311 validate xml before parsing
This commit is contained in:
@@ -2,6 +2,8 @@ package sensitiveDataFiltering
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"mizuserver/pkg/tap"
|
||||
"net/url"
|
||||
@@ -103,6 +105,9 @@ func filterPlainText(bytes []byte, options *shared.TrafficFilteringOptions) []by
|
||||
}
|
||||
|
||||
func filterXmlEtree(bytes []byte) ([]byte, error) {
|
||||
if !IsValidXML(bytes) {
|
||||
return nil, errors.New("Invalid XML")
|
||||
}
|
||||
xmlDoc := etree.NewDocument()
|
||||
err := xmlDoc.ReadFromBytes(bytes)
|
||||
if err != nil {
|
||||
@@ -113,6 +118,10 @@ func filterXmlEtree(bytes []byte) ([]byte, error) {
|
||||
return xmlDoc.WriteToBytes()
|
||||
}
|
||||
|
||||
func IsValidXML(data []byte) bool {
|
||||
return xml.Unmarshal(data, new(interface{})) == nil
|
||||
}
|
||||
|
||||
func filterXmlElement(element *etree.Element) {
|
||||
for i, attribute := range element.Attr {
|
||||
if isFieldNameSensitive(attribute.Key) {
|
||||
|
Reference in New Issue
Block a user