Skip to content

Instantly share code, notes, and snippets.

@sillypog
Created December 1, 2016 02:08
Show Gist options
  • Save sillypog/630877eb663efcf47f063217b19cd3d3 to your computer and use it in GitHub Desktop.
Save sillypog/630877eb663efcf47f063217b19cd3d3 to your computer and use it in GitHub Desktop.
Fragment SQL injection warning
iex(3)> where_string = "device_id = AAA OR login_id = 123"
"device_id = AAA OR login_id = 123"
iex(4)> query = from u in Portmeirion.User, limit: 1, select: %{warehouse_id: u.warehouse_id}, where: fragment(^where_string)
** (ArgumentError) to prevent sql injection, only a keyword list may be interpolated as the first argument to `fragment/1` with the `^` operator, got `"device_id = AAA OR login_id = 123"`
(ecto) lib/ecto/query/builder.ex:512: Ecto.Query.Builder.keyword!/1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment