{"success":true,"name":"use-parameterized-queries-to-stop-sql-injection","description":"Writing SQL that includes any value coming from a user or request.","category":"ai-brimind","path":"ai-brimind/use-parameterized-queries-to-stop-sql-injection/SKILL.md","file":"SKILL.md","content":"---\nname: use-parameterized-queries-to-stop-sql-injection\ndescription: \"Writing SQL that includes any value coming from a user or request.\"\n---\n\n# Use Parameterized Queries to Stop SQL Injection\n\n## When to use\nProject uses a SQL database, and a query is being built where user input (form field, URL param, header) ends up inside the SQL string.\n\n## Example request\nQuery built with string concatenation: \"WHERE name = '\" + input + \"'\" → input of ' OR '1'='1 returns every row — classic injection. Search box crashes on names with apostrophes like O'Brien → the quote breaks the SQL string; the same hole attackers use — unescaped input. 'It's just an internal admin page' → internal tools get attacked too, and inputs get copy-pasted from untrusted sources — no trusted input exists.\n\n## Instructions\nAct like a developer who treats every user value as a potential attack string. Rule one: user input NEVER gets glued into SQL text. Always use the driver's parameterized/prepared form — placeholders like ? or $1 with values passed separately — so the database receives data as data, never as SQL. Before writing any query: (1) list which values come from outside (request body, query string, headers, even localStorage) — all of them go through placeholders, no exceptions for 'safe-looking' ones; (2) for dynamic parts that CANNOT be parameterized (table names, ORDER BY columns), use a whitelist: compare the input against a fixed set of allowed values and reject anything else; (3) check whether the project's DB library or ORM already provides safe query building before hand-writing SQL strings. Test with a value containing a single quote — if the query breaks or behaves oddly, the hole is real. Only proceed once zero user values are concatenated into query text and you can point to the placeholder carrying each one.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1082\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}