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

Sanitizing JSON objects in SQL queries #332

Closed
hoffmanilya opened this issue May 8, 2020 · 3 comments
Closed

Sanitizing JSON objects in SQL queries #332

hoffmanilya opened this issue May 8, 2020 · 3 comments
Assignees

Comments

@hoffmanilya
Copy link

When using Postgres 10/Rails 5, given an INSERT statement as so:

INSERT INTO foos(foo_id, bar_id, external_id, email_address, created_at, updated_at)
    SELECT 123, 456, external_id, email_address, NOW(), NOW()
    FROM jsonb_to_recordset($${"items":[{"external_id":1234,"email_address":"test@domain.com"}]}$$::jsonb->'items')
        AS t(external_id integer, email_address varchar)

The trace that is sent to Scout does not sanitize the JSON object properly. This is what I see as the SQL in Scout:

INSERT INTO foos(foo_id, bar_id, external_id, email_address, created_at, updated_at) 
    SELECT ?, ?, external_id, email_address, NOW(), NOW() 
    FROM jsonb_to_recordset($${"items":[{"external_id":"?","email_address":"test@domain.com"}]}$$::jsonb->'items') 
    AS t(external_id integer, email_address varchar)

Notice that the value of the external_id key in the JSON is sanitized but the value of the email_address key is not. Is there a configuration setting to enable sanitization of all parameters in the query?

@cschneid cschneid self-assigned this May 8, 2020
@cschneid
Copy link
Contributor

cschneid commented May 8, 2020

Thank you for the excellent report. Unfortunately there's no additional config to tweak the sql sanitization.

Is the json object inside jsonb_to_recordset being passed as a bind parameter, or is it in the SQL directly?

I'll get this added to the sanitization code either way.

@hoffmanilya
Copy link
Author

@cschneid thanks for the quick reply! In this case, the JSON object is directly inside the SQL.

@dlanderson
Copy link
Contributor

Closed in #431 - pending gem release.

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

3 participants