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

[5.2] Wrap and escape MySQL JSON path #12992

Closed
wants to merge 2 commits into from

Conversation

sbusch
Copy link

@sbusch sbusch commented Apr 2, 2016

Followup to PR #12964

Includes two tests (one related to #12964) to verify correct wrapping/escaping.

@sbusch
Copy link
Author

sbusch commented Apr 2, 2016

I'd rather use getPdo()->quote() from an associated connection instance instead of custom replacements with str_replace() but the grammar class has no access to the connection apparently.

OTOH is it possible to use prepared statements with bound parameters for the JSON path, like field->?? That would be way better. If MySQL doesn't allow this we could convert to JSON_EXTRACT(column, path) which is equivalent[1] and should allow bound parameters. Unfortunately wrapValue() is unable to inject bound variables.

[1] In MySQL 5.7.9 and later, you can use column->path with a JSON column identifier and JSON path expression as a synonym for JSON_EXTRACT(column, path).

@sbusch
Copy link
Author

sbusch commented Apr 2, 2016

Just tried: field->? is not allowed, but JSON_EXTRACT() would work.

@taylorotwell
Copy link
Member

I guess I don't understand why we are quoting column names? Are people really passing user input directly into their column names?

@GrahamCampbell
Copy link
Member

Are people really passing user input directly into their column names?

Well, if someone's not being careful with mass assignment, yes.

@taylorotwell
Copy link
Member

I don't really know if this is the correct way to prevent SQL injection. It seems pretty hacky and I don't know why people should be passing user input into their column names. I would rather just document not to allow users to control your column names in your queries.

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

Successfully merging this pull request may close these issues.

3 participants