Scrivio Interview library
ConceptIntermediate6 min read · updated 12 November 2026

Pick five categories from the OWASP Top 10 (for example the 2021 edition; check for the latest) and give a concrete example of each in a Spring Boot service, with the control you would use.

Five categories from the OWASP Top 10 2021 map neatly onto everyday Spring Boot code: broken access control (an IDOR on /orders/{id}, fixed by checking ownership in the query or with method security), cryptographic failures (passwords stored as SHA-256, fixed with bcrypt or Argon2 and TLS everywhere), injection (concatenated JPQL, fixed with bind parameters), vulnerable and outdated components (Log4Shell or Spring4Shell, handled by dependency scanning and quick patching) and SSRF (a URL-fetch feature reaching the cloud metadata endpoint, fixed with a destination allowlist that blocks internal addresses). OWASP publishes new editions, so check the latest list, but these risks stay relevant.

Why this question is asked

The OWASP Top 10 is the most widely used list of web application risks, and interviewers like it because it tests whether we can connect a category name to real code. Reciting the list is easy; showing the vulnerable line in a Spring controller and the specific fix is what proves experience. In this answer, we will take five categories from the 2021 edition, and for each one look at a concrete vulnerable example in a Spring Boot service, why it is exploitable, and the control that fixes it.

1A Quick Recap of the OWASP Top 10

OWASP, the Open Worldwide Application Security Project, publishes the Top 10 every few years from data on real vulnerabilities. The 2021 edition starts with A01 Broken Access Control and includes A02 Cryptographic Failures, A03 Injection, A06 Vulnerable and Outdated Components and A10 Server-Side Request Forgery, among others. A newer edition may reorder or merge categories, so in an interview it is worth saying which edition we mean.

Five categories in a Spring Boot service
Category (2021)ExampleControl
A01 Broken access controlGET /orders/{id} returns any user's orderOwnership check in query or @PreAuthorize
A02 Cryptographic failuresPasswords stored as SHA-256BCrypt or Argon2, TLS everywhere
A03 InjectionJPQL built by string concatenationBind parameters
A06 Vulnerable componentsLog4Shell, Spring4ShellDependency scanning, fast patching
A10 SSRFFetch-URL feature reaches 169.254.169.254Allowlist, block internal addresses

2Broken Access Control: IDOR on Orders

An IDOR, an insecure direct object reference, is the most common form of broken access control. The endpoint takes an id from the URL and loads the record without checking that it belongs to the caller. The user is authenticated, so Spring Security lets the request through, but authentication only says who they are, not what they may see.

Java
@GetMapping("/orders/{id}")
Order get(@PathVariable long id) {
return orders.findById(id).orElseThrow(); // user 17 asks for /orders/9001 and gets user 42's order
}
// Fix: make ownership part of the query
@GetMapping("/orders/{id}")
Order get(@PathVariable long id, @AuthenticationPrincipal Jwt jwt) {
return orders.findByIdAndCustomerId(id, jwt.getSubject())
.orElseThrow(OrderNotFound::new); // 404 for someone else's order
}

Notice that we answer 404 rather than 403 for an order that exists but belongs to someone else, so an attacker cannot even learn which ids exist. Method security with @PreAuthorize or @PostAuthorize and a custom check works too, but putting the owner into the query is hard to forget and also avoids loading data we must not return.

3Cryptographic Failures: Fast Hashes for Passwords

SHA-256 is a good hash for integrity, but it is designed to be fast, and a modern GPU computes billions of SHA-256 hashes per second. If the user table leaks, most real passwords are cracked within hours. Password storage needs a slow, salted hash designed for the job: bcrypt, scrypt or Argon2. Spring Security's DelegatingPasswordEncoder stores the algorithm id with each hash, so we can upgrade later.

Java
String stored = sha256Hex(password); // fast, unsalted: cracked offline quickly
PasswordEncoder enc = PasswordEncoderFactories.createDelegatingPasswordEncoder();
String hash = enc.encode("correct horse"); // {bcrypt}$2a$10$... with a random salt
enc.matches("correct horse", hash); // true

The second half of this category is data in transit: every connection carrying credentials or personal data, including service-to-service calls and the database connection, uses TLS, and cookies are marked Secure.

4Injection: Concatenated JPQL

JPA does not protect us when we build the query text from input. A search method that concatenates a name lets the caller change the query, for example adding or '1'='1' to return every row. The fix is a named or positional bind parameter, which sends the value separately from the query.

Java
String q = "select c from Customer c where c.name = '" + name + "'";
em.createQuery(q, Customer.class).getResultList(); // name = "x' or '1'='1" returns all customers
em.createQuery("select c from Customer c where c.name = :name", Customer.class)
.setParameter("name", name).getResultList(); // safe: name is only data

5Vulnerable Components: Log4Shell and Spring4Shell

Log4Shell, CVE-2021-44228, let an attacker trigger a JNDI lookup by putting a string like ${jndi:ldap://...} in any logged value, such as a User-Agent header, which loaded remote code in Log4j 2 before 2.15 (later fixes went further). Spring4Shell, CVE-2022-22965, allowed remote code execution through data binding in Spring MVC on JDK 9 and later when deployed as a WAR on Tomcat. In both cases the application code was fine; the libraries were not.

The control is process, not a code change: dependency scanning in CI that fails on critical CVEs, automated update pull requests, a platform BOM so teams upgrade Spring Boot in one place, and an SBOM so that when the next one lands we know within an hour which services are affected.

6SSRF: A URL Fetch Reaching Internal Endpoints

Server-side request forgery happens when our server fetches a URL chosen by the user, for example to import an avatar or preview a link. The attacker supplies an internal address, such as http://169.254.169.254/latest/meta-data/ on a cloud VM, and our server fetches cloud credentials on their behalf, or reaches internal admin services that trust the network.

Java
// Vulnerable: fetches whatever the user sends
byte[] img = restClient.get().uri(userUrl).retrieve().body(byte[].class);
// Safer: allowlist hosts, resolve once, reject private and link-local addresses
URI uri = URI.create(userUrl);
if (!"https".equals(uri.getScheme()) || !ALLOWED_HOSTS.contains(uri.getHost()))
throw new BadRequest("host not allowed");
InetAddress addr = InetAddress.getByName(uri.getHost());
if (addr.isLoopbackAddress() || addr.isSiteLocalAddress() || addr.isLinkLocalAddress())
throw new BadRequest("internal address"); // 169.254.169.254 is link-local

Notice that we check the resolved address, not only the host name, because a public name can resolve to an internal IP. For strong protection we also disable redirects, connect to the address we checked, and block metadata access at the network level, for example by requiring IMDSv2 on AWS.

7Follow-up questions

Why return 404 instead of 403 for another user's order?

A 403 confirms that the order exists, which lets an attacker enumerate valid ids. Returning 404 for anything the caller may not see leaks nothing. Some APIs prefer 403 for clarity; the important part is consistency and that no data is returned.

Is CSRF still in the Top 10?

CSRF is not a separate category in the 2021 list; it falls under broken access control. Spring Security enables CSRF protection by default for session-based applications, and stateless APIs using bearer tokens in headers usually do not need it.

8Conclusion

In this answer, we mapped five OWASP Top 10 2021 categories onto a Spring Boot service. Broken access control showed up as an IDOR fixed with ownership in the query, cryptographic failures as SHA-256 passwords fixed with bcrypt or Argon2 and TLS, injection as concatenated JPQL fixed with bind parameters, vulnerable components as Log4Shell and Spring4Shell handled by scanning and patching, and SSRF as a URL fetch reaching the metadata endpoint, fixed with an allowlist and blocking of internal addresses.

What to say in the interviewAbout 90 seconds aloud

Open with

I will use the 2021 edition. First, broken access control: an endpoint like GET /orders/{id} that loads by id without checking the owner, so any logged-in user can read anyone's order.

Then, if they want more

I fix it by putting the owner into the query, findByIdAndCustomerId with the id from the token, and returning 404 when it does not match; method security is an alternative. Second, cryptographic failures: storing passwords as SHA-256, which GPUs crack quickly. I use Spring Security's delegating encoder with bcrypt or Argon2, and TLS for every connection including the database.

Third, injection: JPQL built by concatenating a search value, where a quote lets the caller rewrite the query. The fix is a named bind parameter. Fourth, vulnerable and outdated components: Log4Shell, CVE-2021-44228, and Spring4Shell, CVE-2022-22965, where our code was fine but the libraries let attackers run code.

The control is dependency scanning in CI, automated updates, a central BOM and an SBOM so we know where to patch within an hour. Fifth, SSRF: an import-from-URL feature where someone passes 169.254.169.254 and our server fetches cloud credentials.

I allowlist destination hosts, check the resolved address and reject loopback, private and link-local ranges, disable redirects, and block metadata access in the network too. I would also mention that OWASP updates the list, so I would check the latest edition.

About this answer

Last updated
12 November 2026
Versions it names
Java 9
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 "Pick five categories from the OWASP Top 10 (for example the 2021 edition; check for the...": https://scrivio-interview-library.netlify.app/spring-boot/web-security-threats/40a148934e/