Skip to content

Commit

Permalink
Deprecate parsing the old syntax for multi-source rules and models
Browse files Browse the repository at this point in the history
Reviewed By: alexkassil

Differential Revision: D58744220

fbshipit-source-id: f39425582e785d25bf3236002f0d5573917527e3
  • Loading branch information
Tianhan Lu authored and facebook-github-bot committed Jun 20, 2024
1 parent 1f08d39 commit 4afc728
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 277 deletions.
21 changes: 0 additions & 21 deletions source/interprocedural_analyses/taint/modelParser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -600,27 +600,6 @@ let rec parse_annotations
in
let get_partial_sink_kind expression =
match Node.value expression with
| Expression.Subscript
{
base = { Node.value = Expression.Name (Name.Identifier kind); _ };
index = Index { Node.value = Name (Name.Identifier label); _ };
} -> (
(* TODO(T192180304): Delete once models are migrated to new syntax. *)
let partial_sink = TaintConfiguration.RegisteredPartialSinks.from_kind_label ~kind ~label in
match
TaintConfiguration.RegisteredPartialSinks.is_registered
~partial_sink
taint_configuration.registered_partial_sinks
with
| Yes -> Ok (Sinks.PartialSink partial_sink)
| No registered_sinks ->
Error
(annotation_error
(Format.sprintf
"Unrecognized partial sink `%s` (choices: `%s`)"
partial_sink
(registered_sinks |> Sinks.PartialSink.Set.elements |> String.concat ~sep:", ")))
)
| Expression.Name (Name.Identifier partial_sink) -> (
match
TaintConfiguration.RegisteredPartialSinks.is_registered
Expand Down
50 changes: 7 additions & 43 deletions source/interprocedural_analyses/taint/taintConfiguration.ml
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,6 @@ module RegisteredPartialSinks = struct
|> PartialSink.Map.of_alist_exn


(* TODO: Remove once the syntax no longer supports specifying labels. *)
let from_kind_label ~kind ~label = Format.asprintf "%s[%s]" kind label

let add partial_sink_1 partial_sink_2 map =
let update_matches partial_sink_1 partial_sink_2 =
PartialSink.Map.update partial_sink_1 (function
Expand Down Expand Up @@ -791,6 +788,7 @@ module Error = struct
| UnsupportedSink of string
| UnsupportedTransform of string
| UnexpectedCombinedSourceRule of JsonAst.Json.t
| UnexpectedStringCombineRule of JsonAst.Json.t
| InvalidMultiSink of {
sink: string;
registered: Sinks.PartialSink.Set.t;
Expand Down Expand Up @@ -851,7 +849,8 @@ module Error = struct
| UnsupportedSink sink -> Format.fprintf formatter "Unsupported taint sink `%s`" sink
| UnsupportedTransform transform ->
Format.fprintf formatter "Unsupported taint transform `%s`" transform
| UnexpectedCombinedSourceRule json ->
| UnexpectedCombinedSourceRule json
| UnexpectedStringCombineRule json ->
let expected_json_form =
`Assoc
[
Expand All @@ -865,7 +864,7 @@ module Error = struct
in
Format.fprintf
formatter
{|Combined source rules must have a section of the form %s, got %a|}
{|Combined source / String combined rules must have a section of the form %s, got %a|}
(Yojson.Safe.to_string expected_json_form)
JsonAst.Json.pp
json
Expand Down Expand Up @@ -927,6 +926,7 @@ module Error = struct
| UnsupportedSource _ -> 8
| UnsupportedSink _ -> 9
| UnexpectedCombinedSourceRule _ -> 10
| UnexpectedStringCombineRule _ -> 11
| InvalidMultiSink _ -> 13
| RuleCodeDuplicate _ -> 14
| OptionDuplicate _ -> 15
Expand Down Expand Up @@ -1304,28 +1304,7 @@ let from_json_list source_json_list =
parse_partial_sink ~path ~section:"partial_sink" second_rule
>>= fun second_sink ->
Result.Ok { first_sources; first_sink; second_sources; second_sink }
| _ -> (
(* Parse old syntax. Delete once the old rules are migrated to new syntax. *)
let sources = JsonAst.Json.Util.member_exn "sources" json in
let keys = JsonAst.Json.Util.keys sources in
match keys with
| [first_tag; second_tag] ->
parse_sources ~allowed_sources ~path ~section:first_tag sources
>>= fun first_sources ->
parse_sources ~allowed_sources ~path ~section:second_tag sources
>>= fun second_sources ->
parse_partial_sink ~path ~section:"partial_sink" json
>>= fun partial_sink ->
Result.Ok
{
first_sources;
first_sink =
RegisteredPartialSinks.from_kind_label ~kind:partial_sink ~label:first_tag;
second_sources;
second_sink =
RegisteredPartialSinks.from_kind_label ~kind:partial_sink ~label:second_tag;
}
| _ -> Result.Error [Error.create ~path ~kind:(Error.UnexpectedCombinedSourceRule json)])
| _ -> Result.Error [Error.create ~path ~kind:(Error.UnexpectedCombinedSourceRule json)]


let parse_string_combine_rule ~allowed_sources ~path json =
Expand All @@ -1340,22 +1319,7 @@ let from_json_list source_json_list =
parse_partial_sink ~path ~section:"partial_sink" second_rule
>>= fun second_sink ->
Result.Ok { first_sources; first_sink; second_sources; second_sink }
| _ ->
(* Parse old syntax. Delete once the old rules are migrated to new syntax. *)
parse_sources ~allowed_sources ~path ~section:"main_sources" json
>>= fun first_sources ->
parse_sources ~allowed_sources ~path ~section:"secondary_sources" json
>>= fun second_sources ->
parse_partial_sink ~path ~section:"partial_sink" json
>>= fun partial_sink ->
Result.Ok
{
first_sources;
first_sink = RegisteredPartialSinks.from_kind_label ~kind:partial_sink ~label:"main";
second_sources;
second_sink =
RegisteredPartialSinks.from_kind_label ~kind:partial_sink ~label:"secondary";
}
| _ -> Result.Error [Error.create ~path ~kind:(Error.UnexpectedStringCombineRule json)]
end
in
let create_combined_source_rules_and_update_partial_sinks
Expand Down
3 changes: 1 addition & 2 deletions source/interprocedural_analyses/taint/taintConfiguration.mli
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ module RegisteredPartialSinks : sig

val empty : t

val from_kind_label : kind:string -> label:string -> Sinks.PartialSink.t

type registration_result =
| Yes
| No of Sinks.PartialSink.Set.t (* The set of registered labels *)
Expand Down Expand Up @@ -173,6 +171,7 @@ module Error : sig
| UnsupportedSink of string
| UnsupportedTransform of string
| UnexpectedCombinedSourceRule of JsonParsing.JsonAst.Json.t
| UnexpectedStringCombineRule of JsonParsing.JsonAst.Json.t
| InvalidMultiSink of {
sink: string;
registered: Sinks.PartialSink.Set.t;
Expand Down
Loading

0 comments on commit 4afc728

Please sign in to comment.