Skip to content

ATM: Test for endpoints scored at inference time - #11532

Merged
tiferet merged 6 commits into
mainfrom
tiferet/endpoint-filter-test
Dec 2, 2022
Merged

ATM: Test for endpoints scored at inference time#11532
tiferet merged 6 commits into
mainfrom
tiferet/endpoint-filter-test

Conversation

@tiferet

@tiferettiferet commented Dec 1, 2022

Copy link
Copy Markdown
Contributor

Adds a test to detect changes in the endpoints that get scored at inference time.

Note that the queries' .ql files (e.g. src/NosqlInjectionATM.ql) can't be called directly here, because they use the model and compute a score.

Closeshttps://github.com/github/ml-ql-adaptive-threat-modeling/issues/2135

@tiferet
tiferet requested review from a team and kaeluka and removed request for a teamDecember 1, 2022 22:26
@tiferettiferet mentioned this pull request Dec 1, 2022
jhelie
jhelie previously approved these changes Dec 2, 2022

@jheliejhelie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tiferet, LGTM. I've added XssThroughDom but this didn't require updating the .expected files : I guess our some small examples do not contain instances of source for Xss and not for XssThroughDom (or vice versa).

@jhelie

jhelie commented Dec 2, 2022

Copy link
Copy Markdown
Contributor

ah I see we were both working on the PR: I can push my change or you can update the ExtractEndpointDataInference.ql file yourself after rebasing on main.

(I'm de-approving in case you are still working on this and I'll refrain pushing my branch unless you tell me to do so)

@jhelie
jhelie dismissed their stale reviewDecember 2, 2022 14:30

changes since review

@tiferet

Copy link
Copy Markdown
ContributorAuthor

Thanks @tiferet, LGTM. I've added XssThroughDom but this didn't require updating the .expected files : I guess our some small examples do not contain instances of source for Xss and not for XssThroughDom (or vice versa).

I don't see any commits from you, but don't worry about it -- I'll make the needed 1-line change and push it 😄

@tiferet
tiferetforce-pushed the tiferet/endpoint-filter-test branch from 4cf32b8 to f1f356fCompareDecember 2, 2022 14:54
@tiferet

Copy link
Copy Markdown
ContributorAuthor

@kaeluka / @henrymercer Does it make sense that there are no XssThroughDom sink candidates with flow from a source in endpoint_large_scale? Was that set created specifically for our existing four queries? If so, do we need to add to it each time we boost a new query?

Adds a test to detect changes in the endpoints that get scored at inference time.
Not strictly needed, but better to keep things private when possible
Oops, now I see why that wasn't private
@tiferet
tiferetforce-pushed the tiferet/endpoint-filter-test branch from f1f356f to d17383dCompareDecember 2, 2022 14:59

@kaelukakaeluka left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I think we don't need to rely on the heavier PathNode class here. Node suffices.

Also suggested a name change to explicitly mention that the predicate only returns endpoints WITH FLOW.

private import experimental.adaptivethreatmodeling.XssThroughDomATM as XssThroughDomAtm

query predicate isSinkCandidateForQuery(
AtmConfig::AtmConfig queryConfig, JS::DataFlow::PathNode sink

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
AtmConfig::AtmConfigqueryConfig, JS::DataFlow::PathNode sink
AtmConfig::AtmConfigqueryConfig, JS::DataFlow::Node sink

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to keep the test as similar as possible to the actual extraction queries. The extraction queries use DataFlow::PathNode (e.g. javascript/ql/experimental/adaptivethreatmodeling/src/SqlInjectionATM.ql). I don't know if there's a reason they do this or not, but if we want to change those to DataFlow::Node (in which case we can change these as well), we should do so in a separate PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extraction queries use the PathNodes for a specific reason - namely, that the UI should be able to list a specific path from source to sink. This is not needed in this test.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment here

@kaeluka

Copy link
Copy Markdown

Does it make sense that there are no XssThroughDom sink candidates with flow from a source in endpoint_large_scale?

No, IMO

Was that set created specifically for our existing four queries?

No, IMO (but I wasn't there)

If so, do we need to add to it each time we boost a new query?

I think so, yes.

@jhelie

Copy link
Copy Markdown
Contributor

Please update the issue template if we need to consider updating endpoint_large_scale when adding a new query.

@owen-mcowen-mc changed the title Test for endpoints scored at inference timeATM: Test for endpoints scored at inference timeDec 2, 2022
Co-authored-by: Stephan Brandauer <kaeluka@github.com>
@tiferet
tiferet requested a review from kaelukaDecember 2, 2022 17:01
@tiferet

Copy link
Copy Markdown
ContributorAuthor

Please update the issue template if we need to consider updating endpoint_large_scale when adding a new query.

@jhelie I added a line about it here.

@henrymercer

henrymercer commented Dec 2, 2022

Copy link
Copy Markdown
Contributor

@kaeluka / @henrymercer Does it make sense that there are no XssThroughDom sink candidates with flow from a source in endpoint_large_scale? Was that set created specifically for our existing four queries? If so, do we need to add to it each time we boost a new query?

Stephan is correct, and I'll add some more context. See https://github.com/github/codeql/tree/main/javascript/ql/experimental/adaptivethreatmodeling/test/endpoint_large_scale/autogenerated for a description of how endpoint_large_scale is generated. Ideally, the files copied from javascript/ql/test/query-tests/Security/CWE-079 would contain some sink candidates with flow for XSS through DOM, but it looks like the model isn't finding anything new there.

The test set was not created specifically for the existing four queries, but in general we will need to check it whenever we boost a new query to ensure it covers the new query.

@tiferet

Copy link
Copy Markdown
ContributorAuthor

@kaeluka / @henrymercer Does it make sense that there are no XssThroughDom sink candidates with flow from a source in endpoint_large_scale? Was that set created specifically for our existing four queries? If so, do we need to add to it each time we boost a new query?

Stephan is correct, and I'll add some more context. See https://github.com/github/codeql/tree/main/javascript/ql/experimental/adaptivethreatmodeling/test/endpoint_large_scale/autogenerated for a description of how endpoint_large_scale is generated. Ideally, the files copied from javascript/ql/test/query-tests/Security/CWE-079 would contain some sink candidates with flow for XSS through DOM, but it looks like the model isn't finding anything new there.

The test set was not created specifically for the existing four queries, but in general we will need to check it whenever we boost a new query to ensure it covers the new query.

Thanks! @jhelie I linked this answer in the issue template as well, for when you get back to the XssThroughDom work.

@kaelukakaeluka left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR LGTM, although I'm a bit unclear whether the discussion between @tiferet and Jean has been resolved already.

  • I'm approving this, assuming that all things related to the conversation will be resolved in a different PR. This is how I understood the conversation.
  • The discussion about PathNodes is not worth losing time over (but it somewhat has bumped the urgency with which I want to look into that class's implementation ^^)

Also: thanks, @henrymercer for weighing in! I never had to look "inside" those tests before, so I appreciate the background info. I actually thought they were hand-crafted for the individual queries.

@tiferet

Copy link
Copy Markdown
ContributorAuthor

The PR LGTM, although I'm a bit unclear whether the discussion between @tiferet and Jean has been resolved already.

That was actually a conversation about the addition of XssThroughDom, that ended up here just because this PR revealed that our test set lacks XssThroughDom examples 😄. That's part of the XssThroughDom work, though, unrelated to this PR.

@tiferet
tiferet merged commit 79d8444 into mainDec 2, 2022
@tiferet
tiferet deleted the tiferet/endpoint-filter-test branch December 2, 2022 21:13
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@tiferet@jhelie@kaeluka@henrymercer