@@ -4260,6 +4260,15 @@ module StdlibPrivate {
4260
4260
output = "ReturnValue.ListElement" and
4261
4261
preservesValue = true
4262
4262
or
4263
+ // in case we create a list from a container with precise elementt,
4264
+ // we need to taint the list.
4265
+ exists ( DataFlow:: TupleElementContent tc , int i | i = tc .getIndex ( ) |
4266
+ input = "Argument[0].TupleElement[" + i .toString ( ) + "]"
4267
+ ) and
4268
+ // TODO: Once we have DictKeyContent, we need to transform that into taint
4269
+ output = "ReturnValue" and
4270
+ preservesValue = false
4271
+ or
4263
4272
input = "Argument[0]" and
4264
4273
output = "ReturnValue" and
4265
4274
preservesValue = false
@@ -4708,8 +4717,13 @@ module StdlibPrivate {
4708
4717
override predicate propagatesFlow ( string input , string output , boolean preservesValue ) {
4709
4718
exists ( DataFlow:: DictionaryElementContent dc , string key | key = dc .getKey ( ) |
4710
4719
input = "Argument[self].DictionaryElement[" + key + "]" and
4711
- output = "ReturnValue.ListElement" and
4712
- preservesValue = true
4720
+ (
4721
+ output = "ReturnValue.ListElement" and
4722
+ preservesValue = true
4723
+ or
4724
+ output = "ReturnValue" and
4725
+ preservesValue = false
4726
+ )
4713
4727
)
4714
4728
or
4715
4729
input = "Argument[self]" and
@@ -4759,8 +4773,13 @@ module StdlibPrivate {
4759
4773
override predicate propagatesFlow ( string input , string output , boolean preservesValue ) {
4760
4774
exists ( DataFlow:: DictionaryElementContent dc , string key | key = dc .getKey ( ) |
4761
4775
input = "Argument[self].DictionaryElement[" + key + "]" and
4762
- output = "ReturnValue.ListElement.TupleElement[1]" and
4763
- preservesValue = true
4776
+ (
4777
+ output = "ReturnValue.ListElement.TupleElement[1]" and
4778
+ preservesValue = true
4779
+ or
4780
+ output = "ReturnValue" and
4781
+ preservesValue = false
4782
+ )
4764
4783
)
4765
4784
or
4766
4785
// TODO: Add the keys to output list
@@ -4826,6 +4845,50 @@ module StdlibPrivate {
4826
4845
}
4827
4846
}
4828
4847
4848
+ // ---------------------------------------------------------------------------
4849
+ // Flow summaries for string methods
4850
+ // ---------------------------------------------------------------------------
4851
+ class StringManipulation extends SummarizedCallable {
4852
+ string method_name ;
4853
+
4854
+ StringManipulation ( ) {
4855
+ this = "string." + method_name and
4856
+ method_name in [
4857
+ "capitalize" , "casefold" , "center" , "expandtabs" , "format" , "format_map" , "join" , "ljust" ,
4858
+ "lstrip" , "lower" , "replace" , "rjust" , "rstrip" , "strip" , "swapcase" , "title" , "upper" ,
4859
+ "zfill" , "encode" , "decode"
4860
+ ]
4861
+ }
4862
+
4863
+ override DataFlow:: CallCfgNode getACall ( ) {
4864
+ result .( DataFlow:: MethodCallNode ) .calls ( _, method_name )
4865
+ }
4866
+
4867
+ override DataFlow:: ArgumentNode getACallback ( ) {
4868
+ result .( DataFlow:: AttrRead ) .getAttributeName ( ) = method_name
4869
+ }
4870
+
4871
+ override predicate propagatesFlow ( string input , string output , boolean preservesValue ) {
4872
+ input = "Argument[self]" and
4873
+ output = "ReturnValue" and
4874
+ preservesValue = false
4875
+ or
4876
+ method_name = "join" and
4877
+ exists ( DataFlow:: TupleElementContent tc , int i | i = tc .getIndex ( ) |
4878
+ input = "Argument[0].TupleElement[" + i + "]"
4879
+ ) and
4880
+ output = "ReturnValue" and
4881
+ preservesValue = false
4882
+ or
4883
+ method_name = "format_map" and
4884
+ exists ( DataFlow:: DictionaryElementContent dc , string key | key = dc .getKey ( ) |
4885
+ input = "Argument[0].DictionaryElement[" + key + "]"
4886
+ ) and
4887
+ output = "ReturnValue" and
4888
+ preservesValue = false
4889
+ }
4890
+ }
4891
+
4829
4892
/**
4830
4893
* A flow summary for `os.getenv` / `os.getenvb`
4831
4894
*
0 commit comments