-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C++: Allow MaD barriers #21162
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++: Allow MaD barriers #21162
Conversation
This commit was done by Opus 4.5 with the following prompt: In the commit 004d40e I have made it so that C# CodeQL queries which use sinks defined using data extensions (also known as "models-as-data"), which are accessed using `sinkNode(Node node, string kind)`, also use barriers defined using models-as-data, which are accessed using `barrierNode(Node node, string kind)`, with the same `kind` string. Please do the same for C++. If there are any complicated cases then list them at the end for me to do manually.
6b6c317 to
656ebab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enables Models-as-Data (MaD) barriers for SQL injection detection in C/C++ code. The change allows SQL injection barriers to be defined using the extensible Models-as-Data framework, complementing the existing hardcoded barrier for integral types.
Changes:
- Added MaD barrier support to the SQL injection query's
isBarrierpredicate
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
It seems this might also need a test? |
|
@jketema The PR that added the ability to specify barrier nodes added a test of that ( With the other languages I've done this for, there have been existing sanitizers that I can convert, so that has acted as a kind of test for these extension points. Now that I look closer, I see that there are two classes extending |
|
But that ir barrier guard test does not exercise the change made here, or does it? |
I can have a look. |
|
Looks like the MySql one should be easy to rewrite. However, it seems there is something a bit off with the query. The use of
I'll try fixing those two issues first. |
|
This may be C++ specific, but how do MaD summary models and MaD barrier models interact? I tried to rewrite the MySQL barrier model to use MaD, but realized that the tests weren't triggering an injection without the model either, because we don't model flow through the escaping functions. So, I though I'd add both a summary and a barrier model: Quick-eval'ing WIP branch: https://github.com/github/codeql/tree/jketema/sql-barrier |
@owen-mc I merged a fix for this. |
|
Oh! I know why this doesn't work. It comes from a misunderstand of the "Argument" column of the new barrier MaD models. Looking at the shared code for how these rows are interpreted we see that the column @jketema specified is interpreted as an "output" column and not an "input" column (let's ignore C++ specific details such as indirections for this discussion). This means that for a call such as However, the summary specified for If you place the barrier on I think this is a mistake in the design of the new MaD rows. It should be possible to place a barrier not only on output columns, but also on input columns ... but I can also see the benefit of this simple model (i.e., "it's always interpreted as an output"), but it should probably be documented. |
|
🤦♂️ I think using the output argument (1st argument) is fine here. I think I just got confused by a bit too many copy-and-pastes. And I also got confused by the |
C++: Add MySQL MaD taint and barrier models
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming Owen looked my changes over, this LGTM. I'm currently still running DCA, so want to hold off merging until that comes back ok.
|
Yes, I reviewed your changes. Does |
Correct. Note that multiple |
|
DCA was uneventful. |
The first commit was done by Opus 4.5. I then rebased it after C++: Support models-as-data barriers and barrier guards was merged and deleted most of its work.