Avoid BigQuery SQL injection in Go with saferbq
When building BigQuery applications using the Go SDK you may allow users to select tables or datasets dynamically. This means you need to include user-specified identifiers in your SQL queries. I was surprised that the BigQuery manual and code examples do not warn about SQL injection vulnerabilities when doing this. Even more surprising: BigQuery does not provide a built-in mechanism to safely handle user input in table or dataset names. The official SDK supports parameterized queries for data values using @ and ? syntax, but these cannot be used for identifiers that need backtick escaping. You may be tempted to use string concatenation, but that opens the door to SQL injection, and should be avoided. This post explains the problem and introduces saferbq, a Go package I wrote to help you write injection-free BigQuery SQL. ...