-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[5.2] Wrap field name in MySQL JSON path expressions #12964
Conversation
Just noticed the failing tests, fixing it... |
…ressions must be wrapped
@themsaid thoughts? |
Yes correct, an error will be thrown if the field name is not wrapped for preserved keys. select |
So you're saying this should be merged @themsaid ? |
I think this can be simplified:
No need to call |
Wrapping the value surely isn't sufficient. We'd need to use prepared statements? |
I'm not at my disk now, I may look into that in detail later today. |
@themsaid sure, proposed simplification works for now, but each future improvement to wrapValue() - which may be security-related, for example when applying/changing escaping - must then be incorporated here. @GrahamCampbell As this PR is about wrapping column names: doesn't the mechanism of prepared statements apply to values only? Are prepared statements also applied to column names? |
We wouldn't use prepared statements for column names @GrahamCampbell |
I don't see how this is related to SQL injection at all in any way shape or form. |
It's only to wrap column names to be safe from conflicting with reserved keywords. |
@taylorotwell Before this PR, code like App\User::where($request->get('searchfield').'->selector', 'value')->delete() was vulnerable to SQL injection as it circumvented I know such code is a dangerous idea but now it's correctly wrapped (escaped). There's still Examples: Query as intended: delete from `users` where foo->selector=value Malicious query: SQL injection without fix: delete from `users` where foo=foo or foo->selector=value With fix a regular SQL error should be triggered: delete from `users` where `foo=foo or foo`->selector=value In addition, the attacker cannot break out of the backticks because If you think I'm correct then similar implementations for other grammars, e.g. PostgreSQL, could be vulnerable aswell and should be checked (I don't know PostgreSQL well enough) Note: I'm currently working on additionally wrapping/escaping the JSON path for the same reason. |
Without this, MySQL throws an error e.g. when using reserved names as field names.
At least in theory, this should also reduce attack surface for SQL injection! This weakness may apply to other database grammars (Postgres?), not tested.
Example behavior without this fix: