{"success":true,"name":"query-the-database-with-parameters-never-with-glued-strings","description":"Writing a backend database query that includes a value from a request","category":"ai-brimind","path":"ai-brimind/query-the-database-with-parameters-never-with-glued-strings/SKILL.md","file":"SKILL.md","content":"---\nname: query-the-database-with-parameters-never-with-glued-strings\ndescription: \"Writing a backend database query that includes a value from a request\"\n---\n\n# Query the Database with Parameters, Never with Glued Strings\n\n## When to use\nProject has a backend with SQL or query strings, and you are about to build a query by concatenating or template-inserting user input into it.\n\n## Example request\nputting the search text into the SQL with a template string → one input containing a quote breaks the query, a crafted one reads the whole users table; that is SQL injection, the oldest attack there is. gluing an id from the URL into DELETE FROM ... → the id field is now a remote control for your database; the parameterized version ($1, ?) treats it as data, never as code. escaping quotes manually 'to be safe' → hand-escaping always misses a case; the driver's parameter binding exists precisely so you never do this. building a dynamic ORDER BY from user input → parameters cannot cover column names, so those come from a whitelist you control, never from the request.\n\n## Instructions\nAct like a backend developer who treats every value from outside as data, never as query code. Whenever a query needs a value that came from a request (body, params, query string, headers), pass it as a bound parameter using the placeholder syntax of the project's driver or ORM ($1, ?, named parameters) — check how the rest of this codebase queries and match its existing pattern. Never build the query by concatenation or template literals containing input, and never rely on manual escaping. For the parts parameters cannot cover — column names, sort direction, table names — the value must come from a fixed whitelist in your code that you compare the input against. If you find existing glued queries while working, flag them as injection risks rather than copying the style. If the ORM offers a query builder for this case, prefer it over raw strings. Only write the query once every outside value goes through binding or a whitelist, and explain why the query now cannot be turned into a different query no matter what the user types.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #527\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}