PLAIN/TEXT — ISSUE 253/456 COMPUTER SCIENCE · FOUNDATION / DATABASE SECURITY · ~4 MIN READING DATE: 2027-06-11 ARCHIVE: https://plaintext.click/newsletter/ SUBJECT: Why a surname should never become database code Why a surname should never become database code =============================================== / START HERE A shop searches its customer list when someone enters a name. A database query is an instruction asking a stored collection of records to return or change information. SQL injection is a flaw in which supplied data changes the meaning of an instruction written in the SQL query language. A name should change which value is searched for, not which database instruction is performed. / WHY NOW A surname containing an apostrophe should not break a search. More seriously, a program that builds instructions by joining text can accidentally let a submitted value alter which records the database returns or changes. / THE IDEA The problem is mixing two roles in the same text: the trusted instruction and the untrusted value it operates on. Quotation marks have meaning to the query reader, so merely surrounding a supplied name with quotes does not reliably preserve that boundary. A parameterized query sends a fixed instruction shape with separate data values. A placeholder marks where a value belongs. The database interface binds the supplied value there as data, rather than reparsing its characters as extra query structure. This is different from checking whether a name contains suspicious punctuation. Real names legitimately contain punctuation, and rules designed to guess every dangerous string are fragile. Keep the code/data separation even after checking value type and length for the application’s ordinary requirements. / THE FORMAL IDEA SELECT id FROM customers WHERE surname = ? - SELECT asks for data; id is the requested field; customers is the fixed table. - WHERE restricts results; surname is the fixed field to compare; ? is a parameter placeholder. Exact placeholder notation depends on the database interface. / RUN THE TINY EXAMPLE Change one thing. Predict what happens. Bind the value Smith → search for the surname Smith. Change only the value to O'Neil, containing the straight quote used by SQL → search for the complete surname O'Neil. The instruction still contains one equality comparison and one value. Do not paste the supplied name into the instruction text before sending it. The changed input changes which value is matched, not what the database has been instructed to do. This distinction is the security mechanism. The example uses an ordinary name to show that safe handling should also preserve correct everyday behaviour. / SO WHAT? Parameters usually represent values, not arbitrary table names or sorting keywords. If a screen offers newest-first or oldest-first, map that choice to a small set of fixed instructions controlled by the application. A database account should also have only the access the feature needs, limiting consequences if another defect appears. / ONE CAVEAT Parameterization does not decide whether the caller may view a returned record. Dynamically constructed queries inside a stored procedure can still be unsafe, so trace where the final instruction is built. / KEEP THIS Keep query structure fixed and bind changing values separately so user data cannot acquire the role of database instructions. / SOURCE TRAIL [1] OWASP — SQL Injection Prevention https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html NEXT: What keeps a nuclear chain reaction going? --- HARD IDEAS. PLAIN TEXT. You are receiving this because you asked for one clear computer-science or physics idea each day. Unsubscribe: https://plaintext.click/unsubscribe View in browser: https://plaintext.click/newsletter/2027/06/2027-06-11-sql-parameterization.html From: Plain/Text / Brickston Consulting · 30 N Gould St Ste N, Sheridan, WY 82801 US · knowledge@plaintext.click