NOTE
1.7 SQL Injection
SQL injection embeds attack code in input so the server executes unintended SQL. These notes examine its causes and defenses.
This is a historical learning note and may contain outdated or incomplete understanding.
1. What Is SQL Injection
A kind of web attack. SQL injection is an attack technique in which SQL code is added to input parameters and passed to the server to be parsed and executed.
2. Why SQL Injection Happens
User input is concatenated directly into an SQL statement and executed.
3. How to Prevent SQL Injection
3.1. Enable SQL Precompilation
- Use
?as a placeholder for parameters when writing SQL. - Use Prepared Statements / parameterized APIs provided by the database driver to bind parameters instead of directly concatenating user input.
This separates the SQL structure from parameter data, so user input is passed only as data and is not parsed as SQL syntax. The key to preventing SQL injection is parameterization, not execution-plan caching.
4. Example
4.1. Golang
5. References
Drag to pan, scroll to zoom, and click a node to expand or collapse it. Large maps start with deeper levels collapsed; click nodes to expand them.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub