-
Notifications
You must be signed in to change notification settings - Fork 2k
python: enable summaries from model #12581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
RasmusWL
merged 15 commits into
github:main
from
yoff:python/enable-summaries-from-models
Jun 26, 2023
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
18f4b75
python: enable summaries from model
yoff 3cf9e3e
Py/js/ruby: sync files
yoff 6554e80
python: add test for model summaries
yoff 2296410
python: rename summaries
yoff eb3c33d
python: remove erronous `getACall()`
yoff e111a19
python: split tests into taint and value
yoff 5ceac5a
python: add changenote
yoff cb2de69
python: consolidate tests
yoff 0f8ebd1
Update python/ql/test/experimental/dataflow/model-summaries/model_sum…
yoff 2264b11
python: more consistent tests
yoff 86dfc7b
python: format
yoff 26856a8
Apply suggestions from code review
yoff 0121263
Merge branch 'main' into python/enable-summaries-from-models
RasmusWL 6cb0319
Python: Updates from inline test being parameterized
RasmusWL 257f991
Python: Remove one more unnecessary taint test
RasmusWL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
python/ql/test/experimental/dataflow/model-summaries/InlineTaintTest.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| argumentToEnsureNotTaintedNotMarkedAsSpurious | ||
| untaintedArgumentToEnsureTaintedNotMarkedAsMissing | ||
| failures |
3 changes: 3 additions & 0 deletions
3
python/ql/test/experimental/dataflow/model-summaries/InlineTaintTest.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import python | ||
| private import TestSummaries | ||
| import experimental.meta.InlineTaintTest |
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions
25
python/ql/test/experimental/dataflow/model-summaries/TestSummaries.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| private import python | ||
| private import semmle.python.dataflow.new.FlowSummary | ||
| private import semmle.python.frameworks.data.ModelsAsData | ||
| private import semmle.python.ApiGraphs | ||
|
|
||
| private class StepsFromModel extends ModelInput::SummaryModelCsv { | ||
| override predicate row(string row) { | ||
| row = | ||
| [ | ||
| "foo;Member[MS_identity];Argument[0];ReturnValue;value", | ||
| "foo;Member[MS_apply_lambda];Argument[1];Argument[0].Parameter[0];value", | ||
| "foo;Member[MS_apply_lambda];Argument[0].ReturnValue;ReturnValue;value", | ||
| "foo;Member[MS_reversed];Argument[0].ListElement;ReturnValue.ListElement;value", | ||
| "foo;Member[MS_reversed];Argument[0];ReturnValue;taint", | ||
| "foo;Member[MS_list_map];Argument[1].ListElement;Argument[0].Parameter[0];value", | ||
| "foo;Member[MS_list_map];Argument[0].ReturnValue;ReturnValue.ListElement;value", | ||
| "foo;Member[MS_list_map];Argument[1];ReturnValue;taint", | ||
| "foo;Member[MS_append_to_list];Argument[0].ListElement;ReturnValue.ListElement;value", | ||
| "foo;Member[MS_append_to_list];Argument[1];ReturnValue.ListElement;value", | ||
| "foo;Member[MS_append_to_list];Argument[0];ReturnValue;taint", | ||
| "foo;Member[MS_append_to_list];Argument[1];ReturnValue;taint", | ||
| "json;Member[MS_loads];Argument[0];ReturnValue;taint" | ||
| ] | ||
| } | ||
| } |
20 changes: 0 additions & 20 deletions
20
python/ql/test/experimental/dataflow/model-summaries/dataflow/TestSummaries.qll
This file was deleted.
Oops, something went wrong.
69 changes: 0 additions & 69 deletions
69
python/ql/test/experimental/dataflow/model-summaries/dataflow/model_summaries.py
This file was deleted.
Oops, something went wrong.
128 changes: 128 additions & 0 deletions
128
python/ql/test/experimental/dataflow/model-summaries/model_summaries.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
|
|
||
| import sys | ||
| import os | ||
|
|
||
| sys.path.append(os.path.dirname(os.path.dirname((__file__)))) | ||
| from testlib import expects | ||
|
|
||
| # These are defined so that we can evaluate the test code. | ||
| NONSOURCE = "not a source" | ||
| SOURCE = "source" | ||
|
|
||
|
|
||
| def is_source(x): | ||
| return x == "source" or x == b"source" or x == 42 or x == 42.0 or x == 42j | ||
|
|
||
|
|
||
| def SINK(x): | ||
| if is_source(x): | ||
| print("OK") | ||
| else: | ||
| print("Unexpected flow", x) | ||
|
|
||
|
|
||
| def SINK_F(x): | ||
| if is_source(x): | ||
| print("Unexpected flow", x) | ||
| else: | ||
| print("OK") | ||
|
|
||
| ensure_tainted = ensure_not_tainted = print | ||
| TAINTED_STRING = "TAINTED_STRING" | ||
|
|
||
| from foo import MS_identity, MS_apply_lambda, MS_reversed, MS_list_map, MS_append_to_list | ||
|
|
||
| # Simple summary | ||
| via_identity = MS_identity(SOURCE) | ||
| SINK(via_identity) # $ flow="SOURCE, l:-1 -> via_identity" | ||
|
|
||
| tainted = MS_identity(TAINTED_STRING) | ||
| ensure_tainted(tainted) # $ tainted | ||
|
|
||
|
|
||
| # Lambda summary | ||
| via_lambda = MS_apply_lambda(lambda x: [x], SOURCE) | ||
| SINK(via_lambda[0]) # $ flow="SOURCE, l:-1 -> via_lambda[0]" | ||
|
|
||
| tainted_lambda = MS_apply_lambda(lambda x: [x], TAINTED_STRING) | ||
| ensure_tainted(tainted_lambda) # $ tainted | ||
|
|
||
|
|
||
| # A lambda that breaks the flow | ||
| not_via_lambda = MS_apply_lambda(lambda x: 1, SOURCE) | ||
| SINK_F(not_via_lambda) | ||
|
|
||
| untainted_lambda = MS_apply_lambda(lambda x: 1, TAINTED_STRING) | ||
| ensure_not_tainted(untainted_lambda) | ||
|
|
||
| # Collection summaries | ||
| via_reversed = MS_reversed([SOURCE]) | ||
| SINK(via_reversed[0]) # $ flow="SOURCE, l:-1 -> via_reversed[0]" | ||
|
|
||
| tainted_list = MS_reversed([TAINTED_STRING]) | ||
| ensure_tainted(tainted_list[0]) # $ tainted | ||
|
|
||
| # Complex summaries | ||
| def box(x): | ||
| return [x] | ||
|
|
||
| via_map = MS_list_map(box, [SOURCE]) | ||
| SINK(via_map[0][0]) # $ flow="SOURCE, l:-1 -> via_map[0][0]" | ||
|
|
||
| tainted_mapped = MS_list_map(box, [TAINTED_STRING]) | ||
| ensure_tainted(tainted_mapped[0][0]) # $ tainted | ||
|
|
||
| def explicit_identity(x): | ||
| return x | ||
|
|
||
| via_map_explicit = MS_list_map(explicit_identity, [SOURCE]) | ||
| SINK(via_map_explicit[0]) # $ flow="SOURCE, l:-1 -> via_map_explicit[0]" | ||
|
|
||
| tainted_mapped_explicit = MS_list_map(explicit_identity, [TAINTED_STRING]) | ||
| tainted_mapped_explicit_implicit = MS_list_map(explicit_identity, TAINTED_LIST) | ||
| ensure_tainted( | ||
| tainted_mapped_explicit, # $ tainted | ||
| tainted_mapped_explicit[0], # $ tainted | ||
| tainted_mapped_explicit_implicit, # $ tainted | ||
| tainted_mapped_explicit_implicit[0] # $ tainted | ||
| ) | ||
|
|
||
| via_map_summary = MS_list_map(MS_identity, [SOURCE]) | ||
| SINK(via_map_summary[0]) # $ flow="SOURCE, l:-1 -> via_map_summary[0]" | ||
|
|
||
| tainted_mapped_summary = MS_list_map(MS_identity, [TAINTED_STRING]) | ||
| tainted_mapped_summary_implicit = MS_list_map(MS_identity, TAINTED_LIST) | ||
| ensure_tainted( | ||
| tainted_mapped_summary, # $ tainted | ||
| tainted_mapped_summary[0], # $ tainted | ||
| tainted_mapped_summary_implicit, # $ tainted | ||
| tainted_mapped_summary_implicit[0] # $ tainted | ||
| ) | ||
|
|
||
| via_append_el = MS_append_to_list([], SOURCE) | ||
| SINK(via_append_el[0]) # $ flow="SOURCE, l:-1 -> via_append_el[0]" | ||
|
|
||
| tainted_list_el = MS_append_to_list([], TAINTED_STRING) | ||
| ensure_tainted( | ||
| tainted_list_el, # $ tainted | ||
| tainted_list_el[0] # $ tainted | ||
| ) | ||
|
|
||
| via_append = MS_append_to_list([SOURCE], NONSOURCE) | ||
| SINK(via_append[0]) # $ flow="SOURCE, l:-1 -> via_append[0]" | ||
|
|
||
| tainted_list = MS_append_to_list([TAINTED_STRING], NONSOURCE) | ||
| tainted_list_implicit = MS_append_to_list(TAINTED_LIST, NONSOURCE) | ||
| ensure_tainted( | ||
| tainted_list, # $ tainted | ||
| tainted_list[0], # $ tainted | ||
| tainted_list_implicit, # $ tainted | ||
| tainted_list_implicit[0] # $ tainted | ||
| ) | ||
|
|
||
| from json import MS_loads as json_loads | ||
| tainted_resultlist = json_loads(TAINTED_STRING) | ||
| ensure_tainted( | ||
| tainted_resultlist, # $ tainted | ||
| tainted_resultlist[0] # $ tainted | ||
| ) | ||
|
yoff marked this conversation as resolved.
Outdated
|
||
2 changes: 0 additions & 2 deletions
2
python/ql/test/experimental/dataflow/model-summaries/taint/NormalTaintTrackingTest.expected
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
python/ql/test/experimental/dataflow/model-summaries/taint/NormalTaintTrackingTest.ql
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
python/ql/test/experimental/dataflow/model-summaries/taint/TestSummaries.qll
This file was deleted.
Oops, something went wrong.
70 changes: 0 additions & 70 deletions
70
python/ql/test/experimental/dataflow/model-summaries/taint/model_summaries_taint.py
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you have just shown that we have data-flow, and we know all dataflow steps are also taint-flow steps, I think it's fine to only check taint-flow for the cases where there is NOT dataflow.
I think that will make the test-file a bit easier to read as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I tried to make it more consistent now by not checking taint when dataflow is already established and when we do check taint, check both the collection and the expected element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking some more about this, I think these tests should be about whether you can write flow summaries in CSV files that do the right thing.
Having all these extra taint steps are closer to what our current taint-tracking does in the end, but from my point of view, doesn't help us achieve the goal of the tests.
I removed the
TAINTED_LISTparts locally, but thought it was a bit too controversial to just commit directly to your PR -- instead I've put the commits here: yoff#79 (if you agree, we can add these to main later on 👍)