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

Dynamic: add Fuzzy token #13737

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

Conversation

asgerf
Copy link
Contributor

@asgerf asgerf commented Jul 13, 2023

Adds a Fuzzy token to the identifying access path for all dynamic languages, which will match, loosely speaking, an arbitrary series of operations.

For example, suppose we wanted to add a SQL injection sink for the query method in the mysql package, but we don't have a detailed enough knowledge of the library to do this precisely. So we just write the model like this:

mysql; Fuzzy.Member[query].Argument[0]; sql-injection

This would match all query calls whose receiver is an object that appears to come from the mysql package. The latter criterion comes from "tracking through an arbitrary series of operations".

This can serve as a foundation for a dedicated extension point for fuzzy models. An entry in such a fuzzy model might simply look like:

mysql; query; Argument[0]; sql-injection

The API graph entry point depended on API::Node.

This was due to depending on the the TComponent newtype which has a branch that depends on API::Node
@asgerf asgerf added the no-change-note-required This PR does not need a change note label Jul 14, 2023
@asgerf asgerf marked this pull request as ready for review July 14, 2023 10:50
@asgerf asgerf requested review from a team as code owners July 14, 2023 10:50
Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

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

Python 👍
And thanks for implementing this for Python, also! 💪
I suppose that in getAFuzzySuccessor we should make sure to avoid loops and that is why self parameters are avoided in Ruby. The Python implementation does look loop-free as far as I can tell. Do the DCA runs actually test the new feature, if we have no fuzzy specifications yet?

conn.query(q, (err, rows) => {...}); // <-- add 'q' as a SQL injection sink
});
We can recognize this using a fuzzy model, as showin in the following extension:
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
We can recognize this using a fuzzy model, as showin in the following extension:
We can recognize this using a fuzzy model, as shown in the following extension:

data:
- ["mysql", "Fuzzy.Member[query].Argument[0]", "sql-injection"]
- The first column, **"mysql"**, begins the search at at places where the `mysql` package is imported.
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
- The first column, **"mysql"**, begins the search at at places where the `mysql` package is imported.
- The first column, **"mysql"**, begins the search at places where the `mysql` package is imported.

In principle, this would also find expressions such as `pool.query` and `err.query`, but in practice such expressions
are not likely to occur, because the `pool` and `err` objects do not have a member named `query`.
- **Argument[0]** selects the first argument of a call to the selected member, that is, the `q` argument to `conn.query`.
- **sql-injection** indicates that this is considered a sink for the SQL injection query.
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
- **sql-injection** indicates that this is considered a sink for the SQL injection query.
- **sql-injection** indicates that this is considered as a sink for the SQL injection query.

@@ -431,6 +484,9 @@ The following components are supported:
- **MapValue** selects a value of a map object.
- **Awaited** selects the value of a promise.
- **Instance** selects instances of a class.
- **Fuzzy** selects all values that are derived from the current value through a combination of the other operations described in this list.
For example, this can be used to find all values the appear to originate from a particular package. This can be useful for finding method calls
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
For example, this can be used to find all values the appear to originate from a particular package. This can be useful for finding method calls
For example, this can be used to find all values that appear to originate from a particular package. This can be useful for finding method calls

Copy link
Contributor

@alexrford alexrford left a comment

Choose a reason for hiding this comment

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

Ruby LGTM - I've played around with this a bit and it seems potentially very useful for modeling automation.

or
result = node.getAnElement()
or
result = node.getInstance()
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess that this means that "FuzzyLib!;Fuzzy.<path>;test-sink" will find strictly more results than "FuzzyLib;Fuzzy.<path>;test-sink"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants