Skip to content

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 2 times, most recently 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think analyses is probably better in both contexts, but I don't think the gain in clarity is enough to justify making edits here and in the Java docs, since "analysis" does also technically make sense (at least I think it does!), and it wouldn't just affect this paragraph.

}
}

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, that looks weird to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

But if we think that it's fine to highlight the entirety of sinkModel(namespace, ..., I can change it over.

I think this would probably would be best, but it would involve numerous edits to both this documentation and the Java documentation. If you have time to do this, it'd be great, but it's not urgent 👍

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).

@egregius313 egregius313 force-pushed the egregius313/csharp/docs/mad-docs branch from d95c5f8 to 18465d8 Compare February 13, 2024 17:08
@egregius313
Copy link
Contributor Author

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).

@michaelnebel The existing extensible-predicates.rst mentions synthetic fields/globals, but does not explain them? Would fleshing out the documentation for them make sense as well?

@michaelnebel
Copy link
Contributor

michaelnebel commented Feb 14, 2024

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).

@michaelnebel The existing extensible-predicates.rst mentions synthetic fields/globals, but does not explain them? Would fleshing out the documentation for them make sense as well?

That is an excellent question!
I think we could do much more extensive documentation, if we want to. If you are up for providing examples for synthetics that would be great, but if I think that examples for covering Field and Property (only the latter is relevant for C#) would be more important.

That is, if you want to do more examples, then the order of "importance" is probably:

  1. Field and Property (the latter only relevant for C#).
  2. ArrayElement, MapKey, MapValue (these are only relevant for Java).
  3. Attributes (the ext field in the MaD format can be used to capture summaries for callables based on their annotation (java) and attribute (C#).
  4. SyntheticField.
  5. SyntheticGlobal: Note that there are no C# examples, but I expect this to work, because the FlowSummaryImpl implementation is now shared - but this is untested for C# (at least from a MaD stand point - there are some synthetic globals but they are declared in QL.

You are more than welcome to add more examples - this would be highly appreciated (I do know this is scope creep, but it would be really valuable, if we had these examples), but not strictly required I think.

@egregius313
Copy link
Contributor Author

You are more than welcome to add more examples - this would be highly appreciated (I do know this is scope creep, but it would be really valuable, if we had these examples), but not strictly required I think.

@michaelnebel I am going to work on extensible-predicate, but in order to avoid scope-creep in this PR, I am going to do those updates in a separate PR. It will make it easier to make sure this is reviewed and ready to merge.

@egregius313 egregius313 added the ready-for-doc-review This PR requires and is ready for review from the GitHub docs team. label Feb 15, 2024
@subatoi subatoi self-assigned this Feb 16, 2024
subatoi
subatoi previously approved these changes Feb 16, 2024
Copy link
Contributor

@subatoi subatoi left a comment

Choose a reason for hiding this comment

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

Thank you! Only minor and super minor (purely docs) comments. This is very clear and matches the Java docs really well.

}
}

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.

But if we think that it's fine to highlight the entirety of sinkModel(namespace, ..., I can change it over.

I think this would probably would be best, but it would involve numerous edits to both this documentation and the Java documentation. If you have time to do this, it'd be great, but it's not urgent 👍

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.

I think analyses is probably better in both contexts, but I don't think the gain in clarity is enough to justify making edits here and in the Java docs, since "analysis" does also technically make sense (at least I think it does!), and it wouldn't just affect this paragraph.

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.

Looks good to me!

egregius313 and others added 2 commits February 20, 2024 14:17
Co-authored-by: Ben Ahmady <32935794+subatoi@users.noreply.github.com>
@egregius313 egregius313 force-pushed the egregius313/csharp/docs/mad-docs branch from be4c14d to c5dbaa6 Compare February 20, 2024 19:17
@michaelnebel
Copy link
Contributor

@subatoi @hvitved @jf205 : Are there any objections on merging the documentation?

@subatoi
Copy link
Contributor

subatoi commented Feb 27, 2024

@michaelnebel not from me from a Docs point of view 👍

@subatoi
Copy link
Contributor

subatoi commented Feb 27, 2024

@michaelnebel Sorry for the late thought: it occurred to us to check this is due to ship with CLI 2.16.3. If so, all good 👍

Edit: 2.16.4, apologies

@michaelnebel
Copy link
Contributor

@michaelnebel Sorry for the late thought: it occurred to us to check this is due to ship with CLI 2.16.3. If so, all good 👍

Alright thank you!
In case it is not shipped, I suppose we can merge most of the content of the PR and just make orphan and not link it from the main documentation?

@egregius313 egregius313 merged commit a743683 into github:main Feb 27, 2024
- The second value ``SqlCommand`` is the name of the class (type) that contains the method.
- The third value ``False`` is a flag that indicates whether or not the sink also applies to all overrides of the method.
- The fourth value ``SqlCommand`` is the method name. Constructors are named after the class.
- The fifth value ``(System.String,System.Data.SqlClient.SqlConnection)`` is the method input type signature. The type names must be fully qualified.
Copy link
Contributor

Choose a reason for hiding this comment

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

The type names must be fully qualified.

More curiosity than an actual problem, but why does C# require fully qualified names, but Java doesn't?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation ready-for-doc-review This PR requires and is ready for review from the GitHub docs team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants