cyberaudit-skill 3.0.6 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/cyberaudit/COMMANDS.md +16 -1
- package/skills/cyberaudit/SKILL.md +38 -2
- package/skills/cyberaudit/api/API-CHECKLIST.md +102 -0
- package/skills/cyberaudit/api/API-PHILOSOPHY.md +121 -0
- package/skills/cyberaudit/api/API-REMEDIATION-LIBRARY.md +149 -0
- package/skills/cyberaudit/api/types/GRAPHQL.md +82 -0
- package/skills/cyberaudit/api/types/REST.md +71 -0
- package/skills/cyberaudit/api/types/WEBSOCKET.md +75 -0
- package/skills/cyberaudit/api/vulnerabilities/BOLA.md +41 -0
- package/skills/cyberaudit/api/vulnerabilities/BOPLA.md +38 -0
- package/skills/cyberaudit/api/vulnerabilities/INVENTORY.md +47 -0
- package/skills/cyberaudit/api/vulnerabilities/RATE-LIMITING.md +66 -0
- package/skills/cyberaudit/api/vulnerabilities/THIRD-PARTY-API.md +57 -0
- package/skills/cyberaudit/reports/REPORT-TEMPLATE-API.md +89 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cyberaudit-skill",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"description": "Universal security audit skill for AI agents. Install once, audit any web or mobile app. OpenCode, Claude Code, Cursor, Kiro, Gemini — all supported.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -56,6 +56,21 @@ When user types `/cyberaudit` or `/audit` — **list all commands below**.
|
|
|
56
56
|
| `/audit:ionic` | Ionic audit |
|
|
57
57
|
| `/audit:expo` | Expo audit |
|
|
58
58
|
|
|
59
|
+
## API
|
|
60
|
+
|
|
61
|
+
| Command | Action |
|
|
62
|
+
|---|---|
|
|
63
|
+
| `/audit:api` | Full API audit (OWASP API Top 10) |
|
|
64
|
+
| `/audit:auth-api` | API authentication & authorization |
|
|
65
|
+
| `/audit:api:rest` | REST API audit |
|
|
66
|
+
| `/audit:api:graphql` | GraphQL API audit |
|
|
67
|
+
| `/audit:api:ws` | WebSocket API audit |
|
|
68
|
+
| `/audit:api:bola` | BOLA/IDOR audit |
|
|
69
|
+
| `/audit:api:bopla` | BOPLA (BFLA) audit |
|
|
70
|
+
| `/audit:api:rate-limit` | Rate limiting audit |
|
|
71
|
+
| `/audit:api:inventory` | API inventory/discovery |
|
|
72
|
+
| `/audit:api:third-party` | Third-party API audit |
|
|
73
|
+
|
|
59
74
|
## Compliance
|
|
60
75
|
|
|
61
76
|
| Command | Action |
|
|
@@ -68,4 +83,4 @@ When user types `/cyberaudit` or `/audit` — **list all commands below**.
|
|
|
68
83
|
|
|
69
84
|
## Execution
|
|
70
85
|
|
|
71
|
-
For any `/audit:xxx` command, load the corresponding files from `web/`, `mobile/`, or `reports/`, then execute the audit methodology from `SKILL.md`.
|
|
86
|
+
For any `/audit:xxx` command, load the corresponding files from `web/`, `mobile/`, `api/`, or `reports/`, then execute the audit methodology from `SKILL.md`.
|
|
@@ -70,6 +70,20 @@ Security audit intelligence for AI agents. Universal, framework-agnostic, method
|
|
|
70
70
|
| `/audit:ionic` | Ionic audit |
|
|
71
71
|
| `/audit:expo` | Expo audit |
|
|
72
72
|
|
|
73
|
+
### API
|
|
74
|
+
| Command | Action |
|
|
75
|
+
|---|---|
|
|
76
|
+
| `/audit:api` | Full API audit (OWASP API Top 10) |
|
|
77
|
+
| `/audit:auth-api` | API authentication & authorization |
|
|
78
|
+
| `/audit:api:rest` | REST API audit |
|
|
79
|
+
| `/audit:api:graphql` | GraphQL API audit |
|
|
80
|
+
| `/audit:api:ws` | WebSocket API audit |
|
|
81
|
+
| `/audit:api:bola` | BOLA/IDOR audit |
|
|
82
|
+
| `/audit:api:bopla` | BOPLA (BFLA) audit |
|
|
83
|
+
| `/audit:api:rate-limit` | Rate limiting audit |
|
|
84
|
+
| `/audit:api:inventory` | API inventory/discovery |
|
|
85
|
+
| `/audit:api:third-party` | Third-party API audit |
|
|
86
|
+
|
|
73
87
|
### Compliance
|
|
74
88
|
| Command | Action |
|
|
75
89
|
|---|---|
|
|
@@ -84,7 +98,7 @@ Security audit intelligence for AI agents. Universal, framework-agnostic, method
|
|
|
84
98
|
Execute on every audit request:
|
|
85
99
|
|
|
86
100
|
**STEP 1 — IDENTIFICATION** (30 sec)
|
|
87
|
-
- TYPE → Web / Mobile / Both
|
|
101
|
+
- TYPE → Web / Mobile / API / Both
|
|
88
102
|
- FRAMEWORK → Identify precisely (React, Laravel, Flutter, etc.)
|
|
89
103
|
- CONTEXT → Dev / Staging / Production
|
|
90
104
|
- SCOPE → Entire code / Single module
|
|
@@ -93,6 +107,7 @@ Execute on every audit request:
|
|
|
93
107
|
**STEP 2 — MODE LOADING**
|
|
94
108
|
- Web → Load web checklist + framework-specific guide
|
|
95
109
|
- Mobile → Load mobile checklist + framework-specific guide
|
|
110
|
+
- API → Load API checklist + type-specific guide (REST/GraphQL/WebSocket)
|
|
96
111
|
|
|
97
112
|
**STEP 3 — STRUCTURED AUDIT**
|
|
98
113
|
Follow the loaded philosophy. Never skip a phase. Document each finding immediately.
|
|
@@ -178,6 +193,11 @@ Every report must include:
|
|
|
178
193
|
- **Express**: CORS, helmet, input validation, error handling
|
|
179
194
|
- **NestJS**: Guards, pipes, serialization, GraphQL security
|
|
180
195
|
|
|
196
|
+
### API Types
|
|
197
|
+
- **REST**: Resource IDOR/BOLA, mass assignment, parameter injection, deprecated endpoints
|
|
198
|
+
- **GraphQL**: Introspection, depth/complexity, batching attacks, field-level auth
|
|
199
|
+
- **WebSocket**: Authentication on connect, per-message auth, origin validation, rate limiting
|
|
200
|
+
|
|
181
201
|
### Mobile Frameworks
|
|
182
202
|
- **React Native**: AsyncStorage, deep links, WebView XSS, JS bundle exposure
|
|
183
203
|
- **Flutter**: Method channels, root detection, local storage, obfuscation
|
|
@@ -217,9 +237,24 @@ This skill lives at `~/.skills/cyberaudit/`. Additional sub-skills:
|
|
|
217
237
|
├── MASTER.md (full vulnerability taxonomy + scoring)
|
|
218
238
|
├── USAGE-GUIDE.md (user-facing documentation)
|
|
219
239
|
├── README.md (project overview)
|
|
240
|
+
├── api/
|
|
241
|
+
│ ├── API-PHILOSOPHY.md
|
|
242
|
+
│ ├── API-CHECKLIST.md
|
|
243
|
+
│ ├── API-REMEDIATION-LIBRARY.md
|
|
244
|
+
│ ├── types/
|
|
245
|
+
│ │ ├── REST.md
|
|
246
|
+
│ │ ├── GRAPHQL.md
|
|
247
|
+
│ │ └── WEBSOCKET.md
|
|
248
|
+
│ └── vulnerabilities/
|
|
249
|
+
│ ├── BOLA.md
|
|
250
|
+
│ ├── BOPLA.md
|
|
251
|
+
│ ├── RATE-LIMITING.md
|
|
252
|
+
│ ├── INVENTORY.md
|
|
253
|
+
│ └── THIRD-PARTY-API.md
|
|
220
254
|
├── reports/
|
|
221
255
|
│ ├── REPORT-TEMPLATE-WEB.md
|
|
222
256
|
│ ├── REPORT-TEMPLATE-MOBILE.md
|
|
257
|
+
│ ├── REPORT-TEMPLATE-API.md
|
|
223
258
|
│ └── EXECUTIVE-SUMMARY-TEMPLATE.md
|
|
224
259
|
├── shared/
|
|
225
260
|
│ ├── COMPLIANCE.md
|
|
@@ -254,7 +289,8 @@ This skill lives at `~/.skills/cyberaudit/`. Additional sub-skills:
|
|
|
254
289
|
```
|
|
255
290
|
|
|
256
291
|
For detailed framework-specific checks, load the appropriate file from `web/frameworks/` or `mobile/frameworks/`.
|
|
257
|
-
For vulnerability-specific deep dives, load from `web/vulnerabilities
|
|
292
|
+
For vulnerability-specific deep dives, load from `web/vulnerabilities/`, `mobile/vulnerabilities/`, or `api/vulnerabilities/`.
|
|
293
|
+
For API-specific audits, load from `api/` (philosophy, checklist, type guide, remediation library).
|
|
258
294
|
|
|
259
295
|
---
|
|
260
296
|
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# API SECURITY CHECKLIST — CyberAudit Skill
|
|
2
|
+
|
|
3
|
+
## Phase 0 — Discovery
|
|
4
|
+
|
|
5
|
+
- [ ] All endpoints documented and audited
|
|
6
|
+
- [ ] Shadow/deprecated endpoints identified
|
|
7
|
+
- [ ] Auth mechanism identified per endpoint
|
|
8
|
+
- [ ] All HTTP methods tested on each endpoint
|
|
9
|
+
- [ ] Parameter variations tested
|
|
10
|
+
- [ ] Content-type variations tested
|
|
11
|
+
|
|
12
|
+
## Phase 1 — Authentication
|
|
13
|
+
|
|
14
|
+
- [ ] JWT signature verified (not just decoded)
|
|
15
|
+
- [ ] JWT `alg` restricted (no "none" algorithm)
|
|
16
|
+
- [ ] JWT expiration enforced server-side
|
|
17
|
+
- [ ] JWT secret strong and rotated
|
|
18
|
+
- [ ] OAuth redirect_uri validated
|
|
19
|
+
- [ ] OAuth state parameter used
|
|
20
|
+
- [ ] API keys not exposed in URLs
|
|
21
|
+
- [ ] API keys revocable
|
|
22
|
+
- [ ] API keys scoped to minimum permissions
|
|
23
|
+
- [ ] No hardcoded credentials in code
|
|
24
|
+
- [ ] Multi-factor authentication available
|
|
25
|
+
- [ ] Password hashing: bcrypt/argon2
|
|
26
|
+
|
|
27
|
+
## Phase 2 — Authorization
|
|
28
|
+
|
|
29
|
+
- [ ] IDOR test on every object endpoint
|
|
30
|
+
- [ ] BFLA test on every admin function
|
|
31
|
+
- [ ] Role-based access control enforced
|
|
32
|
+
- [ ] Mass assignment protected
|
|
33
|
+
- [ ] UUIDs used instead of sequential IDs
|
|
34
|
+
- [ ] Object ownership verified server-side
|
|
35
|
+
- [ ] Vertical privilege escalation tested
|
|
36
|
+
- [ ] Horizontal privilege escalation tested
|
|
37
|
+
- [ ] Indirect object reference checked
|
|
38
|
+
|
|
39
|
+
## Phase 3 — Input Validation
|
|
40
|
+
|
|
41
|
+
- [ ] SQL injection: parameterized queries
|
|
42
|
+
- [ ] NoSQL injection: sanitize operators
|
|
43
|
+
- [ ] Command injection: avoid exec() with input
|
|
44
|
+
- [ ] XML injection: disable external entities
|
|
45
|
+
- [ ] SSRF: validate redirect URLs
|
|
46
|
+
- [ ] Path traversal: restrict file access
|
|
47
|
+
- [ ] Parameter pollution: last value wins?
|
|
48
|
+
- [ ] Schema validation bypass: extra fields
|
|
49
|
+
- [ ] Content-type confusion: application/json vs XML
|
|
50
|
+
- [ ] GraphQL: depth limiting
|
|
51
|
+
- [ ] GraphQL: query complexity limiting
|
|
52
|
+
- [ ] GraphQL: disable introspection in production
|
|
53
|
+
|
|
54
|
+
## Phase 4 — Rate Limiting
|
|
55
|
+
|
|
56
|
+
- [ ] Rate limiting on ALL endpoints
|
|
57
|
+
- [ ] Stricter limits on auth endpoints
|
|
58
|
+
- [ ] Rate limiting by user/IP/token
|
|
59
|
+
- [ ] Proper 429 response with Retry-After
|
|
60
|
+
- [ ] Brute force protection on login
|
|
61
|
+
- [ ] Enumeration prevention (consistent messages)
|
|
62
|
+
- [ ] Pagination has max limit
|
|
63
|
+
- [ ] Pagination cursor-based for sensitive data
|
|
64
|
+
- [ ] Resource usage monitoring
|
|
65
|
+
|
|
66
|
+
## Phase 5 — Data Exposure
|
|
67
|
+
|
|
68
|
+
- [ ] Responses contain minimum data
|
|
69
|
+
- [ ] No sensitive data in error messages
|
|
70
|
+
- [ ] No stack traces in production
|
|
71
|
+
- [ ] No debug endpoints exposed
|
|
72
|
+
- [ ] Logging excludes sensitive fields
|
|
73
|
+
- [ ] PII exposure audited per endpoint
|
|
74
|
+
- [ ] Consistent response format (no info leak)
|
|
75
|
+
- [ ] CORS whitelist restrictive
|
|
76
|
+
- [ ] CORS credentials: true without wildcard origin
|
|
77
|
+
- [ ] Security headers: CSP, HSTS, X-Frame, etc.
|
|
78
|
+
|
|
79
|
+
## Phase 6 — WebSocket Security
|
|
80
|
+
|
|
81
|
+
- [ ] WSS enforced (no unencrypted WS)
|
|
82
|
+
- [ ] Authentication on connect
|
|
83
|
+
- [ ] Authorization per message
|
|
84
|
+
- [ ] Input validation per message
|
|
85
|
+
- [ ] Rate limiting per connection
|
|
86
|
+
- [ ] Message size limits
|
|
87
|
+
- [ ] Origin validation
|
|
88
|
+
- [ ] Connection timeout
|
|
89
|
+
- [ ] Reconnection not automatic for sensitive actions
|
|
90
|
+
|
|
91
|
+
## Phase 7 — Third-Party APIs
|
|
92
|
+
|
|
93
|
+
- [ ] Outgoing HTTPS enforced
|
|
94
|
+
- [ ] Certificate validation (no self-signed skip)
|
|
95
|
+
- [ ] Timeout configured
|
|
96
|
+
- [ ] Retry logic with backoff
|
|
97
|
+
- [ ] Webhook signature verified
|
|
98
|
+
- [ ] Third-party data treated as untrusted
|
|
99
|
+
- [ ] Third-party credentials stored securely
|
|
100
|
+
- [ ] Third-party API key rotation
|
|
101
|
+
- [ ] Webhook payload validation
|
|
102
|
+
- [ ] IP allowlisting where possible
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# API AUDIT PHILOSOPHY — CyberAudit Skill
|
|
2
|
+
# The mindset of an API security expert
|
|
3
|
+
|
|
4
|
+
## The API Mental DNA
|
|
5
|
+
|
|
6
|
+
An API is not a website with less HTML.
|
|
7
|
+
It is a bare attack surface, no interface,
|
|
8
|
+
no friction, accessible by machines
|
|
9
|
+
that can send thousands of requests per second.
|
|
10
|
+
|
|
11
|
+
When you audit an API, think like
|
|
12
|
+
an attacker who read the entire documentation
|
|
13
|
+
AND is looking for what the documentation does not say.
|
|
14
|
+
|
|
15
|
+
Modern APIs have three unique characteristics
|
|
16
|
+
that make them particularly dangerous:
|
|
17
|
+
|
|
18
|
+
1. THEY TRUST BY DESIGN
|
|
19
|
+
An API is built to be consumed.
|
|
20
|
+
Its nature is to accept requests.
|
|
21
|
+
The challenge: distinguish legitimate requests
|
|
22
|
+
from malicious ones.
|
|
23
|
+
|
|
24
|
+
2. THEY EXPOSE BUSINESS LOGIC DIRECTLY
|
|
25
|
+
No UI to hide functionality.
|
|
26
|
+
Every endpoint is an exposed business function.
|
|
27
|
+
An attacker reading your docs sees your architecture.
|
|
28
|
+
|
|
29
|
+
3. THEY ARE DESIGNED FOR AUTOMATION
|
|
30
|
+
What is a feature for developers
|
|
31
|
+
is a weapon for attackers.
|
|
32
|
+
A script can test 10,000 IDs in 10 seconds.
|
|
33
|
+
|
|
34
|
+
## The 8 Truths of API Security
|
|
35
|
+
|
|
36
|
+
TRUTH 1 — THE OBJECT IS THE ATTACK UNIT
|
|
37
|
+
On the web, you attack pages.
|
|
38
|
+
On an API, you attack objects.
|
|
39
|
+
GET /users/1 → GET /users/2 → GET /users/3...
|
|
40
|
+
IDOR is the #1 vulnerability in APIs.
|
|
41
|
+
Every endpoint with an ID is an attack vector.
|
|
42
|
+
|
|
43
|
+
TRUTH 2 — AUTHENTICATION ≠ AUTHORIZATION
|
|
44
|
+
An API can perfectly authenticate a user
|
|
45
|
+
and still give them access to everyone else's data.
|
|
46
|
+
Valid token ≠ authorized access to this resource.
|
|
47
|
+
|
|
48
|
+
TRUTH 3 — EVERYTHING IS AN INPUT
|
|
49
|
+
Headers, query params, body, cookies, files.
|
|
50
|
+
An API trusts what it receives.
|
|
51
|
+
Validation must happen at every boundary.
|
|
52
|
+
|
|
53
|
+
TRUTH 4 — RATE LIMITING IS SECURITY
|
|
54
|
+
Without rate limiting, an API is defenseless.
|
|
55
|
+
Brute force, enumeration, DDoS — all prevented
|
|
56
|
+
by a simple rate limit.
|
|
57
|
+
|
|
58
|
+
TRUTH 5 — THE DOCUMENTATION IS AN ATTACK PLAN
|
|
59
|
+
Your OpenAPI spec tells attackers exactly
|
|
60
|
+
where to look. Every endpoint described
|
|
61
|
+
is an endpoint tested.
|
|
62
|
+
|
|
63
|
+
TRUTH 6 — INTERNAL APIS ARE NOT SAFE
|
|
64
|
+
"Internal only" means no WAF, no rate limiting,
|
|
65
|
+
no auth, no monitoring. Internal APIs are
|
|
66
|
+
the most vulnerable.
|
|
67
|
+
|
|
68
|
+
TRUTH 7 — LEGACY ENDPOINTS ARE BACKDOORS
|
|
69
|
+
/v1/users, /api/old/orders, deprecated routes
|
|
70
|
+
that were forgotten. They still work.
|
|
71
|
+
They have weaker security.
|
|
72
|
+
|
|
73
|
+
TRUTH 8 — THIRD-PARTY APIS ARE YOUR LIABILITY
|
|
74
|
+
The API you consume can be compromised.
|
|
75
|
+
The API you expose can be abused by partners.
|
|
76
|
+
Trust must be verified, not assumed.
|
|
77
|
+
|
|
78
|
+
## The API Audit Flow
|
|
79
|
+
|
|
80
|
+
PHASE 0 — DISCOVERY & MAPPING
|
|
81
|
+
□ List ALL endpoints (documented + undocumented)
|
|
82
|
+
□ Identify auth mechanisms per endpoint
|
|
83
|
+
□ Map data types and sensitivity
|
|
84
|
+
□ Find shadow APIs and deprecated endpoints
|
|
85
|
+
□ Test every HTTP method on every endpoint
|
|
86
|
+
|
|
87
|
+
PHASE 1 — AUTHENTICATION
|
|
88
|
+
□ Token handling (JWT, OAuth, API keys)
|
|
89
|
+
□ Token validation on every endpoint
|
|
90
|
+
□ Token expiration and rotation
|
|
91
|
+
□ Weak authentication mechanisms
|
|
92
|
+
|
|
93
|
+
PHASE 2 — AUTHORIZATION
|
|
94
|
+
□ IDOR/BOLA on every object access
|
|
95
|
+
□ BFLA on every admin function
|
|
96
|
+
□ Mass assignment protection
|
|
97
|
+
□ Role-based access control verification
|
|
98
|
+
|
|
99
|
+
PHASE 3 — INPUT VALIDATION
|
|
100
|
+
□ Injection testing on all inputs
|
|
101
|
+
□ Parameter pollution
|
|
102
|
+
□ Content-type validation
|
|
103
|
+
□ Schema validation bypass
|
|
104
|
+
|
|
105
|
+
PHASE 4 — RATE LIMITING & ABUSE
|
|
106
|
+
□ Brute force protection
|
|
107
|
+
□ Enumeration prevention
|
|
108
|
+
□ Pagination abuse
|
|
109
|
+
□ Resource exhaustion
|
|
110
|
+
|
|
111
|
+
PHASE 5 — DATA EXPOSURE
|
|
112
|
+
□ Over-fetching in responses
|
|
113
|
+
□ Sensitive data in error messages
|
|
114
|
+
□ Excessive data in list endpoints
|
|
115
|
+
□ Debug endpoints exposed
|
|
116
|
+
|
|
117
|
+
PHASE 6 — CONFIGURATION
|
|
118
|
+
□ CORS misconfiguration
|
|
119
|
+
□ TLS/SSL verification
|
|
120
|
+
□ Security headers
|
|
121
|
+
□ Debug mode disabled
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# API Remediation Library — CyberAudit Skill
|
|
2
|
+
|
|
3
|
+
## Authentication Fixes
|
|
4
|
+
|
|
5
|
+
### JWT Hardening
|
|
6
|
+
```javascript
|
|
7
|
+
// Secure JWT configuration
|
|
8
|
+
const jwt = require('jsonwebtoken');
|
|
9
|
+
const token = jwt.sign(
|
|
10
|
+
{ userId: user.id, role: user.role },
|
|
11
|
+
process.env.JWT_SECRET,
|
|
12
|
+
{ algorithm: 'HS256', expiresIn: '15m', issuer: 'myapp' }
|
|
13
|
+
);
|
|
14
|
+
```
|
|
15
|
+
- Disable 'none' algorithm
|
|
16
|
+
- Verify signature on every request
|
|
17
|
+
- Use short expiration (15-30 min)
|
|
18
|
+
- Implement refresh token rotation
|
|
19
|
+
|
|
20
|
+
### API Key Management
|
|
21
|
+
```javascript
|
|
22
|
+
// Hash keys before storing
|
|
23
|
+
const crypto = require('crypto');
|
|
24
|
+
const hash = crypto.createHash('sha256').update(rawKey).digest('hex');
|
|
25
|
+
db.apiKeys.create({ hash, userId, scopes: ['read:orders'] });
|
|
26
|
+
```
|
|
27
|
+
- Never store raw keys in database
|
|
28
|
+
- Prefix keys for identification (sk_live_xxx)
|
|
29
|
+
- Support key rotation without downtime
|
|
30
|
+
- Scope keys to minimum permissions
|
|
31
|
+
|
|
32
|
+
## Authorization Fixes
|
|
33
|
+
|
|
34
|
+
### Ownership Check Middleware
|
|
35
|
+
```javascript
|
|
36
|
+
function verifyOwnership(model) {
|
|
37
|
+
return async (req, res, next) => {
|
|
38
|
+
const resource = await model.findById(req.params.id);
|
|
39
|
+
if (!resource) return res.status(404).json({ error: 'Not found' });
|
|
40
|
+
if (resource.userId !== req.user.id && req.user.role !== 'admin') {
|
|
41
|
+
return res.status(403).json({ error: 'Forbidden' });
|
|
42
|
+
}
|
|
43
|
+
req.resource = resource;
|
|
44
|
+
next();
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Role-Based Access Control
|
|
50
|
+
```javascript
|
|
51
|
+
function authorize(...roles) {
|
|
52
|
+
return (req, res, next) => {
|
|
53
|
+
if (!roles.includes(req.user.role)) {
|
|
54
|
+
return res.status(403).json({ error: 'Insufficient permissions' });
|
|
55
|
+
}
|
|
56
|
+
next();
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// Usage: deleteUser -> authenticate, authorize('admin')
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Input Validation Fixes
|
|
63
|
+
|
|
64
|
+
### Schema Validation (Joi)
|
|
65
|
+
```javascript
|
|
66
|
+
const Joi = require('joi');
|
|
67
|
+
const schema = Joi.object({
|
|
68
|
+
name: Joi.string().min(2).max(100).required(),
|
|
69
|
+
email: Joi.string().email().required(),
|
|
70
|
+
role: Joi.string().valid('user', 'admin').default('user')
|
|
71
|
+
});
|
|
72
|
+
const { error, value } = schema.validate(req.body);
|
|
73
|
+
if (error) return res.status(400).json({ error: error.details[0].message });
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### SQL Injection Prevention
|
|
77
|
+
```javascript
|
|
78
|
+
// Always use parameterized queries
|
|
79
|
+
db.query('SELECT * FROM users WHERE id = $1', [userId]);
|
|
80
|
+
// Never: db.query(`SELECT * FROM users WHERE id = ${userId}`);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### NoSQL Injection Prevention
|
|
84
|
+
```javascript
|
|
85
|
+
// Sanitize operators before query
|
|
86
|
+
function sanitize(obj) {
|
|
87
|
+
if (typeof obj !== 'object') return obj;
|
|
88
|
+
delete obj.$where; delete obj.$ne; delete obj.$regex;
|
|
89
|
+
// ... remove other dangerous operators
|
|
90
|
+
}
|
|
91
|
+
db.collection('users').find(sanitize(query));
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Rate Limiting Fixes
|
|
95
|
+
|
|
96
|
+
### Express Rate Limit
|
|
97
|
+
```javascript
|
|
98
|
+
const rateLimit = require('express-rate-limit');
|
|
99
|
+
const loginLimiter = rateLimit({
|
|
100
|
+
windowMs: 15 * 60 * 1000, // 15 minutes
|
|
101
|
+
max: 5,
|
|
102
|
+
message: { error: 'Too many attempts, try again later' },
|
|
103
|
+
standardHeaders: true,
|
|
104
|
+
legacyHeaders: false
|
|
105
|
+
});
|
|
106
|
+
app.use('/api/auth/login', loginLimiter);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## WebSocket Fixes
|
|
110
|
+
|
|
111
|
+
### Authentication on Connect
|
|
112
|
+
```javascript
|
|
113
|
+
const WebSocket = require('ws');
|
|
114
|
+
const server = new WebSocket.Server({ port: 8080 });
|
|
115
|
+
server.on('connection', (socket, req) => {
|
|
116
|
+
const token = new URL(req.url, 'http://localhost').searchParams.get('token');
|
|
117
|
+
try {
|
|
118
|
+
const user = jwt.verify(token, process.env.JWT_SECRET);
|
|
119
|
+
socket.user = user; // Attach verified user
|
|
120
|
+
} catch {
|
|
121
|
+
socket.close(4001, 'Authentication failed');
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Per-Message Authorization
|
|
127
|
+
```javascript
|
|
128
|
+
socket.on('message', (data) => {
|
|
129
|
+
const msg = JSON.parse(data);
|
|
130
|
+
if (msg.action === 'deleteUser') {
|
|
131
|
+
if (!socket.user.isAdmin) {
|
|
132
|
+
socket.send(JSON.stringify({ error: 'Forbidden' }));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// Proceed with delete
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Security Headers
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
const helmet = require('helmet');
|
|
144
|
+
app.use(helmet({
|
|
145
|
+
contentSecurityPolicy: { directives: { defaultSrc: ["'self'"] } },
|
|
146
|
+
hsts: { maxAge: 31536000, includeSubDomains: true }
|
|
147
|
+
}));
|
|
148
|
+
app.disable('x-powered-by');
|
|
149
|
+
```
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# GraphQL API — Security Audit Guide
|
|
2
|
+
|
|
3
|
+
## Unique Risks
|
|
4
|
+
|
|
5
|
+
GraphQL changes the attack model fundamentally:
|
|
6
|
+
- Single endpoint, all operations
|
|
7
|
+
- Client decides what data to fetch
|
|
8
|
+
- Nested queries can cause DoS
|
|
9
|
+
- Introspection leaks the entire schema
|
|
10
|
+
|
|
11
|
+
## Vulnerability Patterns
|
|
12
|
+
|
|
13
|
+
### CRITICAL — Introspection Enabled
|
|
14
|
+
```graphql
|
|
15
|
+
query { __schema { types { name fields { name } } } }
|
|
16
|
+
```
|
|
17
|
+
An attacker gets your entire schema: all types, fields, mutations.
|
|
18
|
+
Fix: disable introspection in production.
|
|
19
|
+
|
|
20
|
+
### CRITICAL — No Depth Limiting
|
|
21
|
+
```graphql
|
|
22
|
+
query {
|
|
23
|
+
user { posts { comments { user { posts { comments { ... } } } } } }
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
Deeply nested queries can crash the server.
|
|
27
|
+
Fix: max depth limit (typically 5-7 levels).
|
|
28
|
+
|
|
29
|
+
### HIGH — No Query Complexity Analysis
|
|
30
|
+
Some queries are cheap (single field), some are expensive (list all).
|
|
31
|
+
```graphql
|
|
32
|
+
query { allUsers { posts { comments } } }
|
|
33
|
+
```
|
|
34
|
+
Fix: assign cost to each field, reject queries over limit.
|
|
35
|
+
|
|
36
|
+
### HIGH — Batching Attacks
|
|
37
|
+
```graphql
|
|
38
|
+
query {
|
|
39
|
+
u1: user(id: 1) { creditCard }
|
|
40
|
+
u2: user(id: 2) { creditCard }
|
|
41
|
+
# ... 500 more
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
Single query enumerates many records.
|
|
45
|
+
Fix: rate limit by query complexity, not just by request count.
|
|
46
|
+
|
|
47
|
+
### HIGH — Missing Authorization
|
|
48
|
+
GraphQL resolves fields independently. A field might be authorized at the query level but not at the nested resolver level.
|
|
49
|
+
```
|
|
50
|
+
User.orders → authorized in resolver ✓
|
|
51
|
+
User.orders[0].adminNotes → resolver forgets auth check ✗
|
|
52
|
+
```
|
|
53
|
+
Fix: authorize every resolver independently.
|
|
54
|
+
|
|
55
|
+
### MEDIUM — Field Suggestions
|
|
56
|
+
```
|
|
57
|
+
query { uesrs { name } }
|
|
58
|
+
# Response: "Did you mean 'users'?"
|
|
59
|
+
```
|
|
60
|
+
Suggestions leak valid field names.
|
|
61
|
+
Fix: disable suggestions in production.
|
|
62
|
+
|
|
63
|
+
### MEDIUM — Mutations Without Rate Limiting
|
|
64
|
+
Mutations modify data. Unchecked mutations allow:
|
|
65
|
+
- Mass account creation
|
|
66
|
+
- Mass password reset requests
|
|
67
|
+
- Rapid data modification
|
|
68
|
+
|
|
69
|
+
Fix: stricter rate limits on mutations vs queries.
|
|
70
|
+
|
|
71
|
+
## GraphQL-Specific Best Practices
|
|
72
|
+
|
|
73
|
+
1. Disable introspection in production
|
|
74
|
+
2. Implement query depth limiting
|
|
75
|
+
3. Implement query complexity analysis
|
|
76
|
+
4. Rate limit by query complexity, not count
|
|
77
|
+
5. Authorize every resolver independently
|
|
78
|
+
6. Disable field suggestions
|
|
79
|
+
7. Use persisted queries where possible
|
|
80
|
+
8. Limit batch request size
|
|
81
|
+
9. Validate all mutation inputs strictly
|
|
82
|
+
10. Monitor for abnormal query patterns
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# REST API — Security Audit Guide
|
|
2
|
+
|
|
3
|
+
## Threat Model
|
|
4
|
+
|
|
5
|
+
REST APIs are resource-oriented. Each endpoint maps to a CRUD operation on a resource. The attack surface is every URL + method combination.
|
|
6
|
+
|
|
7
|
+
## Vulnerability Patterns
|
|
8
|
+
|
|
9
|
+
### CRITICAL — IDOR/BOLA
|
|
10
|
+
Every resource access must verify ownership.
|
|
11
|
+
```
|
|
12
|
+
GET /api/orders/1 → verify order belongs to user
|
|
13
|
+
PUT /api/users/2/role → verify admin + ownership
|
|
14
|
+
```
|
|
15
|
+
Test: replace IDs sequentially, check access.
|
|
16
|
+
|
|
17
|
+
### CRITICAL — Mass Assignment
|
|
18
|
+
Extra fields in request body modify protected attributes.
|
|
19
|
+
```
|
|
20
|
+
POST /api/users
|
|
21
|
+
{ "name": "test", "role": "admin" } ← role should be ignored
|
|
22
|
+
```
|
|
23
|
+
Fix: whitelist allowed fields server-side.
|
|
24
|
+
|
|
25
|
+
### CRITICAL — Injection in Parameters
|
|
26
|
+
URL params, query strings, headers all carry injection risk.
|
|
27
|
+
```
|
|
28
|
+
GET /api/users?search=' OR 1=1 --
|
|
29
|
+
GET /api/users?sort=email; DROP TABLE users --
|
|
30
|
+
```
|
|
31
|
+
Fix: parameterized queries, input validation.
|
|
32
|
+
|
|
33
|
+
### HIGH — Authentication Bypass
|
|
34
|
+
```
|
|
35
|
+
GET /api/admin/users ← 401 Unauthorized
|
|
36
|
+
GET /api/admin/users?role=admin ← 200 OK (bypass via param)
|
|
37
|
+
```
|
|
38
|
+
Fix: auth middleware on route groups, not individual handlers.
|
|
39
|
+
|
|
40
|
+
### HIGH — Improper Asset Management
|
|
41
|
+
Deprecated endpoints still active:
|
|
42
|
+
```
|
|
43
|
+
GET /api/v1/users (current)
|
|
44
|
+
GET /api/v0/users (old, no auth)
|
|
45
|
+
```
|
|
46
|
+
Fix: decommission old versions, redirect with 410.
|
|
47
|
+
|
|
48
|
+
### MEDIUM — Excessive Data Exposure
|
|
49
|
+
```
|
|
50
|
+
GET /api/users returns:
|
|
51
|
+
{ "id": 1, "name": "John", "ssn": "123-45-6789", "password_hash": "$2a$..." }
|
|
52
|
+
```
|
|
53
|
+
Fix: Response DTOs, exclude sensitive fields.
|
|
54
|
+
|
|
55
|
+
### MEDIUM — Rate Limiting Absent
|
|
56
|
+
Without rate limiting:
|
|
57
|
+
- Brute force login: 1000 tries/min
|
|
58
|
+
- Enumeration: scan all user IDs
|
|
59
|
+
- DoS: flood expensive endpoints
|
|
60
|
+
|
|
61
|
+
Fix: rate limiting per user/IP/token.
|
|
62
|
+
|
|
63
|
+
## REST-Specific Best Practices
|
|
64
|
+
|
|
65
|
+
1. Use proper HTTP methods (GET read, POST create, PUT full update, PATCH partial)
|
|
66
|
+
2. Return proper status codes (401 unauth, 403 forbidden, 429 rate limit)
|
|
67
|
+
3. Validate Content-Type header (reject unexpected formats)
|
|
68
|
+
4. Never expose internal IDs in URLs if sequential
|
|
69
|
+
5. Use HATEOAS links carefully (don't leak endpoints)
|
|
70
|
+
6. Version your API properly (URL or header based)
|
|
71
|
+
7. Document all endpoints (but don't include security details)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# WebSocket API — Security Audit Guide
|
|
2
|
+
|
|
3
|
+
## Unique Risks
|
|
4
|
+
|
|
5
|
+
WebSockets are persistent, bidirectional, and often bypass traditional web security controls:
|
|
6
|
+
- No per-request headers or cookies after initial handshake
|
|
7
|
+
- WAFs struggle to inspect WebSocket traffic
|
|
8
|
+
- Long-lived connections increase attack surface
|
|
9
|
+
|
|
10
|
+
## Vulnerability Patterns
|
|
11
|
+
|
|
12
|
+
### CRITICAL — No Authentication on Connect
|
|
13
|
+
```javascript
|
|
14
|
+
const ws = new WebSocket('wss://api.example.com/ws');
|
|
15
|
+
// No auth token sent → anyone can connect
|
|
16
|
+
```
|
|
17
|
+
Fix: require JWT/token in connection header or first message.
|
|
18
|
+
|
|
19
|
+
### CRITICAL — No Per-Message Authorization
|
|
20
|
+
Connection is authenticated, but subsequent messages are not authorized.
|
|
21
|
+
```
|
|
22
|
+
User connects (valid token) → sends: {"action": "deleteUser", "target": 5}
|
|
23
|
+
No check if user is admin or owns user 5.
|
|
24
|
+
```
|
|
25
|
+
Fix: authorize every message independently.
|
|
26
|
+
|
|
27
|
+
### HIGH — No Input Validation
|
|
28
|
+
```
|
|
29
|
+
ws.send(JSON.stringify({ action: "query", sql: "DROP TABLE users" }));
|
|
30
|
+
```
|
|
31
|
+
Fix: validate all message content server-side. Never trust the client.
|
|
32
|
+
|
|
33
|
+
### HIGH — Message Injection
|
|
34
|
+
If messages are parsed or rendered unescaped:
|
|
35
|
+
```
|
|
36
|
+
ws.send(JSON.stringify({ action: "chat", message: "<script>...</script>" }));
|
|
37
|
+
```
|
|
38
|
+
Fix: escape output, strip HTML, validate message schema.
|
|
39
|
+
|
|
40
|
+
### MEDIUM — No Rate Limiting
|
|
41
|
+
Without per-connection rate limiting:
|
|
42
|
+
- Message flood
|
|
43
|
+
- Resource exhaustion
|
|
44
|
+
- Data exfiltration via rapid queries
|
|
45
|
+
Fix: rate limit per connection, close connections that exceed limits.
|
|
46
|
+
|
|
47
|
+
### MEDIUM — No Origin Validation
|
|
48
|
+
```javascript
|
|
49
|
+
// Server accepts connections from any origin
|
|
50
|
+
```
|
|
51
|
+
An attacker's website can open WebSocket connections on behalf of logged-in users (CSWSH — Cross-Site WebSocket Hijacking).
|
|
52
|
+
Fix: validate Origin header during handshake.
|
|
53
|
+
|
|
54
|
+
### MEDIUM — No Connection Timeout
|
|
55
|
+
Connections stay open indefinitely, consuming resources.
|
|
56
|
+
Fix: implement idle timeout, absolute timeout, and heartbeat.
|
|
57
|
+
|
|
58
|
+
### LOW — Unencrypted Connections
|
|
59
|
+
```
|
|
60
|
+
const ws = new WebSocket('ws://api.example.com/ws');
|
|
61
|
+
```
|
|
62
|
+
Fix: mandatory WSS (TLS) for all WebSocket connections.
|
|
63
|
+
|
|
64
|
+
## WebSocket-Specific Best Practices
|
|
65
|
+
|
|
66
|
+
1. Authenticate on connection (token in first message or header)
|
|
67
|
+
2. Authorize every message independently
|
|
68
|
+
3. Validate all message content and schema
|
|
69
|
+
4. Rate limit per connection
|
|
70
|
+
5. Validate Origin header during handshake
|
|
71
|
+
6. Implement idle timeout and absolute timeout
|
|
72
|
+
7. Use WSS exclusively (no plain WS)
|
|
73
|
+
8. Limit message size
|
|
74
|
+
9. Log all connections and disconnections
|
|
75
|
+
10. Monitor for abnormal message patterns
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# BOLA — Broken Object Level Authorization (API1:2023)
|
|
2
|
+
|
|
3
|
+
OWASP API Security Top 10 — #1
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
BOLA (also known as IDOR) occurs when an API does not verify that the requesting user is authorized to access a specific object. The attacker simply changes an object ID in the request to access another user's data.
|
|
8
|
+
|
|
9
|
+
## Detection
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
// Vulnerable: no ownership check
|
|
13
|
+
app.get('/api/orders/:id', (req, res) => {
|
|
14
|
+
const order = db.orders.findById(req.params.id);
|
|
15
|
+
res.json(order);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// Secure: ownership check
|
|
19
|
+
app.get('/api/orders/:id', authenticate, (req, res) => {
|
|
20
|
+
const order = db.orders.findById(req.params.id);
|
|
21
|
+
if (order.userId !== req.user.id && !req.user.isAdmin) {
|
|
22
|
+
return res.status(403).json({ error: 'Forbidden' });
|
|
23
|
+
}
|
|
24
|
+
res.json(order);
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Testing
|
|
29
|
+
|
|
30
|
+
1. Create user A and user B
|
|
31
|
+
2. Get A's auth token
|
|
32
|
+
3. Access B's resources by changing IDs
|
|
33
|
+
4. If successful → BOLA
|
|
34
|
+
|
|
35
|
+
## Remediation
|
|
36
|
+
|
|
37
|
+
1. Verify ownership on every object access
|
|
38
|
+
2. Use UUIDs instead of sequential IDs
|
|
39
|
+
3. Implement proper authorization middleware
|
|
40
|
+
4. Log all access control failures
|
|
41
|
+
5. Test with automated scanners
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# BOPLA — Broken Function Level Authorization (API2:2023)
|
|
2
|
+
|
|
3
|
+
OWASP API Security Top 10 — #2
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
BOPLA occurs when an API exposes administrative or privileged functions that regular users can access. The attacker uses a regular user token to call admin endpoints.
|
|
8
|
+
|
|
9
|
+
## Detection
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
// Vulnerable: no admin check
|
|
13
|
+
app.delete('/api/admin/users/:id', authenticate, (req, res) => {
|
|
14
|
+
db.users.delete(req.params.id);
|
|
15
|
+
res.status(204).send();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// Secure: role check
|
|
19
|
+
app.delete('/api/admin/users/:id', authenticate, authorize('admin'), (req, res) => {
|
|
20
|
+
db.users.delete(req.params.id);
|
|
21
|
+
res.status(204).send();
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Testing
|
|
26
|
+
|
|
27
|
+
1. Create a regular user and an admin user
|
|
28
|
+
2. Get regular user token
|
|
29
|
+
3. Try all admin endpoints with regular token
|
|
30
|
+
4. If any succeed → BOPLA
|
|
31
|
+
|
|
32
|
+
## Remediation
|
|
33
|
+
|
|
34
|
+
1. Implement role-based access control
|
|
35
|
+
2. Verify authorization on every admin function
|
|
36
|
+
3. Never rely on route-level auth alone
|
|
37
|
+
4. Use function-level authorization decorators/middleware
|
|
38
|
+
5. Test with least-privilege tokens
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# API Inventory — Asset Management
|
|
2
|
+
|
|
3
|
+
## Why It Matters
|
|
4
|
+
|
|
5
|
+
APIs proliferate faster than documentation:
|
|
6
|
+
- Shadow APIs (undeclared, unmonitored)
|
|
7
|
+
- Deprecated versions (still running, weaker security)
|
|
8
|
+
- Debug endpoints (exposed in production)
|
|
9
|
+
- Misconfigured new endpoints
|
|
10
|
+
|
|
11
|
+
## Discovery Techniques
|
|
12
|
+
|
|
13
|
+
### Automated
|
|
14
|
+
```bash
|
|
15
|
+
# Subdomain enumeration
|
|
16
|
+
subfinder -d example.com | httpx -silent
|
|
17
|
+
|
|
18
|
+
# Path enumeration
|
|
19
|
+
ffuf -w /usr/share/wordlists/api.txt -u https://api.example.com/FUZZ
|
|
20
|
+
|
|
21
|
+
# Swagger/OpenAPI discovery
|
|
22
|
+
ffuf -w endpoints.txt -u https://example.com/FUZZ/swagger.json
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Manual
|
|
26
|
+
- Review JavaScript source for API calls
|
|
27
|
+
- Check network tab in browser devtools
|
|
28
|
+
- Monitor DNS records for subdomain patterns
|
|
29
|
+
- Review job postings for tech stack hints
|
|
30
|
+
|
|
31
|
+
### From Response Analysis
|
|
32
|
+
- Look for API version headers
|
|
33
|
+
- Check response structure differences
|
|
34
|
+
- Identify internal hostnames or IPs
|
|
35
|
+
|
|
36
|
+
## Inventory Checklist
|
|
37
|
+
|
|
38
|
+
- [ ] All API subdomains mapped
|
|
39
|
+
- [ ] All API paths discovered
|
|
40
|
+
- [ ] HTTP methods tested per path
|
|
41
|
+
- [ ] Content types tested per endpoint
|
|
42
|
+
- [ ] Authentication status per endpoint
|
|
43
|
+
- [ ] Version history documented
|
|
44
|
+
- [ ] Deprecated endpoints flagged
|
|
45
|
+
- [ ] Debug/test endpoints identified
|
|
46
|
+
- [ ] Third-party API dependencies listed
|
|
47
|
+
- [ ] Shadow APIs found and documented
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Rate Limiting — API Abuse Prevention
|
|
2
|
+
|
|
3
|
+
## Why It Matters
|
|
4
|
+
|
|
5
|
+
Without rate limiting:
|
|
6
|
+
- Brute force: 10,000 passwords tested in 1 minute
|
|
7
|
+
- Enumeration: entire user database scraped
|
|
8
|
+
- DoS: server overwhelmed by single client
|
|
9
|
+
- Financial: costs from cloud API calls
|
|
10
|
+
|
|
11
|
+
## Implementation Patterns
|
|
12
|
+
|
|
13
|
+
### By IP
|
|
14
|
+
```nginx
|
|
15
|
+
limit_req_zone $binary_remote_addr zone=api:10m rate=30r/m;
|
|
16
|
+
```
|
|
17
|
+
Pros: simple, no client changes
|
|
18
|
+
Cons: shared IPs (NAT), proxy bypass
|
|
19
|
+
|
|
20
|
+
### By User ID
|
|
21
|
+
```javascript
|
|
22
|
+
// After authentication
|
|
23
|
+
const key = `ratelimit:${req.user.id}`;
|
|
24
|
+
const count = await redis.incr(key);
|
|
25
|
+
if (count > 100) return 429;
|
|
26
|
+
```
|
|
27
|
+
Pros: accurate per user
|
|
28
|
+
Cons: requires auth, unauthenticated = IP fallback
|
|
29
|
+
|
|
30
|
+
### By Token
|
|
31
|
+
```javascript
|
|
32
|
+
const key = `ratelimit:${req.headers['x-api-key']}`;
|
|
33
|
+
```
|
|
34
|
+
Pros: works for service accounts
|
|
35
|
+
Cons: tokens can be shared
|
|
36
|
+
|
|
37
|
+
### Hybrid
|
|
38
|
+
```javascript
|
|
39
|
+
const key = req.user?.id || req.ip;
|
|
40
|
+
```
|
|
41
|
+
Best approach: authenticated users by ID, anonymous by IP.
|
|
42
|
+
|
|
43
|
+
## Recommended Limits
|
|
44
|
+
|
|
45
|
+
| Endpoint Type | Limit | Window |
|
|
46
|
+
|--------------|-------|--------|
|
|
47
|
+
| Login | 5 | 15 min |
|
|
48
|
+
| Registration | 3 | 1 hour |
|
|
49
|
+
| Password Reset| 3 | 1 hour |
|
|
50
|
+
| General API | 100 | 1 min |
|
|
51
|
+
| File Upload | 10 | 1 hour |
|
|
52
|
+
| Search | 30 | 1 min |
|
|
53
|
+
| WebSocket Msg| 60 | 1 min |
|
|
54
|
+
|
|
55
|
+
## Response
|
|
56
|
+
|
|
57
|
+
```http
|
|
58
|
+
HTTP/1.1 429 Too Many Requests
|
|
59
|
+
Retry-After: 900
|
|
60
|
+
Content-Type: application/json
|
|
61
|
+
|
|
62
|
+
{
|
|
63
|
+
"error": "rate_limit_exceeded",
|
|
64
|
+
"retry_after_seconds": 900
|
|
65
|
+
}
|
|
66
|
+
```
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Third-Party API Security
|
|
2
|
+
|
|
3
|
+
## The Trust Problem
|
|
4
|
+
|
|
5
|
+
Your security depends on APIs you do not control:
|
|
6
|
+
- Payment gateways, auth providers, SaaS integrations
|
|
7
|
+
- Data enrichment services, analytics, monitoring
|
|
8
|
+
- AI/ML APIs, cloud functions, webhooks
|
|
9
|
+
|
|
10
|
+
## Risk Categories
|
|
11
|
+
|
|
12
|
+
### 1. Data Exposure
|
|
13
|
+
When your app sends data to third parties:
|
|
14
|
+
- Are they encrypting at rest?
|
|
15
|
+
- Do they log sensitive data?
|
|
16
|
+
- What happens to data on account deletion?
|
|
17
|
+
- Do they sell or share data?
|
|
18
|
+
|
|
19
|
+
### 2. Supply Chain Attack
|
|
20
|
+
When third-party API is compromised:
|
|
21
|
+
- Attacker controls responses
|
|
22
|
+
- Malicious data injected downstream
|
|
23
|
+
- Credential theft from third-party breach
|
|
24
|
+
|
|
25
|
+
### 3. Webhook Abuse
|
|
26
|
+
When third party calls your endpoint:
|
|
27
|
+
- Spoofed webhook calls
|
|
28
|
+
- Replay attacks
|
|
29
|
+
- Payload manipulation
|
|
30
|
+
- Webhook endpoint DDoS
|
|
31
|
+
|
|
32
|
+
## Remediation
|
|
33
|
+
|
|
34
|
+
### Outgoing Calls
|
|
35
|
+
1. Enforce HTTPS with certificate validation
|
|
36
|
+
2. Set timeouts on all requests
|
|
37
|
+
3. Implement retry logic with exponential backoff
|
|
38
|
+
4. Treat all external data as untrusted
|
|
39
|
+
5. Validate response schemas
|
|
40
|
+
6. Log all external calls for audit
|
|
41
|
+
7. Store credentials in a secrets manager
|
|
42
|
+
|
|
43
|
+
### Incoming Webhooks
|
|
44
|
+
1. Verify webhook signatures (HMAC)
|
|
45
|
+
2. Validate payload schema
|
|
46
|
+
3. Use a webhook secret per integration
|
|
47
|
+
4. Implement replay protection (timestamp + nonce)
|
|
48
|
+
5. Rate limit per webhook source
|
|
49
|
+
6. IP allowlist where possible
|
|
50
|
+
7. Return 200 quickly, process async
|
|
51
|
+
|
|
52
|
+
### Monitoring
|
|
53
|
+
1. Monitor for unusual third-party response patterns
|
|
54
|
+
2. Alert on third-party SLA breaches
|
|
55
|
+
3. Review third-party security postures regularly
|
|
56
|
+
4. Test third-party failure modes (graceful degradation)
|
|
57
|
+
5. Keep third-party dependencies minimal
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# API Security Audit Report
|
|
2
|
+
|
|
3
|
+
**Target:** [API Name/URL]
|
|
4
|
+
**Date:** [YYYY-MM-DD]
|
|
5
|
+
**Auditor:** [Name]
|
|
6
|
+
**Version:** [API Version]
|
|
7
|
+
|
|
8
|
+
## Executive Summary
|
|
9
|
+
|
|
10
|
+
[Brief overview: scope, critical findings, overall risk level]
|
|
11
|
+
|
|
12
|
+
**Risk Level:** [Critical / High / Medium / Low]
|
|
13
|
+
**Endpoints Tested:** [X]
|
|
14
|
+
**Vulnerabilities Found:** [X]
|
|
15
|
+
|
|
16
|
+
## Scope
|
|
17
|
+
|
|
18
|
+
### In Scope
|
|
19
|
+
- [Endpoint 1]
|
|
20
|
+
- [Endpoint 2]
|
|
21
|
+
- [Authentication mechanism]
|
|
22
|
+
- [API version]
|
|
23
|
+
|
|
24
|
+
### Out of Scope
|
|
25
|
+
- [Anything excluded]
|
|
26
|
+
|
|
27
|
+
## Methodology
|
|
28
|
+
|
|
29
|
+
- [X] Discovery & Mapping
|
|
30
|
+
- [X] Authentication Testing
|
|
31
|
+
- [X] Authorization Testing (BOLA/BOPLA)
|
|
32
|
+
- [X] Input Validation
|
|
33
|
+
- [X] Rate Limiting
|
|
34
|
+
- [X] Data Exposure
|
|
35
|
+
- [X] Configuration Review
|
|
36
|
+
|
|
37
|
+
## Findings
|
|
38
|
+
|
|
39
|
+
### CRITICAL
|
|
40
|
+
| # | Finding | Endpoint | Impact | Remediation |
|
|
41
|
+
|---|---------|----------|--------|-------------|
|
|
42
|
+
| 1 | [Title] | [URL] | [Impact] | [Fix] |
|
|
43
|
+
| 2 | [Title] | [URL] | [Impact] | [Fix] |
|
|
44
|
+
|
|
45
|
+
### HIGH
|
|
46
|
+
| # | Finding | Endpoint | Impact | Remediation |
|
|
47
|
+
|---|---------|----------|--------|-------------|
|
|
48
|
+
| 3 | [Title] | [URL] | [Impact] | [Fix] |
|
|
49
|
+
|
|
50
|
+
### MEDIUM
|
|
51
|
+
| # | Finding | Endpoint | Impact | Remediation |
|
|
52
|
+
|---|---------|----------|--------|-------------|
|
|
53
|
+
| 4 | [Title] | [URL] | [Impact] | [Fix] |
|
|
54
|
+
|
|
55
|
+
## Detailed Findings
|
|
56
|
+
|
|
57
|
+
### Finding 1: [Title] (Critical)
|
|
58
|
+
**Endpoint:** [URL]
|
|
59
|
+
**Description:** [Detailed description]
|
|
60
|
+
**Request:**
|
|
61
|
+
```http
|
|
62
|
+
GET /api/...
|
|
63
|
+
```
|
|
64
|
+
**Response:**
|
|
65
|
+
```http
|
|
66
|
+
HTTP/1.1 200 OK
|
|
67
|
+
{ ... }
|
|
68
|
+
```
|
|
69
|
+
**Impact:** [Business/technical impact]
|
|
70
|
+
**Remediation:** [Step-by-step fix]
|
|
71
|
+
**CVSS:** [Score]
|
|
72
|
+
|
|
73
|
+
### Finding 2: [Title]
|
|
74
|
+
...
|
|
75
|
+
|
|
76
|
+
## Recommendations
|
|
77
|
+
|
|
78
|
+
1. [Priority action]
|
|
79
|
+
2. [Priority action]
|
|
80
|
+
3. [Priority action]
|
|
81
|
+
|
|
82
|
+
## Appendix
|
|
83
|
+
|
|
84
|
+
### Tools Used
|
|
85
|
+
- [Tool/version]
|
|
86
|
+
|
|
87
|
+
### Reference
|
|
88
|
+
- OWASP API Security Top 10 (2023)
|
|
89
|
+
- [Other references]
|