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

sql-injection: consider case using psycopg2.extensions.AsIs #225

Closed
moylop260 opened this issue Nov 16, 2018 · 13 comments
Closed

sql-injection: consider case using psycopg2.extensions.AsIs #225

moylop260 opened this issue Nov 16, 2018 · 13 comments

Comments

@moylop260
Copy link
Collaborator

Steps:

  1. Create a odoo module using the following sql injection case:
from psycopg2.extensions import AsIs
self.env.cr.execute("SELECT id FROM %s", (AsIs('res_users; DELETE FROM res_users;'),))
  1. Run pylint enabling sql-injection checker.

Saw:
sql-injection checker is not detected.

Expected:
sql-injection checker detected.

@pedrobaeza
Copy link
Member

pedrobaeza commented Nov 16, 2018

Well, you are ruining the trick for avoiding the check, as there's no other way of for example build the SQL views reports.

@moylop260
Copy link
Collaborator Author

We can use a sanitize method like
OCA/server-tools#1426 (comment)

Could you share me a code bypassing this check using AsIs?

In order to check if there is a way to skip a special case from the check

@moylop260
Copy link
Collaborator Author

Using private attributes was fixed here:

I mean, sql-injection is not face out if the variables startswith _

I just have created the following PR to test the case:

@pedrobaeza
Copy link
Member

Can you try with a variable inside the same scope (not an object variable)?

@moylop260
Copy link
Collaborator Author

@pedrobaeza
Copy link
Member

Well, I mean if it doesn't count when the variable is in the same scope. Any way, I don't like this, as you are reducing also the possibilities. What about if I want to put this:

"CREATE VIEW %s AS (SELECT %s FROM res_partner)" % (_variable, self.select()))

@moylop260
Copy link
Collaborator Author

moylop260 commented Nov 21, 2018

I just have created a table of True with all cases using public and private attributes and using with and without underscored variables.

Use Result
self._private_attribute skip sql-injection
self.public_attribute sql-injection
_variable sql-injection
variable sql-injection

Really, if you use a variable doesn't matter the name.
For OOP the attributes change if it starts with a underscore.
Then, the variables are out of scope for this case.

@pedrobaeza
Copy link
Member

Then that's why I don't want this new check, because that are valid cases.

@moylop260
Copy link
Collaborator Author

I don't get you.

@pedrobaeza
Copy link
Member

Enabling this check, my cases will be considered error.

@moylop260
Copy link
Collaborator Author

moylop260 commented Nov 22, 2018

Considering AsIs in the sql-injection check, the new result should be:

Use Current Result New Result
1 AsIs(self._private_attribute) skip sql-injection skip sql-injection
2 AsIs(self.public_attribute) skip sql-injection sql-injection
3 AsIs(_variable) skip sql-injection sql-injection
4 AsIs(variable) skip sql-injection sql-injection
5 self._private_attribute skip sql-injection skip sql-injection
6 self.public_attribute sql-injection sql-injection
7 _variable sql-injection sql-injection
8 variable sql-injection sql-injection

In this case, you are in the first case, then, your cases won't considered sql-injection error.
In fact, if you remove AsIs like case # 5, neither will considered error, since that we are skipping private attributes from #226

@moylop260
Copy link
Collaborator Author

Closing since it is a valid workaround where the dev needs to be sure it is not a sql-injection

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

No branches or pull requests

2 participants