Scrivio Interview library
ScenarioIntermediate6 min read · updated 12 November 2026

A static analysis tool reports 400 possible SQL injection findings in a ten-year-old codebase with JDBC, JPA and MyBatis. How do you triage and fix them efficiently?

Do not work through 400 findings one by one. Group them by pattern, such as string concatenation in JDBC, ${} in MyBatis and dynamic ORDER BY, and by whether user input can reach them, then fix internet-facing paths first. Most fixes are mechanical: bind parameters instead of concatenation, #{} instead of ${} in MyBatis except for allowlisted identifiers, and shared helpers with allowlists for dynamic columns and sorting. Finally, add the rule to CI so no new code introduces the pattern, and record verified false positives so they do not come back.

Why this question is asked

Static analysis on an old codebase produces numbers that freeze teams: 400 possible SQL injections sounds like an emergency and a year of work at the same time. In reality, such a list usually contains a few patterns repeated many times, a fair number of false positives, and a small set of findings that are truly dangerous. Interviewers ask this scenario to see whether we can turn a long list into a plan: find the real risk fast, fix it efficiently, and stop the list from growing back. In this answer, we will triage by pattern and reachability, set priorities, look at the fix for each pattern in JDBC, JPA and MyBatis, build shared helpers for dynamic identifiers, and add the CI gate and the false-positive process.

1Triage by Pattern, Not by Finding

The first step is to export the findings and group them by the code pattern that triggered them. In a ten-year-old codebase with three persistence technologies, the groups typically look like this: string concatenation into JDBC statements, concatenation into JPQL or native queries in JPA, ${} substitution in MyBatis mapper XML or annotations, and dynamic ORDER BY or column names built from parameters. Each group has one standard fix, so grouping turns 400 problems into four or five kinds of work.

Within each group, we look at the shape of the concatenated values. Many findings concatenate constants, enum names or numbers that are already typed as int or long; those are not injectable, though they may still be worth cleaning up. The interesting ones concatenate String values.

Example grouping of 400 findings
PatternCountStandard fix
JDBC string concatenation150PreparedStatement / JdbcTemplate with ?
MyBatis ${} for values110Replace with #{}
MyBatis ${} for identifiers40Allowlist helper, keep ${} on validated value
JPQL / native concatenation60Named parameters
Dynamic ORDER BY40Shared sort allowlist helper
Illustrative numbers; the real split comes from the export.

2Rank by Reachability and Exposure

Next we ask, for each finding, whether user input can reach it and from where. Many tools report taint paths, a trace from a source such as a request parameter to the query. Where they do not, a quick call-hierarchy search from the method to a controller, message listener or file import answers it. A query fed only by configuration or a nightly job's constants is low risk; a query fed by a public search box is critical.

Priority follows exposure. Internet-facing paths, such as public APIs, the customer website and partner endpoints, come first. Authenticated internal tools come next, because insiders and compromised accounts exist. Batch and admin paths fed by trusted data come last. In practice this often reduces the urgent set to a few dozen findings that can be fixed in days, which changes the conversation with management from "we have 400 vulnerabilities" to "the exposed ones are fixed, the rest are scheduled".

Step throughTriage of one finding
  1. Concatenated value is a String?Numbers and enums are not injectable
    YesCheck reachabilityNoLow: clean up later
  2. Reachable from user input?Taint path or call hierarchy
    YesCheck exposureNoMark verified false positive
  3. Internet-facing path?Public API, website, partner
    YesFix nowNoSchedule by exposure

3 steps in order. Play them, or step through them one at a time.

3Fixing Each Pattern

The fixes are mechanical once the pattern is known. For JDBC and JPA, values move into bind parameters: ? placeholders in PreparedStatement or JdbcTemplate, named parameters in JPQL and native queries. The query text becomes constant and the values travel separately to the database.

Java
// JDBC before / after
jdbc.query("select * from orders where customer = '" + name + "'", mapper);
jdbc.query("select * from orders where customer = ?", mapper, name);
<!-- MyBatis before: ${} pastes text into the SQL -->
<select id="find">select * from orders where customer = '${name}'</select>
<!-- MyBatis after: #{} becomes a bind parameter -->
<select id="find">select * from orders where customer = #{name}</select>
// name = "x' or '1'='1" -> before: all rows; after: no rows

In MyBatis the difference is a single character, and it is the most common finding in MyBatis code. #{name} produces a PreparedStatement parameter. ${name} performs string substitution before the SQL is sent, exactly like concatenation. Developers often used ${} because it seemed to work for everything, including column names, which is where the next step comes in.

4Shared Helpers for Dynamic Identifiers

Some ${} uses and concatenations are for identifiers, such as sort columns, sort directions or a choice of table, which cannot be bind parameters. For those, the fix is not escaping but an allowlist: the user chooses a key and the code maps it to a fixed identifier. Writing that check in every mapper would be slow and inconsistent, so we build one small shared helper and use it everywhere.

Java
public final class SqlIdentifiers {
public static String sortColumn(String requested, Map<String, String> allowed) {
String col = allowed.get(requested);
if (col == null) throw new IllegalArgumentException("Unsupported sort: " + requested);
return col; // a constant from our own map
}
public static String direction(String d) {
return "desc".equalsIgnoreCase(d) ? "DESC" : "ASC";
}
}
// service: params.put("orderBy", SqlIdentifiers.sortColumn(req.sort(), ORDER_COLUMNS));
// mapper: order by ${orderBy} ${dir} -- ${} kept, but only on validated constants

What changed is where the value comes from. The ${} in the mapper is still there, but it can only receive strings from our own map. A short comment, or a naming convention like a Safe suffix on the parameter, tells reviewers and the scanner that this use is deliberate. The same helper serves JDBC, JPA and MyBatis, and once it exists, teams fix dynamic-sort findings in minutes.

5Stop New Findings and Record False Positives

Fixing 400 findings is pointless if new code adds 50 more. So the rule goes into CI: the analyser, or a simple targeted check such as flagging ${ in mapper files and string concatenation inside query methods, runs on every pull request and fails the build for new findings. Using a baseline of existing findings lets the gate block new problems from day one while the backlog is still being worked through.

False positives need a process too. When someone verifies that a finding cannot be reached by user input, or that the concatenated value comes from an allowlist helper, they mark it as such in the tool, with a short reason and their name. Without that, the same findings reappear at every scan, people stop reading the report, and real findings get lost in the noise. Tracking the count per category each week shows progress and keeps the work visible.

6Follow-up questions

Should we stop feature work until all 400 are fixed?

Usually not. Fix the reachable internet-facing findings immediately, which is often a small set, then schedule the rest by exposure alongside normal work. The CI gate ensures the problem does not grow while the backlog shrinks.

Can a web application firewall cover the gap?

A WAF can block common payloads on exposed endpoints while fixes are in progress, which is useful as a temporary measure. It is not a fix, because payloads can be encoded or shaped to avoid its rules.

How do you verify the fixes did not break queries?

Run the existing integration tests against a real database, ideally with Testcontainers, and add tests for the dangerous inputs: a name with a quote should return no rows instead of all rows, and an unknown sort key should be rejected.

7Conclusion

In this answer, we turned 400 SQL injection findings into a plan. Grouping by pattern and checking reachability separates the dangerous findings from the noise, and internet-facing paths are fixed first. Concatenation becomes bind parameters, MyBatis ${} becomes #{} except for identifiers that go through a shared allowlist helper, and a CI rule with a baseline stops new findings while verified false positives are recorded so the report stays meaningful.

What to say in the interviewAbout 90 seconds aloud

Open with

I would not go through 400 findings one by one. First I would export them and group them by pattern: string concatenation in JDBC, concatenation in JPQL or native queries, dollar-brace substitution in MyBatis, and dynamic ORDER BY or column names.

Then, if they want more

In a codebase like that it is usually four or five patterns repeated many times, and each pattern has one standard fix. Then I would check reachability: is the concatenated value a String, and can user input reach it, using the tool's taint paths or a call hierarchy back to controllers and listeners.

Constants, numbers and enums are not injectable, so those drop to low priority or get marked as verified false positives. I would fix internet-facing paths first, then authenticated internal ones, then batch jobs.

The fixes themselves are mechanical: bind parameters with question marks in JdbcTemplate and named parameters in JPA, and in MyBatis replace dollar-brace with hash-brace, which turns substitution into a bind parameter.

For identifiers like sort columns, which cannot be parameters, I would add one shared helper that maps a user's choice to a column from an allowlist, so the remaining dollar-brace uses only ever receive our own constants.

Finally I would add the rule to CI with a baseline, so new code cannot introduce the pattern, and record verified false positives with a reason so the report stays trustworthy.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
OWASP Top Ten
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A static analysis tool reports 400 possible SQL injection findings in a ten-year-old...": https://scrivio-interview-library.netlify.app/spring-boot/web-security-threats/cc159001f4/