1- import javascript
2- import DataFlow
31import advanced_security.javascript.frameworks.ui5.UI5
42import advanced_security.javascript.frameworks.ui5.dataflow.DataFlow
53private import semmle.javascript.frameworks.data.internal.ApiGraphModelsExtensions as ApiGraphModelsExtensions
@@ -648,16 +646,7 @@ class XmlView extends UI5View instanceof XmlFile {
648646 type = result .getControlTypeName ( ) and
649647 ApiGraphModelsExtensions:: sinkModel ( getASuperType ( type ) , path , "ui5-html-injection" , _) and
650648 property = path .replaceAll ( " " , "" ) .regexpCapture ( "Member\\[([^\\]]+)\\]" , 1 ) and
651- result .getBindingTarget ( ) = control .getAttribute ( property ) and
652- /* If the control is an `sap.ui.core.HTML` then the control should be missing the `sanitizeContent` attribute */
653- (
654- getASuperType ( type ) = "HTMLControl"
655- implies
656- (
657- not exists ( control .getAttribute ( "sanitizeContent" ) ) or
658- control .getAttribute ( "sanitizeContent" ) .getValue ( ) = "false"
659- )
660- )
649+ result .getBindingTarget ( ) = control .getAttribute ( property )
661650 )
662651 }
663652
@@ -823,7 +812,7 @@ class UI5Control extends TUI5Control {
823812 }
824813
825814 /** Holds if this control reads from or writes to a model. */
826- predicate accessesModel ( UI5Model model ) { accessesModel ( model , _) }
815+ predicate accessesModel ( UI5Model model ) { this . accessesModel ( model , _) }
827816
828817 /** Holds if this control reads from or writes to a model with regards to a binding path. */
829818 predicate accessesModel ( UI5Model model , XmlBindingPath bindingPath ) {
@@ -842,6 +831,43 @@ class UI5Control extends TUI5Control {
842831
843832 /** Get the controller that manages this control. */
844833 CustomController getController ( ) { result = this .getView ( ) .getController ( ) }
834+
835+ /**
836+ * Gets the full import path of the associated control.
837+ */
838+ string getControlTypeName ( ) { result = this .getQualifiedType ( ) .replaceAll ( "." , "/" ) }
839+
840+ /**
841+ * Holds if the control content is sanitized for HTML
842+ * 'sap/ui/core/HTML' sanitized using the property 'sanitizeContent'
843+ * 'sap/ui/richttexteditor/RichTextEditor' sanitized using the property 'sanitizeValue'
844+ */
845+ predicate isHTMLSanitized ( ) {
846+ this .getControlTypeName ( ) = "sap/ui/richtexteditor/RichTextEditor" and
847+ not this .isSanitizePropertySetTo ( "sanitizeValue" , false )
848+ or
849+ this .getControlTypeName ( ) = "sap/ui/core/HTML" and
850+ this .isSanitizePropertySetTo ( "sanitizeContent" , true ) and
851+ not this .isSanitizePropertySetTo ( "sanitizeContent" , false )
852+ }
853+
854+ bindingset [ propName, val]
855+ private predicate isSanitizePropertySetTo ( string propName , boolean val ) {
856+ /* 1. `sanitizeContent` attribute is set declaratively. */
857+ this .getProperty ( propName ) .toString ( ) = val .toString ( )
858+ or
859+ /* 2. `sanitizeContent` attribute is set programmatically using setProperty(). */
860+ exists ( CallNode node | node = this .getAReference ( ) .getAMemberCall ( "setProperty" ) |
861+ node .getArgument ( 0 ) .getStringValue ( ) = propName and
862+ not node .getArgument ( 1 ) .mayHaveBooleanValue ( val .booleanNot ( ) )
863+ )
864+ or
865+ /* 3. `sanitizeContent` attribute is set programmatically using a setter. */
866+ exists ( CallNode node |
867+ node = this .getAReference ( ) .getAMemberCall ( "setS" + propName .suffix ( 1 ) ) and
868+ not node .getArgument ( 0 ) .mayHaveBooleanValue ( val .booleanNot ( ) )
869+ )
870+ }
845871}
846872
847873private newtype TUI5ControlProperty =
@@ -857,7 +883,7 @@ class UI5ControlProperty extends TUI5ControlProperty {
857883 ValueNode asJsControlProperty ( ) { this = TJsControlProperty ( result ) }
858884
859885 string toString ( ) {
860- result = this .asXmlControlProperty ( ) .toString ( ) or
886+ result = this .asXmlControlProperty ( ) .getValue ( ) . toString ( ) or
861887 result = this .asJsonControlProperty ( ) .toString ( ) or
862888 result = this .asJsControlProperty ( ) .toString ( )
863889 }
0 commit comments