X Tutup
The Wayback Machine - https://web.archive.org/web/20240212155941/https://github.com/github/codeql/pull/15563
Skip to content
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

C#: Models as Data Documentation #15563

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

egregius313
Copy link
Contributor

Introduces Models-as-Data documentation for C#

  • Changes Java to use the language-agnostic beta notice
  • Introduces C#-specific models-as-data doc

Later follow-up will be to add the threat modeling documentation.

@egregius313 egregius313 requested a review from a team February 9, 2024 02:29
@egregius313 egregius313 force-pushed the egregius313/csharp/docs/mad-docs branch from 9821ffb to 4d31893 Compare February 9, 2024 02:41
@egregius313 egregius313 force-pushed the egregius313/csharp/docs/mad-docs branch from 4d31893 to 4e75726 Compare February 9, 2024 03:43
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

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

Thanks a lot for writing this up. Some comments.

About data extensions
---------------------

You can customize analysis by defining models (summaries, sinks, and sources) of your code's C#/.NET dependencies in data extension files. Each model defines the behavior of one or more elements of your library or framework, such as methods, properties, and callables. When you run dataflow analysis, these models expand the potential sources and sinks tracked by dataflow analysis and improve the precision of results.
Copy link
Contributor

Choose a reason for hiding this comment

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

customize analysis -> customize analyses?

Copy link
Contributor

Choose a reason for hiding this comment

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

And dataflow analysis -> dataflow analyses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure which is better, but that wording is taken from the Java customizing-library-models docs.

- ``sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, provenance)``. This is used to model sources of potentially tainted data.
- ``sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, provenance)``. This is used to model sinks where tainted data maybe used in a way that makes the code vulnerable.
- ``summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, provenance)``. This is used to model flow through elements.
- ``neutralModel(namespace, type, name, signature, kind, provenance)``. This is similar to a summary model but used to model the flow of values that have only a minor impact on the dataflow analysis.
Copy link
Contributor

Choose a reason for hiding this comment

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

have only a minor impact -> have no impact?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this should be changed to no impact I am totally fine doing so. This is taken from how Java's MaD docs describes it, so if it needs to be changed it might make sense to change it in both.

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to change this statement; Also for java.
After #15246 was merged, manual neutral summary models have impact for both C# and Java as they "override" generated summaries (that is, if a manual neutral exist for a callable we ignore any generated summary for it).
That is, for
C#: Manual neutral models can be used over to override generated summary models, such that the generated summary models will be ignored; other than that they have no effect.
Java: Manul neutrals models overrides generated summary models, such that the generated summary models will be ignored; other than that they have a sligt impact on the dataflow dispatch logic, which is out of scope for this documentation.

}
}
We need to add a tuple to the ``sinkModel``\(namespace, type, subtypes, name, signature, ext, input, kind, provenance) extensible predicate by updating a data extension file.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with .rst syntax, but the above looks wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the purpose of that is so that only the word sinkModel is rendered as code and be highlighted. But if we think that it's fine to highlight the entirety of sinkModel(namespace, ..., I can change it over.

cf The Java MaD docs:
Screenshot 2024-02-09 at 2 45 54 PM

Since we are adding flow through a method, we need to add tuples to the ``summaryModel`` extensible predicate.
Each tuple defines flow from one argument to the return value.
The first row defines flow from the first argument (``s1`` in the example) to the return value (``t`` in the example) and the second row defines flow from the second argument (``s2`` in the example) to the return value (``t`` in the example).
Copy link
Contributor

Choose a reason for hiding this comment

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

The wording probably needs to be changed, as the two rows were collapsed into one.
You could consider to write the example using two rows and then state that the rows can be collapsed into a single row using the more compact syntax Argument[0,1].

Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

@egregius313 : Really good examples!
It would be great, if we could also make something similar to extensible-predicates.rst which is currently java specific (and for some reason not linked from the java documentation).

Co-authored-by: Michael Nebel <michaelnebel@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants
X Tutup