Skip to content

Java: add some neutral models discovered with heuristics#12249

Merged
jcogs33 merged 6 commits intogithub:mainfrom
jcogs33:jcogs33/add-heuristic-neutral-models
Jun 1, 2023
Merged

Java: add some neutral models discovered with heuristics#12249
jcogs33 merged 6 commits intogithub:mainfrom
jcogs33:jcogs33/add-heuristic-neutral-models

Conversation

@jcogs33
Copy link
Copy Markdown
Contributor

@jcogs33 jcogs33 commented Feb 17, 2023

Description

This PR adds some neutral models discovered with heuristics.
The apache model was discovered with a ssrf heuristic. The rest of the models were discovered with a path-injection heuristic.

(cc @atorralba @tiferet)

Consideration

  • I put a provenance of "manual" on these since they were manually reviewed after initially being generated by heuristic queries. Let me know if I should use a different provenance for heuristic-generated models (related to this discussion).
  • I didn't add a change-note because I don't think neutral models are really a "user-visible" change. Let me know if I'm wrong about that and if I should add a change note for these models.
  • I haven't added test cases for neutral models before, but let me know if I should add some "tests" that just have a // no flow comment or something similar.

@github-actions github-actions bot added the Java label Feb 17, 2023
@jcogs33 jcogs33 added the no-change-note-required This PR does not need a change note label Feb 17, 2023
@jcogs33 jcogs33 marked this pull request as ready for review February 17, 2023 20:44
@jcogs33 jcogs33 requested a review from a team as a code owner February 17, 2023 20:44
Copy link
Copy Markdown
Contributor

@atorralba atorralba left a comment

Choose a reason for hiding this comment

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

Looks good! I think there was a small formatting mistake I added some suggestions for.

I put a provenance of "manual" on these since they were manually reviewed after initially being generated by heuristic queries. Let me know if I should use a different provenance for heuristic-generated models (related to #12228 (comment)).

I think manual is the right provenance according to the discussion.

I didn't add a change-note because I don't think neutral models are really a "user-visible" change. Let me know if I'm wrong about that and if I should add a change note for these models.

This doesn't need a change note indeed.

I haven't added test cases for neutral models before, but let me know if I should add some "tests" that just have a // no flow comment or something similar.

For neutral summaries, it probably doesn't make sense to add tests. But for neutral sinks, which are manually added and from my POV have a stronger and more intentional sense of "this is safe/non-exploitable", I think it could make sense to have tests — so that we get notified if that assumption is no longer valid and someone adds such a sink in the future.

@jcogs33
Copy link
Copy Markdown
Contributor Author

jcogs33 commented Feb 28, 2023

For neutral summaries, it probably doesn't make sense to add tests. But for neutral sinks, which are manually added and from my POV have a stronger and more intentional sense of "this is safe/non-exploitable", I think it could make sense to have tests — so that we get notified if that assumption is no loner valid and someone adds such a sink in the future.

Sounds good, I'll add tests for these, but I'll wait until the discussion from elsewhere about exactly how to represent neutral sinks is finalized.
Converting this PR back to a draft until then.

@jcogs33 jcogs33 marked this pull request as draft February 28, 2023 00:05
@jcogs33 jcogs33 force-pushed the jcogs33/add-heuristic-neutral-models branch from 0b99aa0 to 500ed0b Compare May 12, 2023 20:37
@jcogs33 jcogs33 force-pushed the jcogs33/add-heuristic-neutral-models branch from ba99a74 to 24fc4ba Compare May 26, 2023 22:55
@jcogs33 jcogs33 marked this pull request as ready for review May 26, 2023 23:15
@jcogs33
Copy link
Copy Markdown
Contributor Author

jcogs33 commented May 26, 2023

Re-opening this PR for review now that #12931 is completed.
As a reminder, this PR is just adding a few neutral sink models that were discovered when reviewing heuristic results, it is not intended to be complete.

Changes since this was last reviewed:

  • added "sink" kinds
  • updated the provenance to "hq-manual"
  • added tests as was recommended above

Regarding the tests, let me know if you think there is a better way to test these. The test case I've added just uses sinkNode to check if a MaD sink exists and will fail if a MaD sink is added for one of the neutrals, but it currently won't fail if a sink is added in regular CodeQL. Let me know if there is a good way to include a check for sinks written in regular CodeQL.
Also, would it make sense to have a more general check/test instead that makes sure that sinks and neutral sinks never overlap? Maybe something like getInvalidNeutralModel added to invalidModelRow?

@jcogs33 jcogs33 requested a review from atorralba May 26, 2023 23:16
@atorralba
Copy link
Copy Markdown
Contributor

Models themselves LGTM.

Let me know if there is a good way to include a check for sinks written in regular CodeQL.

I guess that would only work for queries with extensible sinks (i.e. abstract classes), and you'd need to explicitly use them in tests, which doesn't seem ideal. I think we're fine testing only models-as-data sinks for the moment.

On a different note, you're currently testing that certain callables don't contain sinks, but not that we actually have neutral models for them. Do you think it makes sense to also test that with something like the following?

pragma[nomagic]
predicate isNeutral() { this = any(FlowSummaryImpl::Public::NeutralCallable nsc).asCallable() }

Let me know if you think it's overkill.

@jcogs33
Copy link
Copy Markdown
Contributor Author

jcogs33 commented May 31, 2023

I guess that would only work for queries with extensible sinks (i.e. abstract classes), and you'd need to explicitly use them in tests, which doesn't seem ideal. I think we're fine testing only models-as-data sinks for the moment.

👍

On a different note, you're currently testing that certain callables don't contain sinks, but not that we actually have neutral models for them. Do you think it makes sense to also test that with something like the following?

pragma[nomagic]
predicate isNeutral() { this = any(FlowSummaryImpl::Public::NeutralCallable nsc).asCallable() }

Let me know if you think it's overkill.

It seems somewhat overkill to me, but I don't have a strong opinion about it 🙂, so I added something to test for this in 82f208c. Note that FlowSummaryImpl::Public::NeutralCallable is specific to neutral summaries, so I wasn't able to use it to test for neutral sinks. What I did instead feels a bit hacky to me, so let me know if you think it isn't worth adding this or if you think there's a better way to write this test case. (I suppose I could create a NeutralSinkCallable class similar to FlowSummaryImpl::Public::NeutralCallable, but I was trying to keep it simple by just using existing classes/predicates).

Copy link
Copy Markdown
Contributor

@atorralba atorralba left a comment

Choose a reason for hiding this comment

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

(I suppose I could create a NeutralSinkCallable class similar to FlowSummaryImpl::Public::NeutralCallable, but I was trying to keep it simple by just using existing classes/predicates).

I think we should have that class, but that's out of the scope of this PR.

I like that we can test that we're creating the neutrals we're intending to, AND that none of those collides with a sink. Thanks for indulging me!

@jcogs33 jcogs33 merged commit 10bab71 into github:main Jun 1, 2023
@jcogs33 jcogs33 deleted the jcogs33/add-heuristic-neutral-models branch June 1, 2023 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants