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

Rust: Add some flow source models #18069

Merged
merged 19 commits into from
Nov 26, 2024
Merged

Rust: Add some flow source models #18069

merged 19 commits into from
Nov 26, 2024

Conversation

geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented Nov 22, 2024

Add some flow source models:

  • command line arguments
  • environment
  • reqwest library

These were chosen to support writing simple test cases such as those we have for the SQL Injection query. We will need more and different sources to find much of real world security interest.

I've also added a bit more wiring in Concepts.qll, and created a new query and test to expose the sources directly.

@geoffw0 geoffw0 added no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code labels Nov 22, 2024
*/
private class StdEnvArgs extends CommandLineArgsSource::Range {
StdEnvArgs() {
this.asExpr().getExpr().(CallExpr).getExpr().(PathExpr).getPath().getResolvedPath() = ["crate::env::args", "crate::env::args_os"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@redsun82 these paths don't look right - I assume the correct path would be something like std::env::args or crate::std::env::args? They do match both what we get in the tests and what we see in real databases at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(fixing this will probably be follow-up work, what we have works well enough right now and is needed to get queries working)

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, this might have to do with the prelude, I'll have a look

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, no, currently that is expected.

The thing is that a path only makes sense in the context of a crate (there is no such thing as a global concept of path across crates). So that path is the correct one relative to the std crate.

The other piece of information is the (highly non-standard and prone to be changed) getCrateOrigin, which gives lang:std for the std lib.

we could theoretically combine the two, it's just that while I'm quite confident of the correctness of the resolved path (up to the fact that it may not cover all entities yet), I'm still unsure about the effectiveness of getCrateOrigin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. It sounds like we could check getCrateOrigin for models where we're worried about ambiguity ("crate::get" makes me nervous), but perhaps not check it for cases where we aren't (e.g. "crate::env::vars") since that will be more robust if getCrateOrigin is potentially prone to change. Alternatively we could fall back on other details such as types to ensure our models are matching the right things - to the extent that we extract enough information.

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've push a commit adding the restriction I described above.

I've also added an agenda item next week to discuss crate origins, how we can get reliable information and how they will interact with models-as-data.

// --- stubs for the "reqwest" library ---

/*
--- we don't seem to have a way to use this, hence we currently test against the real reqwest library
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@redsun82 I tried to stub reqwest, it has a much simpler interface than sqlx. But I ran into a problem that it's not possible (I think) to emulate the correct paths for the library and import it into a test.rs at the moment. When we can, we can switch to a stubbing approach for reqwest at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(fixing this will probably be follow-up work, what we have works well enough right now)

@geoffw0
Copy link
Contributor Author

geoffw0 commented Nov 25, 2024

I believe this is just waiting for approval.

update: new conflicts...

Copy link
Contributor

@redsun82 redsun82 left a comment

Choose a reason for hiding this comment

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

LGTM!

@redsun82 redsun82 merged commit cb0ac61 into github:main Nov 26, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants