Skip to content

Commit

Permalink
Add 'name' clause to all Pysa DSL ModelQueries in fbsource
Browse files Browse the repository at this point in the history
Summary: Currently, the `name` clause for Pysa DSL `ModelQuery`s is optional. We want to make this clause mandatory so that each ModelQuery will have a unique identifier that can be used to query them and log stats. To prepare for that change, I added `name` clauses to all existing `ModelQuery`s in `.pysa` files in the `fbsource` repository.

Reviewed By: alexkassil

Differential Revision: D36728220

fbshipit-source-id: 4f411a415e7a74b89e7f67674bac8873cc2947a9
  • Loading branch information
Grace Xin authored and facebook-github-bot committed Jun 2, 2022
1 parent 2c5ca1a commit ead350b
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 0 deletions.
Expand Up @@ -2,6 +2,7 @@ def _test_sink(arg: TaintSink[Test]): ...
def _test_source() -> TaintSource[Test]: ...

ModelQuery(
name = "get_foo_lhs_sources",
find = "functions",
where = [name.matches("foo")],
model = [
Expand All @@ -10,6 +11,7 @@ ModelQuery(
)

ModelQuery(
name = "get_foo_rhs_sources",
find = "methods",
where = [name.matches("foo")],
model = [
Expand All @@ -18,6 +20,7 @@ ModelQuery(
)

ModelQuery(
name = "get_parameters_sources",
find = "functions",
where = [name.matches("parameters")],
model = [
Expand All @@ -28,6 +31,7 @@ ModelQuery(

# Test positional parameters.
ModelQuery(
name = "get_positional_sources",
find = "functions",
where = [name.matches("positional")],
model = [
Expand All @@ -37,6 +41,7 @@ ModelQuery(

# For methods, self is index 0.
ModelQuery(
name = "get_positional_lhs_sources",
find = "methods",
where = [name.matches("positional")],
model = [
Expand All @@ -46,6 +51,7 @@ ModelQuery(
)

ModelQuery(
name = "get_Base_child_sources",
find = "methods",
where = [parent.equals("model_query.Base")],
model = [
Expand All @@ -54,6 +60,7 @@ ModelQuery(
)

ModelQuery(
name = "get_Base_subclass_sources",
find = "methods",
where = [parent.extends("model_query.Base")],
model = [
Expand All @@ -63,6 +70,7 @@ ModelQuery(

# Test attribute models
ModelQuery(
name = "get_AttributeModel_SourceA",
find = "attributes",
where = [parent.extends("model_query.AttributeTestBase")],
model = [
Expand All @@ -71,6 +79,7 @@ ModelQuery(
)

ModelQuery(
name = "get_foo_SourceB",
find = "attributes",
where = [name.matches("foo")],
model = [
Expand All @@ -80,6 +89,7 @@ ModelQuery(

# Test attribute model queries work with existing models
ModelQuery(
name = "get_AttributeTestClass3_SinkA",
find = "attributes",
where = [parent.equals("model_query.AttributeTestClass3")],
model = [
Expand All @@ -92,6 +102,7 @@ def model_query.alarm_5(source: TaintSource[Test]): ...


ModelQuery(
name = "get_AttributeTestClass4_SourceC",
find = "attributes",
where = [parent.equals("model_query.AttributeTestClass4")],
model = [
Expand All @@ -104,6 +115,7 @@ def model_query.alarm_7() -> TaintSink[Test]: ...

# Testing some attribute queries that shouldn't generate any models
ModelQuery(
name = "get_nothingshouldmatchthis_sources",
find = "attributes",
where = [name.matches("nothingshouldmatchthis")],
model = [
Expand All @@ -112,6 +124,7 @@ ModelQuery(
)

ModelQuery(
name = "get_NonExistentClass_sources",
find = "attributes",
where = [parent.equals("NonExistentClass")],
model = [
Expand All @@ -120,6 +133,7 @@ ModelQuery(
)

ModelQuery(
name = "get_NonExistentClass_subclass_sources",
find = "attributes",
where = [parent.extends("NonExistentClass")],
model = [
Expand All @@ -128,6 +142,7 @@ ModelQuery(
)

ModelQuery(
name = "get_method1_SourceA",
find = "methods",
where = [
AllOf(
Expand All @@ -141,6 +156,7 @@ ModelQuery(
)

ModelQuery(
name = "get_function_test1_SourceA",
find = "functions",
where = [name.matches("function_test1"), Not(name.matches("noalarm"))],
model = [
Expand All @@ -150,6 +166,7 @@ ModelQuery(


ModelQuery(
name = "get_method_test1_SourceB",
find = "methods",
where = [
parent.matches("model_query.ClassTest1"),
Expand All @@ -163,6 +180,7 @@ ModelQuery(


ModelQuery(
name = "get_ClassTest2_SourceC",
find = "methods",
where = [
parent.matches("ClassTest2"),
Expand Down
Expand Up @@ -2,6 +2,7 @@ def _test_sink(arg: TaintSink[Test, Via[special_sink]]): ...
def _test_source() -> TaintSource[Test, Via[special_source]]: ...

ModelQuery(
name = "get_test1_sources",
find = "attributes",
where = [
parent.equals("model_query_annotated.Test1_C"),
Expand All @@ -13,6 +14,7 @@ ModelQuery(
)

ModelQuery(
name = "get_test2_sources",
find = "attributes",
where = [
parent.equals("model_query_annotated.Test2_C"),
Expand All @@ -27,6 +29,7 @@ ModelQuery(
)

ModelQuery(
name = "get_test3_sources",
find = "functions",
where = [
name.matches("test3_"),
Expand Down
@@ -1,4 +1,5 @@
ModelQuery(
name = "get_test1_sources",
find = "functions",
where = [
name.matches("test1_"),
Expand All @@ -10,6 +11,7 @@ ModelQuery(
)

ModelQuery(
name = "get_test2_sources",
find = "functions",
where = [
name.matches("test2_"),
Expand All @@ -21,6 +23,7 @@ ModelQuery(
)

ModelQuery(
name = "get_test3_sources",
find = "functions",
where = [
name.matches("test3_"),
Expand All @@ -32,6 +35,7 @@ ModelQuery(
)

ModelQuery(
name = "get_test4_sources",
find = "functions",
where = [
name.matches("test4_"),
Expand All @@ -43,6 +47,7 @@ ModelQuery(
)

ModelQuery(
name = "get_test5_sources",
find = "functions",
where = [
name.matches("test5_"),
Expand Down
Expand Up @@ -2,12 +2,14 @@ def _test_sink(arg: TaintSink[Test, Via[special_sink]]): ...
def _test_source() -> TaintSource[Test, Via[special_source]]: ...

ModelQuery(
name = "get_test1_sinks",
find="functions",
where=[name.matches("test1_f")],
model=Parameters(TaintSink[Test, ViaTypeOf])
)

ModelQuery(
name = "get_test2_sinks",
find="methods",
where=[parent.matches("Test2_C")],
model=Parameters(TaintSink[Test, ViaTypeOf], where=[Not(name.matches("self"))])
Expand Down
Expand Up @@ -2,6 +2,7 @@ def _test_sink(arg: TaintSink[Test]): ...
def _test_source() -> TaintSource[Test]: ...

ModelQuery(
name = "get_test1_source",
find = "functions",
where = [
name.matches("test1_")
Expand All @@ -12,6 +13,7 @@ ModelQuery(
)

ModelQuery(
name = "get_test2_source",
find = "functions",
where = [
name.matches("test2_")
Expand All @@ -28,6 +30,7 @@ ModelQuery(


ModelQuery(
name = "get_test3_source",
find = "functions",
where = [
name.matches("test3_")
Expand All @@ -44,6 +47,7 @@ ModelQuery(
)

ModelQuery(
name = "get_test4_source",
find = "functions",
where = [
name.matches("test4_")
Expand All @@ -63,6 +67,7 @@ ModelQuery(


ModelQuery(
name = "get_test5_sink",
find = "methods",
where = [
parent.matches("Test5"),
Expand All @@ -85,6 +90,7 @@ ModelQuery(


ModelQuery(
name = "get_test6_source",
find = "functions",
where = [
name.matches("test6_")
Expand All @@ -107,6 +113,7 @@ ModelQuery(
)

ModelQuery(
name = "get_test7_source",
find = "methods",
where = [
parent.matches("Test7"),
Expand All @@ -123,6 +130,7 @@ ModelQuery(
)

ModelQuery(
name = "get_test8_source",
find = "functions",
where = [
name.matches("test8_")
Expand All @@ -133,6 +141,7 @@ ModelQuery(
)

ModelQuery(
name = "get_test9_source",
find = "functions",
where = [
name.matches("test9_")
Expand All @@ -142,6 +151,7 @@ ModelQuery(
]
)
ModelQuery(
name = "get_test9_SourceA",
find = "functions",
where = [
name.matches("test9_")
Expand All @@ -156,6 +166,7 @@ ModelQuery(
]
)
ModelQuery(
name = "get_test9_SourceB",
find = "functions",
where = [
name.matches("test9_")
Expand All @@ -171,6 +182,7 @@ ModelQuery(
)

ModelQuery(
name = "get_test10_source",
find = "functions",
where = [
name.matches("test10_")
Expand All @@ -180,6 +192,7 @@ ModelQuery(
]
)
ModelQuery(
name = "get_test10_SourceA",
find = "functions",
where = [
name.matches("test10_")
Expand All @@ -194,6 +207,7 @@ ModelQuery(
]
)
ModelQuery(
name = "get_test10_SourceB",
find = "functions",
where = [
name.matches("test10_")
Expand All @@ -208,6 +222,7 @@ ModelQuery(
]
)
ModelQuery(
name = "get_test10_SourceC",
find = "functions",
where = [
name.matches("test10_")
Expand All @@ -222,6 +237,7 @@ ModelQuery(
]
)
ModelQuery(
name = "get_test10_SourceD",
find = "functions",
where = [
name.matches("test10_")
Expand Down
Expand Up @@ -2,6 +2,7 @@ def _test_sink(arg: TaintSink[Test, Via[special_sink]]): ...
def _test_source() -> TaintSource[Test, Via[special_source]]: ...

ModelQuery(
name = "get_Test1_sources",
find = "attributes",
where = [
parent.matches("Test1_"),
Expand All @@ -13,6 +14,7 @@ ModelQuery(
)

ModelQuery(
name = "get_Test2_sources",
find = "methods",
where = [
parent.matches("Test2_"),
Expand Down

0 comments on commit ead350b

Please sign in to comment.