22.10.2015, 09:48
To filter out special characters that the SQL interpreter may read as part of the query rather than part of the string. You will either get an erroneous query or an unexpected result which may prove useful to a hacker. For example the character ' (single quote) is used to denote strings, but if it appears in a string itself it must be escape, for example:
Would produce an error
Would not produce an error.
This is the simple case, but it is also necessary to protect against people who could exploit this by supplying a weird input, like
In which case the unescaped query would look like:
That will likely yield the first account in the database which is nearly always the one of the administrator, leading to potentially dangerous situations.
Any time you expect user input. That includes dialogs, chat text and command text.
PHP код:
... WHERE name='O'Hare';
PHP код:
... WHERE name='O\'hare';
This is the simple case, but it is also necessary to protect against people who could exploit this by supplying a weird input, like
PHP код:
zrtpqdfgh' OR 1=1; --
PHP код:
... WHERE name='zrtpqdfgh' OR 1=1; --';
Any time you expect user input. That includes dialogs, chat text and command text.