Skip to content

Commit 97adf7a

Browse files
arthaudfacebook-github-bot
authored andcommitted
Infer tito to self by default
Summary: A while ago, we implemented inference of taint propagation from arguments to the `self` argument. This was gated by the `--infer-self-tito` flag for a while. Since we use this in production for all our runs, let's just enable it by default. Reviewed By: alexkassil Differential Revision: D77671053 fbshipit-source-id: 7f76f05854b534a718767ca880a6d9ddd9501bb5
1 parent 95c0e9b commit 97adf7a

13 files changed

Lines changed: 136 additions & 27 deletions

File tree

client/command_arguments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class AnalyzeArguments:
299299
enable_memory_profiling: bool = False
300300
enable_profiling: bool = False
301301
find_missing_flows: Optional[MissingFlowsKind] = None
302-
infer_self_tito: bool = False
302+
infer_self_tito: bool = True
303303
infer_argument_tito: bool = False
304304
log_identifier: Optional[str] = None
305305
maximum_model_source_tree_width: Optional[int] = None

client/commands/analyze.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Arguments:
4343
dump_call_graph: Optional[str] = None
4444
dump_model_query_results: Optional[str] = None
4545
find_missing_flows: Optional[str] = None
46-
infer_self_tito: bool = False
46+
infer_self_tito: bool = True
4747
infer_argument_tito: bool = False
4848
maximum_model_source_tree_width: Optional[int] = None
4949
maximum_model_sink_tree_width: Optional[int] = None

client/commands/tests/analyze_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def assert_serialized(
9191
("dump_call_graph", "/call-graph"),
9292
("dump_model_query_results", "/model-query"),
9393
("find_missing_flows", "obscure"),
94-
("infer_self_tito", False),
94+
("infer_self_tito", True),
9595
("infer_argument_tito", False),
9696
("maximum_model_source_tree_width", 10),
9797
("maximum_model_sink_tree_width", 11),
@@ -177,7 +177,7 @@ def test_create_analyze_arguments(self) -> None:
177177
dump_call_graph="/call-graph",
178178
dump_model_query_results="/model-query",
179179
find_missing_flows=command_arguments.MissingFlowsKind.TYPE,
180-
infer_self_tito=True,
180+
infer_self_tito=False,
181181
infer_argument_tito=True,
182182
maximum_model_source_tree_width=10,
183183
maximum_model_sink_tree_width=11,
@@ -247,7 +247,7 @@ def test_create_analyze_arguments(self) -> None:
247247
dump_call_graph="/call-graph",
248248
dump_model_query_results="/model-query",
249249
find_missing_flows="type",
250-
infer_self_tito=True,
250+
infer_self_tito=False,
251251
infer_argument_tito=True,
252252
maximum_model_source_tree_width=10,
253253
maximum_model_sink_tree_width=11,

client/pyre.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,13 @@ def pyre(
493493
help="Build the cache and exit without computing results..",
494494
)
495495
@click.option(
496-
"--infer-self-tito",
496+
"--infer-self-tito/--no-infer-self-tito",
497497
is_flag=True,
498-
default=False,
498+
default=True,
499499
help="Infer taint propagations (tito) from arguments to `self` for all methods.",
500500
)
501501
@click.option(
502-
"--infer-argument-tito",
502+
"--infer-argument-tito/--no-infer-argument-tito",
503503
is_flag=True,
504504
default=False,
505505
help="Infer taint propagations (tito) from arguments to other arguments.",

documentation/website/docs/pysa_advanced.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ def MyClass.updates_foo(self, x: TaintInTaintOut[Updates[self], UpdatePath[_.foo
212212

213213
## Taint propagation from arguments to self
214214

215-
By default, Pysa only infers taint propagation from arguments to self for
216-
constructors, property setters and the special `__setitem__` method.
215+
By default, Pysa infers taint propagation from arguments to self for all methods,
216+
including constructors, property setters and the special `__setitem__` method.
217217

218218
For instance:
219219
```python
@@ -226,22 +226,26 @@ class Foo:
226226

227227
def issue():
228228
foo = Foo(source())
229-
sink(foo) # Issue found.
229+
sink(foo) # Issue (1) found.
230230

231231
foo = Foo("")
232232
foo.set_x(source())
233-
sink(foo) # Issue NOT found.
233+
sink(foo) # Issue (2) found.
234234
```
235235

236-
To enable the inference of propagations from arguments to self for all methods,
237-
one can provide the command line argument `--infer-self-tito` or use the taint
238-
annotation `@InferSelfTito` in a `.pysa` file:
236+
To disable the inference of propagations from arguments to self for all methods - except
237+
constructors, property setters and `__setitem__` - one can provide the command
238+
line argument `--no-infer-self-tito`. This should reduce the analysis time, as well
239+
as reduce false positives. The counterpart is that it can also lead to false negatives.
240+
For instance, Pysa wouldn't find issue (2) anymore.
241+
242+
When using `--no-infer-self-tito`, we can use the taint annotation `@InferSelfTito`
243+
in a `.pysa` file to enable inference for specific methods:
239244
```python
240245
@InferSelfTito
241246
def my_module.Foo.set_x(): ...
242247
```
243-
Pysa would now find the second issue properly. Note that `--infer-self-tito` can
244-
significantly increase the analysis time as well as the amount of false positives.
248+
Pysa would now find the second issue properly.
245249

246250
## Taint propagation between arguments
247251

source/command/analyzeCommand.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module AnalyzeConfiguration = struct
9292
let maximum_parameterized_targets_at_call_site =
9393
optional_int_member "maximum_parameterized_targets_at_call_site" json
9494
in
95-
let infer_self_tito = bool_member "infer_self_tito" ~default:false json in
95+
let infer_self_tito = bool_member "infer_self_tito" ~default:true json in
9696
let infer_argument_tito = bool_member "infer_argument_tito" ~default:false json in
9797
let maximum_model_source_tree_width =
9898
optional_int_member "maximum_model_source_tree_width" json

source/command/test/analyzeTest.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let test_json_parsing context =
3030
dump_call_graph = None;
3131
dump_model_query_results = None;
3232
find_missing_flows = None;
33-
infer_self_tito = false;
33+
infer_self_tito = true;
3434
infer_argument_tito = false;
3535
maximum_model_source_tree_width = None;
3636
maximum_model_sink_tree_width = None;
@@ -92,8 +92,8 @@ let test_json_parsing context =
9292
find_missing_flows = Some Configuration.MissingFlowKind.Obscure;
9393
};
9494
assert_parsed
95-
(`Assoc (("infer_self_tito", `Bool true) :: BaseConfigurationTest.dummy_base_json))
96-
~expected:{ dummy_analyze_configuration with infer_self_tito = true };
95+
(`Assoc (("infer_self_tito", `Bool false) :: BaseConfigurationTest.dummy_base_json))
96+
~expected:{ dummy_analyze_configuration with infer_self_tito = false };
9797
assert_parsed
9898
(`Assoc (("infer_argument_tito", `Bool true) :: BaseConfigurationTest.dummy_base_json))
9999
~expected:{ dummy_analyze_configuration with infer_argument_tito = true };

source/configuration.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ module StaticAnalysis = struct
834834
?dump_model_query_results
835835
?(use_cache = false)
836836
?(build_cache_only = false)
837-
?(infer_self_tito = false)
837+
?(infer_self_tito = true)
838838
?(infer_argument_tito = false)
839839
?maximum_model_source_tree_width
840840
?maximum_model_sink_tree_width

source/interprocedural_analyses/taint/taintConfiguration.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ module Heap = struct
519519
string_combine_partial_sinks = StringOperationPartialSinks.empty;
520520
find_missing_flows = None;
521521
dump_model_query_results_path = None;
522-
infer_self_tito = false;
522+
infer_self_tito = true;
523523
infer_argument_tito = false;
524524
analysis_model_constraints = ModelConstraints.default;
525525
source_sink_filter = SourceSinkFilter.all;
@@ -697,7 +697,7 @@ module Heap = struct
697697
string_combine_partial_sinks = StringOperationPartialSinks.empty;
698698
find_missing_flows = None;
699699
dump_model_query_results_path = None;
700-
infer_self_tito = false;
700+
infer_self_tito = true;
701701
infer_argument_tito = false;
702702
analysis_model_constraints = ModelConstraints.default;
703703
source_sink_filter =
@@ -1635,7 +1635,7 @@ let from_json_list source_json_list =
16351635
string_combine_partial_sinks;
16361636
find_missing_flows = None;
16371637
dump_model_query_results_path = None;
1638-
infer_self_tito = false;
1638+
infer_self_tito = true;
16391639
infer_argument_tito = false;
16401640
analysis_model_constraints =
16411641
ModelConstraints.override_with
@@ -1979,7 +1979,7 @@ let with_command_line_options
19791979
rules;
19801980
implicit_sources;
19811981
implicit_sinks;
1982-
infer_self_tito = configuration.infer_self_tito || infer_self_tito;
1982+
infer_self_tito = configuration.infer_self_tito && infer_self_tito;
19831983
infer_argument_tito = configuration.infer_argument_tito || infer_argument_tito;
19841984
source_sink_filter;
19851985
}

source/interprocedural_analyses/taint/test/integration/closure_models.py.models

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,20 @@
10581058
}
10591059
],
10601060
"tito": [
1061+
{
1062+
"port": "formal(feature, position=1)",
1063+
"taint": [
1064+
{
1065+
"kinds": [
1066+
{
1067+
"return_paths": { "[feature]": 3 },
1068+
"kind": "ParameterUpdate[formal(self, position=0)]"
1069+
}
1070+
],
1071+
"tito": {}
1072+
}
1073+
]
1074+
},
10611075
{
10621076
"port": "formal(self, position=0)[inner]",
10631077
"taint": [

0 commit comments

Comments
 (0)