Skip to content

Rust: update docs #19280

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

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

Rust: update docs #19280

wants to merge 19 commits into from

Conversation

redsun82
Copy link
Contributor

@redsun82 redsun82 commented Apr 11, 2025

This should be kept unmerged until we get to the public preview phase.

@redsun82 redsun82 changed the title Rust: start preparing documentation changes Rust: update supported languages and frameworks Apr 11, 2025
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

A few more libraries we model (partial support, but then I don't think we can claim to fully model any libraries). Sorry I probably missed a few of these in the list I sent you before.

We also have models for the standard io library coming in #19304 , I should update that PR once this is merged or vice-versa.

aibaars
aibaars previously approved these changes Apr 15, 2025
Co-authored-by: Geoffrey White <40627776+geoffw0@users.noreply.github.com>
Co-authored-by: Geoffrey White <40627776+geoffw0@users.noreply.github.com>
geoffw0
geoffw0 previously approved these changes May 2, 2025
@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jun 6, 2025
@github-actions github-actions bot removed the Rust Pull requests that update Rust code label Jun 10, 2025
@redsun82 redsun82 changed the title Rust: update supported languages and frameworks Rust: update docs Jun 10, 2025
@redsun82 redsun82 marked this pull request as ready for review June 12, 2025 15:35
@redsun82 redsun82 requested a review from a team as a code owner June 12, 2025 15:35
@redsun82 redsun82 requested a review from a team as a code owner June 13, 2025 11:03
@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jun 13, 2025
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

The two docs + other changes look great to me!

Some minor suggestions below.

"CodeQL library for Rust" doesn't go into a lot of detail, I think that's OK at this stage, it would be nice to have more example code in future.

I haven't checked the links, references to notes, and generally that everything fits together correctly - we really need a full preview for that and/or to be ready to correct any problems quickly after this goes live.

You should probably get a review from the docs team next?


- The class ``RemoteFlowSource`` represents data flow from remote network inputs and from other applications.
- The class ``LocalFlowSource`` represents data flow from local user input.
- The class ``FlowSource`` includes both of the above.
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 I'd prefer if we point people to Concepts.qll and the classes there. I'd prefer people use that interface, and it has a wider variety of pre-defined sources.

f.getParam(index).getPat().(IdentPat).getName().getText() = "password"
)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Indending needs fixing above.

exists(Function f, CallExpr call, int index |
call.getArg(index) = node.asExpr().getExpr() and
call.getStaticTarget() = f and
f.getParam(index).getPat().(IdentPat).getName().getText() = "password"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should strongly consider adding helper predicates getParamName and getArgName to make code like this a bit cleaner?

analyzing-data-flow-in-rust

- :doc:`CodeQL library for Rust <codeql-library-for-rust>`: When you're analyzing Rust code, you can make use of the large collection of classes in the CodeQL library for Rust.
- :doc:`Analyzing data flow in Ruby <analyzing-data-flow-in-rust>`: You can use CodeQL to track the flow of data through a Rust program to places where the data is used.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- :doc:`Analyzing data flow in Ruby <analyzing-data-flow-in-rust>`: You can use CodeQL to track the flow of data through a Rust program to places where the data is used.
- :doc:`Analyzing data flow in Rust <analyzing-data-flow-in-rust>`: You can use CodeQL to track the flow of data through a Rust program to places where the data is used.

Comment on lines +15 to +16
module `rust.qll <https://github.com/github/codeql/blob/main/rust/ql/lib/rust.qll>`__ imports most other standard library modules, so you can include the complete
library by beginning your query with:
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's "most" other standard library modules, it's not really "complete".

Suggested change
module `rust.qll <https://github.com/github/codeql/blob/main/rust/ql/lib/rust.qll>`__ imports most other standard library modules, so you can include the complete
library by beginning your query with:
module `rust.qll <https://github.com/github/codeql/blob/main/rust/ql/lib/rust.qll>`__ imports most other standard library modules, you can include them by beginning your query with:

Comment on lines +22 to +23
The CodeQL libraries model various aspects of Rust code. The above import includes the abstract syntax tree (AST) library, which is used for locating program elements,
to match syntactic elements in the source code. This can be used for example to find values, patterns and structures.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd drop this comma.

Suggested change
The CodeQL libraries model various aspects of Rust code. The above import includes the abstract syntax tree (AST) library, which is used for locating program elements,
to match syntactic elements in the source code. This can be used for example to find values, patterns and structures.
The CodeQL libraries model various aspects of Rust code. The above import includes the abstract syntax tree (AST) library, which is used for locating program elements
to match syntactic elements in the source code. This can be used for example to find values, patterns and structures.

Comment on lines +42 to +43
Data flow is particularly useful for security queries, where untrusted data flows to vulnerable parts of the program
to exploit it. Related to data flow, is the taint-tracking library, which finds how data can *influence* other values
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 clear what "it" is, and I think these few words are superfluous anyway.

Suggested change
Data flow is particularly useful for security queries, where untrusted data flows to vulnerable parts of the program
to exploit it. Related to data flow, is the taint-tracking library, which finds how data can *influence* other values
Data flow is particularly useful for security queries, where untrusted data flows to vulnerable parts of the program. Related to data flow is the taint-tracking library, which finds how data can *influence* other values


## Overview

<!-- autogenerated CWE coverage table will be added below -->
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 appreciative of the automation here!

Comment on lines +27 to +28
You can map a data flow ``ParameterNode`` to its corresponding ``Parameter`` AST node using the ``asParameter`` member predicate.
Similarly, you can use the ``asExpr`` member predicate to map a data flow ``ExprNode`` to its corresponding ``ExprCfgNode`` in the control-flow library.
Copy link
Contributor

Choose a reason for hiding this comment

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

The order of these two sentences is slightly distracting, as everywhere else we list expr nodes first and then parameter nodes.

Suggested change
You can map a data flow ``ParameterNode`` to its corresponding ``Parameter`` AST node using the ``asParameter`` member predicate.
Similarly, you can use the ``asExpr`` member predicate to map a data flow ``ExprNode`` to its corresponding ``ExprCfgNode`` in the control-flow library.
You can use the ``asExpr`` member predicate to map a data flow ``ExprNode`` to its corresponding ``ExprCfgNode`` in the control-flow library.
Similarly, you can map a data flow ``ParameterNode`` to its corresponding ``Parameter`` AST node using the ``asParameter`` member predicate.

~~~~~~~~~~~~~~~~~~~~~

You can use the local data flow library by importing the ``codeql.rust.dataflow.DataFlow`` module. The library uses the class ``Node`` to represent any element through which data can flow.
``Node``\ s are divided into expression nodes (``ExprNode``) and parameter nodes (``ParameterNode``).
Copy link
Contributor

Choose a reason for hiding this comment

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

This sounds like an exhaustive list but I think there are other kinds of nodes, e.g. flow summary nodes. I don't think we should bring them up here but maybe rephrase to something like:

Suggested change
``Node``\ s are divided into expression nodes (``ExprNode``) and parameter nodes (``ParameterNode``).
Common ``Node`` types include expression nodes (``ExprNode``) and parameter nodes (``ParameterNode``).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants