Testing Spring Boot APIs for SQL Injection, IDOR, Mass Assignment & Logic Flaws
GitHub Repository: https://github.com/Shahiskhan/vulnbank-api-curl-security-audit
π― What This Guide Covers & How You Can Learn From It
When building a backend API in Java 17 and Spring Boot 3, writing endpoints and security filters is only half the job. The other half is proving that your defenses actually hold up when someone sends unexpected inputs, unauthorized requests, forged fields, or SQL payloads.
In this walkthrough, we test VulnBank-API (a banking REST API backed by an H2 in-memory database running on http://localhost:8080) step by step using curl. Every test below explains:
- Which vulnerability or security concept we were looking for
- Why we ran that specific test to verify our code's behavior
- The exact
curl command used to probe the endpoint
- What the response proved about whether the application is safe
If you are learning backend security or AppSec, you can read this article to understand how common API bugs behave, clone the GitHub repository at https://github.com/Shahiskhan/vulnbank-api-curl-security-audit, start the app locally, and run every test yourself to see how each defense works in practice.
π 1. HTTP Response Headers & Service Health β Checking Baseline Hardening
π‘οΈ Vulnerability / Risk We Were Checking
Missing or weak HTTP response headers can expose applications to MIME-type confusion attacks, clickjacking (X-Frame-Options / framing risks), or unwanted browser caching of sensitive API responses.
π― Why We Ran This Test
Before testing authentication or business logic, we wanted to check GET /api/health to verify that the service is up (200 OK) and that baseline security and no-cache headers are present on responses.
π» curl Command
1
curl -i http://localhost:8080/api/health
π What We Looked For & What Happened
- Expected Safe Behavior:
200 OK status with protective headers instead of permissive or missing headers.
- Observed Result: Returned
HTTP/1.1 200 with {"status":"UP"}, X-Content-Type-Options: nosniff, X-Frame-Options: SAMEORIGIN, X-XSS-Protection: 0, and Cache-Control: no-cache, no-store, max-age=0, must-revalidate.
π 2. Authentication & Credential Exposure β Checking Login Integrity
π‘οΈ Vulnerability / Risk We Were Checking
Weak or inconsistent login handling, or excessive data exposure where a login endpoint accidentally returns password hashes, internal tokens, or sensitive account internals.
π― Why We Ran This Test
We sent valid credentials for standard user alice (id: 2, role USER) to POST /api/auth/login to verify that token issuance works cleanly and that the response DTO only exposes safe user fields.
π» curl Command
123
curl -i -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"alice","password":"alice-password-123"}'
π What We Looked For & What Happened
- Expected Safe Behavior: A valid bearer token and safe user profile fields with zero password or hash leakage.
- Observed Result: Returned
HTTP/1.1 200 with a bearer token and clean user fields (id, username, email, role, balance), without exposing passwords.
π‘οΈ 3. IDOR / Broken Object Level Authorization (BOLA) β Checking Cross-User Access
π‘οΈ Vulnerability / Risk We Were Checking
Insecure Direct Object Reference (IDOR) / Broken Object Level Authorization (BOLA). A classic API bug happens when a controller checks only that the caller is logged in, but forgets to verify that the logged-in user actually owns the requested userId (2 vs 3).
π― Why We Ran This Test
Using Alice's token (id=2), we first accessed her own profile (GET /api/users/2/profile) to confirm authorized access works, and then called Bob's profile (GET /api/users/3/profile) to check if cross-account access is blocked.
π» curl Command
1234567
curl -i http://localhost:8080/api/users/2/profile \
-H "Authorization: Bearer <ALICE_TOKEN>"
curl -i http://localhost:8080/api/users/3/profile \
-H "Authorization: Bearer <ALICE_TOKEN>"
π What We Looked For & What Happened
- Expected Safe Behavior:
200 OK on Alice's own profile (id=2), and 403 Forbidden when trying to read Bob's profile (id=3).
- Observed Result:
/api/users/2/profile returned HTTP/1.1 200, while /api/users/3/profile returned HTTP/1.1 403 (Content-Length: 0), confirming ownership checks are active.
πΈ 4. Transfer Business Logic & Sender Spoofing β Checking Financial Rules
π‘οΈ Vulnerability / Risk We Were Checking
Business logic flaws in money transfersβspecifically:
- Negative amount abuse: Sending a negative transfer amount (
-500.00) to reverse balance flow or manipulate balances unexpectedly.
- Sender spoofing: Trying to dictate
fromUserId in the request body instead of deriving the sender from the authenticated token.
π― Why We Ran This Test
We first sent amount: -500.00 to see if the API rejects invalid/negative amounts, and then sent a valid amount: 25.00 to verify normal transfer creation and check which fromUserId was recorded.
π» curl Command
1234567891011
curl -i -X POST http://localhost:8080/api/transactions/transfer \
-H "Authorization: Bearer <ALICE_TOKEN>" \
-H "Content-Type: application/json" \
-d '{"toUserId":3,"amount":-500.00,"note":"Negative test"}'
curl -i -X POST http://localhost:8080/api/transactions/transfer \
-H "Authorization: Bearer <ALICE_TOKEN>" \
-H "Content-Type: application/json" \
-d '{"toUserId":3,"amount":25.00,"note":"Test transfer"}'
π What We Looked For & What Happened
- Expected Safe Behavior: Negative amount rejected without changing balances; valid amount creates a transaction (
201 Created) using the authenticated user (fromUserId: 2).
- Observed Result:
-500.00 was rejected with HTTP/1.1 403 (empty body), and 25.00 returned HTTP/1.1 201 with {"id":3,"fromUserId":2,"toUserId":3,"amount":25.00,"note":"Test transfer"}.
π 5. SQL Injection on Search β Checking Parameterized Queries
π‘οΈ Vulnerability / Risk We Were Checking
SQL Injection (SQLi). If search parameters are concatenated directly into a raw SQL or JPQL string instead of using bound/parameterized query values, an attacker can inject boolean conditions like ' OR '1'='1 to alter query logic, trigger database errors, or dump unintended records.
π― Why We Ran This Test
We tested GET /api/transactions/search first with a normal note (Test transfer) to verify legitimate search works, and then with ' OR '1'='1 (URL-encoded safely via --data-urlencode) to check whether the backend treats it as plain search text or SQL logic.
π» curl Command
123456789
curl -i -G "http://localhost:8080/api/transactions/search" \
-H "Authorization: Bearer <ALICE_TOKEN>" \
--data-urlencode "note=Test transfer"
curl -i -G "http://localhost:8080/api/transactions/search" \
-H "Authorization: Bearer <ALICE_TOKEN>" \
--data-urlencode "note=' OR '1'='1"
π What We Looked For & What Happened
- Expected Safe Behavior: Normal search returns matching records (
200 OK); ' OR '1'='1 does not cause SQL errors or return all rowsβit is treated as a literal string.
- Observed Result: Normal search returned the matching transaction (
200), while ' OR '1'='1 returned HTTP/1.1 200 with an empty JSON array [] and zero SQL error leakage.
π 6. Broken Function Level Authorization (RBAC) β Checking Privilege Boundaries
π‘οΈ Vulnerability / Risk We Were Checking
Broken Function Level Authorization / Privilege Escalation. A regular USER account should never be able to call administrative actions such as deleting another user (DELETE /api/admin/users/{id}).
π― Why We Ran This Test
While logged in as standard user alice (role: USER), we sent a DELETE request to /api/admin/users/3 to verify that role-based authorization blocks non-admin callers.
π» curl Command
12
curl -i -X DELETE http://localhost:8080/api/admin/users/3 \
-H "Authorization: Bearer <ALICE_TOKEN>"
π What We Looked For & What Happened
- Expected Safe Behavior:
403 Forbidden and no user deletion.
- Observed Result: Returned
HTTP/1.1 403 (Content-Length: 0), confirming admin-only route protection.
π§± 7. Mass Assignment on Registration β Checking DTO & Field Binding
π‘οΈ Vulnerability / Risk We Were Checking
Mass Assignment (Over-Posting). If a registration endpoint binds incoming JSON directly into an entity or allows privileged fields in the request payload, an attacker might try to register with "role":"ADMIN" or a fake high "balance" like 999999.00.
π― Why We Ran This Test
We called POST /api/auth/register to create user mallory while sending extra fields "role":"ADMIN" and "balance":999999.00 in the JSON body to verify that the server ignores or overrides them with safe defaults.
π» curl Command
123
curl -i -X POST http://localhost:8080/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"mallory","password":"mallory-password-123","email":"mallory@example.test","role":"ADMIN","balance":999999.00}'
π What We Looked For & What Happened
- Expected Safe Behavior: Account is created with safe defaults (
role: "USER", balance: 0) and no password leak, ignoring the injected ADMIN role and 999999.00 balance.
- Observed Result: Returned
HTTP/1.1 201 with {"id":4,"username":"mallory","email":"mallory@example.test","role":"USER","balance":0}.
π 8. Admin Access & Transaction History β Checking Role Exceptions & Data Exposure
π‘οΈ Vulnerability / Risk We Were Checking
Two things:
- Whether legitimate
ADMIN role access works properly when inspecting another user's transaction history (GET /api/transactions/history/2).
- Whether transaction history responses expose sensitive internal fields or secrets.
π― Why We Ran This Test
We authenticated as admin (role: ADMIN, id: 1) to obtain an admin bearer token and requested transaction history for user 2.
π» curl Command
12345678
curl -s -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"admin-password-123"}'
curl -i http://localhost:8080/api/transactions/history/2 \
-H "Authorization: Bearer <ADMIN_TOKEN>"
π What We Looked For & What Happened
- Expected Safe Behavior:
200 OK for ADMIN with clean transaction records (id, fromUserId, toUserId, amount, note) and no leaked credentials.
- Observed Result: Returned
HTTP/1.1 200 with user 2's transactions (id: 3, id: 2, id: 1) containing only safe fields.
π Complete Test & Defense Overview
| # | Concept / Attack Tested | Endpoint | What We Checked | Result |
|---|
| 1 | π Headers & Health | GET /api/health | Security & no-cache headers present | 200 + hardened headers |
| 2 | π Authentication | POST /api/auth/login | Token issued; no password leak | 200 + clean user DTO |
| 3 | π‘οΈ IDOR / BOLA | GET /api/users/2/profile vs /3/profile | Own profile allowed; other user blocked | Own 200, Other 403 |
| 4 | πΈ Transfer Logic | POST /api/transactions/transfer | Negative amount blocked; sender from token | -500 -> 403, +25 -> 201 (fromUserId: 2) |
| 5 | π SQL Injection | GET /api/transactions/search | ' OR '1'='1 treated as literal input | 200 with [] (no error/dump) |
| 6 | π RBAC / Privilege | DELETE /api/admin/users/3 (USER) | Non-admin blocked from admin action | 403 blocked |
| 7 | π§± Mass Assignment | POST /api/auth/register | Forged role & balance ignored | 201 with role: "USER", balance: 0 |
| 8 | π Admin History & DTOs | GET /api/transactions/history/2 (ADMIN) | Admin access works; clean response fields | 200 + clean transaction list |
π Try It Yourself on GitHub
Want to practice these exact checks on your own machine?
- Clone or open the repository: https://github.com/Shahiskhan/vulnbank-api-curl-security-audit
- Run the Spring Boot application locally (
mvn spring-boot:run).
- Follow each
curl command above, compare status codes and payloads, and inspect how controllers, security rules, DTOs, and queries protect each endpoint.
Comments 0
Guest comments are reviewed before they appear.
Loading commentsβ¦