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

Unexpected behavior that can corrupt application data #69

Open
teso opened this issue Jul 31, 2018 · 2 comments
Open

Unexpected behavior that can corrupt application data #69

teso opened this issue Jul 31, 2018 · 2 comments

Comments

@teso
Copy link

teso commented Jul 31, 2018

return ($value !== false) ? '1=1' : '1=0';

I just had following situation:

  1. Prepared query like that UPDATE ?t:tableName SET ?s:setValues WHERE ?w:whereCondition
  2. Gave data for placeholders:
    'tableName' => 'manager',
    'setValues' => ['companyId' => '61eaf81b8a5b11e39ba6c436c32fa3a3'],
    'whereCondition' => 'id = ?:id',
    'id' => '61eaf81b8a5b11e39ba6c436c32fa3a3'

I expected that templater will replace all placeholders recursivly, but it not happend.
Okey, its my fault, i was not attentive when read documentation. But, more interesting what query i got: UPDATE manager SET companyId="61eaf81b8a5b11e39ba6c436c32fa3a3" WHERE 1=1
It means if you will give something that is not array or FALSE in ?w-placeholder you will update ENTIRE TABLE. Code will not abort with exception, it silently will corrupt your data.

@mkedo
Copy link
Contributor

mkedo commented Jul 31, 2018

@teso Sorry to hear that, I hope you could recover your data.
I agree, the WHERE placeholder should be more picky about the type of data provided to it.

The problem here is that if we start throwing exceptions on everything except, lets say, boolean or array, we might break backwards compatibility.

@vasa-c What do you think? Throwing an exception, at least for a string, sounds reasonable, to prevent thoses kind of mistakes.
I hope no one really uses strings there.

@teso
Copy link
Author

teso commented Aug 2, 2018

@mkedo Fortunately, it happend on the dev environment (but i have no dump for restoring).
We can left this ability only for SELECT queries (for backwards compatibility) and throw exceptions for other cases (if something except array will be given).

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

No branches or pull requests

2 participants