You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>Formatted SQL queries can be difficult to maintain, debug and can increase the risk of SQL injection when concatenating untrusted values into the
2
-
query. However, this rule doesn’t detect SQL injections (unlike rule {rule:javasecurity:S3649}), the goal is only to highlight complex/formatted queries.</p>
3
-
<h2>Ask Yourself Whether</h2>
4
-
<ul>
5
-
<li>Some parts of the query come from untrusted values (like user inputs).</li>
6
-
<li>The query is repeated/duplicated in other parts of the code.</li>
7
-
<li>The application must support different types of relational databases.</li>
8
-
</ul>
9
-
<p>There is a risk if you answered yes to any of those questions.</p>
or stored procedures</a> and bind variables to SQL query parameters.</li>
14
-
<li>Consider using ORM frameworks if there is a need to have an abstract layer to access data.</li>
15
-
</ul>
16
-
<h2>Sensitive Code Example</h2>
17
-
<pre>
1
+
<p>Dynamically building SQL query strings can result in broken SQL syntax and open SQL injection attacks.</p>
2
+
<h2>Why is this an issue?</h2>
3
+
<p>When SQL queries are constructed by concatenating or formatting user-supplied values directly into the query string, the structure of the query
4
+
itself can be altered by a malicious input. This rule flags calls to SQL execution functions where the query string is built using string
5
+
concatenation or format operators rather than parameterized queries or prepared statements. Unlike rule {rule:javasecurity:S3649}, this rule does not perform
6
+
taint analysis — it flags all dynamically formatted SQL queries as a potential risk regardless of the data source.</p>
7
+
<h3>What is the potential impact?</h3>
8
+
<h4>SQL injection</h4>
9
+
<p>If any part of a dynamically formatted query string originates from untrusted input, an attacker can manipulate the query to read, modify, or
10
+
delete data they should not have access to, bypass authentication checks, or in some configurations execute operating system commands.</p>
11
+
<h2>How to fix it</h2>
12
+
<h3>Code examples</h3>
13
+
<p>The following code builds a SQL query by concatenating a value directly into the query string.</p>
0 commit comments