@@ -115,6 +115,59 @@ module Stdlib {
115115 }
116116 }
117117 }
118+
119+ /**
120+ * Provides models for the `http.cookies.Morsel` class
121+ *
122+ * See https://docs.python.org/3.9/library/http.cookies.html#http.cookies.Morsel.
123+ */
124+ module Morsel {
125+ /**
126+ * A source of instances of `http.cookies.Morsel`, extend this class to model new instances.
127+ *
128+ * This can include instantiations of the class, return values from function
129+ * calls, or a special parameter that will be set when functions are called by an external
130+ * library.
131+ *
132+ * Use the predicate `Morsel::instance()` to get references to instances of `http.cookies.Morsel`.
133+ */
134+ abstract class InstanceSource extends DataFlow:: LocalSourceNode { }
135+
136+ /** Gets a reference to an instance of `http.cookies.Morsel`. */
137+ private DataFlow:: TypeTrackingNode instance ( DataFlow:: TypeTracker t ) {
138+ t .start ( ) and
139+ result instanceof InstanceSource
140+ or
141+ exists ( DataFlow:: TypeTracker t2 | result = instance ( t2 ) .track ( t2 , t ) )
142+ }
143+
144+ /** Gets a reference to an instance of `http.cookies.Morsel`. */
145+ DataFlow:: Node instance ( ) { instance ( DataFlow:: TypeTracker:: end ( ) ) .flowsTo ( result ) }
146+
147+ /**
148+ * Taint propagation for `http.cookies.Morsel`.
149+ */
150+ private class AdditionalTaintStep extends TaintTracking:: AdditionalTaintStep {
151+ override predicate step ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
152+ // Methods
153+ //
154+ // TODO: When we have tools that make it easy, model these properly to handle
155+ // `meth = obj.meth; meth()`. Until then, we'll use this more syntactic approach
156+ // (since it allows us to at least capture the most common cases).
157+ nodeFrom = instance ( ) and
158+ exists ( DataFlow:: AttrRead attr | attr .getObject ( ) = nodeFrom |
159+ // normal (non-async) methods
160+ attr .getAttributeName ( ) in [ "output" , "js_output" ] and
161+ nodeTo .( DataFlow:: CallCfgNode ) .getFunction ( ) = attr
162+ )
163+ or
164+ // Attributes
165+ nodeFrom = instance ( ) and
166+ nodeTo .( DataFlow:: AttrRead ) .getObject ( ) = nodeFrom and
167+ nodeTo .( DataFlow:: AttrRead ) .getAttributeName ( ) in [ "key" , "value" , "coded_value" ]
168+ }
169+ }
170+ }
118171}
119172
120173/**
0 commit comments