Skip to content

Conversation

@japroc
Copy link
Contributor

@japroc japroc commented May 5, 2021

Hello!

The main goal of my PR it to add support of pqxx connector.
Right now there are only MyQSL and SQlite support. And it is based solely on function name.
Pqxx sink is a bit more complex, because functions like "exec" may lead to high false positive rate.

I basically reused existing SqlTainted query, and created a custom SqlPqxxTainted query. I think that pqxx support should be implemented in Security.qll, but i seems not so simple to overwrite the logic behind SqlTainted query and it's Taint Configuration. That is why i decides to create separate query. I have also added example file SqlPqxxTainted.c and SqlPqxxTainted.qhelp which almost completely repeats SqlTainted.qhelp.

@MathiasVP
Copy link
Contributor

Hi @japroc,

Thank you for your contribution. We will find a reviewer for your query soon :)

I took a quick and very high-level look at your query, and I think it looks good. One thing you need to change is to give your query a unique @id (as the one you've picked currently conflicts with the SqlTainted query). Perhaps cpp/sql-injection-via-pqxx?

@japroc
Copy link
Contributor Author

japroc commented May 6, 2021

Nice, thanks!

I also want to mention that i dont check namespace. It thought that this operation may be redundant.
You can see that second parameters of predicates calls pqxxTransationClassNames and pqxxConnectionClassNames are blank. I can add namespace check by adding t.getParentScope().(Namespace).getName() instead of _.

@jbj jbj self-assigned this May 10, 2021
@jbj
Copy link
Contributor

jbj commented May 12, 2021

Thank you for the submission. I expect to review this PR next week.

@MathiasVP MathiasVP assigned MathiasVP and unassigned jbj May 25, 2021
Copy link
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, @aproc!

The PR looks super good, so I hope it's okay I commented on a few stylistic things. When these are fixed I'll happily merge your contribution :)

import semmle.code.cpp.dataflow.TaintTracking
import DataFlow::PathGraph

predicate pqxxTransationClassNames(string class_name, string namespace) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We use camelCalse for variables in QL.

@japroc
Copy link
Contributor Author

japroc commented May 25, 2021

Thanks for your contribution, @japroc!

The PR looks super good, so I hope it's okay I commented on a few stylistic things. When these are fixed I'll happily merge your contribution :)

Hi, @MathiasVP!

Nice! I have made changes suggested by you.
What do you think about checking namespace. I could add t.getParentScope().(Namespace).getName() in getPqxxSqlArgument function and isEscapedPqxxArgument predicate. There are some name collisions possible. If you think it's redundant enhancement, we could skip this step and go on.

Thanks!

@japroc japroc requested a review from MathiasVP May 25, 2021 19:45
@MathiasVP
Copy link
Contributor

What do you think about checking namespace. I could add t.getParentScope().(Namespace).getName() in getPqxxSqlArgument function and isEscapedPqxxArgument predicate. There are some name collisions possible. If you think it's redundant enhancement, we could skip this step and go on.

Good point. I think it's a good idea to check for the namespace. Your solution sounds fine, but you might be able to simplify the implementation if you change the type of t in getPqxxSqlArgument from Type to Struct. Then you can use the getNamespace() predicate and avoid dealing with parent scopes.

@japroc
Copy link
Contributor Author

japroc commented May 26, 2021

What do you think about checking namespace. I could add t.getParentScope().(Namespace).getName() in getPqxxSqlArgument function and isEscapedPqxxArgument predicate. There are some name collisions possible. If you think it's redundant enhancement, we could skip this step and go on.

Good point. I think it's a good idea to check for the namespace. Your solution sounds fine, but you might be able to simplify the implementation if you change the type of t in getPqxxSqlArgument from Type to Struct. Then you can use the getNamespace() predicate and avoid dealing with parent scopes.

Struct type does not fit this case. Because we lose work which is typedef transaction<> work;. But UserType which is indirect superclass of Struct works good.

Copy link
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants