@@ -12,7 +12,66 @@ import semmle.javascript.security.TaintedObject
1212/**
1313 * A taint-tracking configuration for reasoning about unsafe HTML constructed from library input vulnerabilities.
1414 */
15- class Configration extends TaintTracking:: Configuration {
15+ module UnsafeHtmlConstructionConfig implements DataFlow:: StateConfigSig {
16+ class FlowState = DataFlow:: FlowLabel ;
17+
18+ predicate isSource ( DataFlow:: Node source , DataFlow:: FlowLabel label ) {
19+ source instanceof Source and
20+ label = [ TaintedObject:: label ( ) , DataFlow:: FlowLabel:: taint ( ) , DataFlow:: FlowLabel:: data ( ) ]
21+ }
22+
23+ predicate isSink ( DataFlow:: Node sink , DataFlow:: FlowLabel label ) {
24+ sink instanceof Sink and
25+ label = DataFlow:: FlowLabel:: taint ( )
26+ }
27+
28+ predicate isBarrier ( DataFlow:: Node node ) {
29+ node instanceof DomBasedXss:: Sanitizer
30+ or
31+ node instanceof UnsafeJQueryPlugin:: Sanitizer
32+ or
33+ DomBasedXss:: isOptionallySanitizedNode ( node )
34+ }
35+
36+ predicate isBarrier ( DataFlow:: Node node , DataFlow:: FlowLabel label ) {
37+ TaintTracking:: defaultSanitizer ( node ) and label .isTaint ( )
38+ or
39+ node = DataFlow:: MakeLabeledBarrierGuard< BarrierGuard > :: getABarrierNode ( label )
40+ }
41+
42+ predicate isAdditionalFlowStep (
43+ DataFlow:: Node pred , DataFlow:: FlowLabel inlbl , DataFlow:: Node succ , DataFlow:: FlowLabel outlbl
44+ ) {
45+ // TODO: localFieldStep is too expensive with dataflow2
46+ // DataFlow::localFieldStep(pred, succ) and
47+ // inlbl.isTaint() and
48+ // outlbl.isTaint()
49+ none ( )
50+ or
51+ TaintedObject:: step ( pred , succ , inlbl , outlbl )
52+ or
53+ // property read from a tainted object is considered tainted
54+ succ .( DataFlow:: PropRead ) .getBase ( ) = pred and
55+ inlbl = TaintedObject:: label ( ) and
56+ outlbl = DataFlow:: FlowLabel:: taint ( )
57+ or
58+ TaintTracking:: defaultTaintStep ( pred , succ ) and
59+ inlbl .isTaint ( ) and
60+ outlbl = inlbl
61+ }
62+
63+ DataFlow:: FlowFeature getAFeature ( ) { result instanceof DataFlow:: FeatureHasSourceCallContext }
64+ }
65+
66+ /**
67+ * Taint-tracking for reasoning about unsafe HTML constructed from library input vulnerabilities.
68+ */
69+ module UnsafeHtmlConstructionFlow = DataFlow:: GlobalWithState< UnsafeHtmlConstructionConfig > ;
70+
71+ /**
72+ * DEPRECATED. Use the `UnsafeHtmlConstructionFlow` module instead.
73+ */
74+ deprecated class Configration extends TaintTracking:: Configuration {
1675 Configration ( ) { this = "UnsafeHtmlConstruction" }
1776
1877 override predicate isSource ( DataFlow:: Node source , DataFlow:: FlowLabel label ) {
@@ -65,11 +124,10 @@ class Configration extends TaintTracking::Configuration {
65124
66125private import semmle.javascript.security.dataflow.Xss:: Shared as Shared
67126
68- private class QuoteGuard extends TaintTracking :: SanitizerGuardNode , Shared:: QuoteGuard {
127+ private class QuoteGuard extends Shared:: QuoteGuard {
69128 QuoteGuard ( ) { this = this }
70129}
71130
72- private class ContainsHtmlGuard extends TaintTracking:: SanitizerGuardNode , Shared:: ContainsHtmlGuard
73- {
131+ private class ContainsHtmlGuard extends Shared:: ContainsHtmlGuard {
74132 ContainsHtmlGuard ( ) { this = this }
75133}
0 commit comments