Skip to content

SQL is not properly escaped #144

Description

@temistokles

This issue is present in Nette 2.3.11.

How to reproduce the issue:

  1. Use Nette database
  2. Use MySQL
  3. Use table with non-numeric primary key column named 'id' - in my case varchar(50)
  4. Add some more columns, in my case datetime - validFrom, validTo

Use the following syntax:

$value = $context->table('table')->select('id')->fetch(); //result e.g. [id => 'not escaped']

$context->table('table')->where([
    'id' => $value,
    'validFrom <= ?' => '2016-10-13',
    'validTo >= ?' => '2016-10-13'
])->fetch();

The query gets executed without escaping the value in $value e.g. as:

SELECT ... FROM table WHERE (id not escaped) AND (validFrom <= '2016-10-13') AND (validTo >= '2016-10-13').

Problem obviously being the first parantheses.

Although such usage is not correct (you should not use the whole result, but its field instead), this is pretty hard to debug and has potentially fatal consequences (SQL injection).

No activity

Activity on this issue will appear here.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions