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

Possible SQL injection vector through string-based query construction. #75

Open
dim5x opened this issue Sep 19, 2020 · 0 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@dim5x
Copy link
Owner

dim5x commented Sep 19, 2020

Describe the bug

    • query = 'select count(1) _count from [admin] where [login] = %(login)s' % {'login': login}
    • ''' % {'login': login, 'description': description}
    • ''' % {'login': login}
    • ''' % {'login': login, 'hash': hash_sha384}
-Важно!

Никогда, ни при каких условиях, не используйте конкатенацию строк (+) или интерполяцию параметра в строке (%) для передачи переменных в SQL запрос. Такое формирование запроса, при возможности попадания в него пользовательских данных – это ворота для SQL-инъекций!

Правильный способ – использование второго аргумента метода .execute()

Возможны два варианта:

  1. C подстановкой по порядку на места знаков вопросов:
    cursor.execute("SELECT Name FROM Artist ORDER BY Name LIMIT ?", ('2'))

  2. И с использованием именованных замен:
    cursor.execute("SELECT Name from Artist ORDER BY Name LIMIT :limit", {"limit": 3})

@dim5x dim5x added the bug Something isn't working label Sep 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants