-
Notifications
You must be signed in to change notification settings - Fork 873
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
SET LOCAL with parameters fails with syntax error #1928
Comments
Same issue and error is returned with the |
This change: Should probably be something like:
But reading the CVE I think neither the original patch, nor this "don't break various queries version" may not solve the problem correctly. A test should be added that directly addresses the CVE because it seems like a value could be sent that includes a closing paren which would bypass this mitigation. I think the second part of the above or clause is not entirely correct. I think we have to actually parse the string for quotes because a value like |
I ended up going with a different approach using the postgresql extension of escape strings. |
@gregwoodfill I'm willing to try to get this working again, but it's more or less a happy accident that it ever did work. To be honest, I never anticipated people purposely using the simple protocol to get parameter substitution in cases where PostgreSQL doesn't allow it. I had intended it to match the capabilities of the extended protocol / prepared statements in cases where the simple protocol was in use. @michaelcmelton Can you give an example? |
Hey @jackc ! Thanks for the quick response! So we're running queries via gorm which has it's own postgres driver that's entirely dependent on your library. In these queries, we're doing some date calculations on the fly with
The resultant query on the DB side is logged and looks something similar to this:
Given the changes in the sanitizer, even with a properly formatted parameter, SQL returns a syntax error pointing directly to the substituted interval string everything else seems valid. |
@jackc thank you for the reply. If the design of PGX is to follow parameter substitution only where PostgreSQL allows, then I think it's fair that this is now the expected behavior. If this was changed in a future update, we would go back to using it, but for now we have a workaround for our one case that we were using simple protocol with parameter substitution. |
This still solves the problem of negative numbers creating a line comment, but this avoids breaking edge cases such as `set foo to $1` where the substition is taking place in a location where an arbitrary expression is not allowed. #1928
I've released v5.5.5 and v4.18.3 which now use spaces instead of parentheses to ensure a minus can't be directly in front of a negative number leading to a line comment ( @michaelcmelton Your e.g.
It might be better would be to pass in a Go |
Describe the bug
When calling conn.Exec to set a local postgres with parameters, a syntax error is returned.
This started happening in v5.5.4 and looks to be related to adding parentheses around parameter values from this commit: c543134
Issuing SET LOCAL with a value wrapped in parentheses is not valid Postgres syntax.
To Reproduce
Steps to reproduce the behavior:
Please run your example with the race detector enabled. For example,
go run -race main.go
orgo test -race
.Expected behavior
conn.Exec executes the statement without error.
Actual behavior
conn.Exec returns a syntax error.
Version
Additional context
Add any other context about the problem here.
Appears to have been introduced here: c543134
PostgreSQL documentation on SET LOCAL: https://www.postgresql.org/docs/current/sql-set.html
The text was updated successfully, but these errors were encountered: