cyberaudit-skill 3.0.5 → 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/dist/cli.js +9 -2
- package/package.json +1 -1
- package/skills/cyberaudit/COMMANDS.md +86 -1125
- package/skills/cyberaudit/SKILL.md +102 -4
- 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
|
@@ -5,7 +5,7 @@ description: >
|
|
|
5
5
|
Use when auditing source code for vulnerabilities — full methodology from
|
|
6
6
|
quick scan to red team. Follows OWASP Top 10 2023, CVSS 3.1, ASVS 4.0.
|
|
7
7
|
Trigger: "audit", "security", "vulnerability", "pentest", "OWASP",
|
|
8
|
-
"scan my code", "security review".
|
|
8
|
+
"scan my code", "security review", "commands", "help".
|
|
9
9
|
compatibility: Pure Markdown skill, no external dependencies. Works with any AI agent that loads SKILL.md.
|
|
10
10
|
metadata:
|
|
11
11
|
author: ArisRoman
|
|
@@ -13,16 +13,92 @@ metadata:
|
|
|
13
13
|
allowed-tools: Read Edit Grep Glob Bash
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
-
# CyberAudit Skill
|
|
16
|
+
# CyberAudit Skill
|
|
17
17
|
|
|
18
18
|
Security audit intelligence for AI agents. Universal, framework-agnostic, methodology-driven.
|
|
19
19
|
|
|
20
|
+
## Available Commands
|
|
21
|
+
|
|
22
|
+
### Global
|
|
23
|
+
| Command | Action |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `/audit` | Full audit (auto-detect web/mobile) |
|
|
26
|
+
| `/audit:quick` | Quick scan — criticals only |
|
|
27
|
+
| `/audit:report` | Generate full report |
|
|
28
|
+
| `/audit:exec` | Generate executive summary |
|
|
29
|
+
|
|
30
|
+
### Web
|
|
31
|
+
| Command | Action |
|
|
32
|
+
|---|---|
|
|
33
|
+
| `/audit:web` | Full web audit (OWASP Top 10) |
|
|
34
|
+
| `/audit:auth` | Authentication & Authorization |
|
|
35
|
+
| `/audit:injection` | SQL, NoSQL, Command, SSTI |
|
|
36
|
+
| `/audit:xss` | Cross-Site Scripting |
|
|
37
|
+
| `/audit:csrf` | Cross-Site Request Forgery |
|
|
38
|
+
| `/audit:cors` | CORS configuration |
|
|
39
|
+
| `/audit:headers` | HTTP security headers |
|
|
40
|
+
| `/audit:secrets` | Exposed secrets & credentials |
|
|
41
|
+
| `/audit:deps` | Dependencies & supply chain |
|
|
42
|
+
| `/audit:ssrf` | Server-Side Request Forgery |
|
|
43
|
+
| `/audit:idor` | IDOR & access control |
|
|
44
|
+
| `/audit:logic` | Business logic flaws |
|
|
45
|
+
| `/audit:crypto` | Web cryptography |
|
|
46
|
+
| `/audit:xxe` | XML External Entities |
|
|
47
|
+
| `/audit:deserial` | Insecure deserialization |
|
|
48
|
+
| `/audit:laravel` | Laravel-specific audit |
|
|
49
|
+
| `/audit:nextjs` | Next.js-specific audit |
|
|
50
|
+
| `/audit:react` | React-specific audit |
|
|
51
|
+
| `/audit:nestjs` | NestJS-specific audit |
|
|
52
|
+
| `/audit:express` | Express-specific audit |
|
|
53
|
+
| `/audit:vue` | Vue.js-specific audit |
|
|
54
|
+
| `/audit:angular` | Angular-specific audit |
|
|
55
|
+
|
|
56
|
+
### Mobile
|
|
57
|
+
| Command | Action |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `/audit:mobile` | Full mobile audit (OWASP MASVS) |
|
|
60
|
+
| `/audit:storage` | Local storage security |
|
|
61
|
+
| `/audit:network` | Network security |
|
|
62
|
+
| `/audit:binary` | Binary analysis |
|
|
63
|
+
| `/audit:permissions` | Permissions audit |
|
|
64
|
+
| `/audit:deeplinks` | Deep links & IPC |
|
|
65
|
+
| `/audit:auth-mobile` | Mobile authentication |
|
|
66
|
+
| `/audit:crypto-mobile` | Mobile cryptography |
|
|
67
|
+
| `/audit:runtime` | Runtime security |
|
|
68
|
+
| `/audit:react-native` | React Native audit |
|
|
69
|
+
| `/audit:flutter` | Flutter audit |
|
|
70
|
+
| `/audit:ionic` | Ionic audit |
|
|
71
|
+
| `/audit:expo` | Expo audit |
|
|
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
|
+
|
|
87
|
+
### Compliance
|
|
88
|
+
| Command | Action |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `/audit:rgpd` | RGPD compliance check |
|
|
91
|
+
| `/audit:pci` | PCI-DSS compliance check |
|
|
92
|
+
| `/audit:hipaa` | HIPAA compliance check |
|
|
93
|
+
| `/audit:masvs` | MASVS 2.0 score |
|
|
94
|
+
| `/audit:owasp` | OWASP Top 10 score |
|
|
95
|
+
|
|
20
96
|
## Boot Sequence
|
|
21
97
|
|
|
22
98
|
Execute on every audit request:
|
|
23
99
|
|
|
24
100
|
**STEP 1 — IDENTIFICATION** (30 sec)
|
|
25
|
-
- TYPE → Web / Mobile / Both
|
|
101
|
+
- TYPE → Web / Mobile / API / Both
|
|
26
102
|
- FRAMEWORK → Identify precisely (React, Laravel, Flutter, etc.)
|
|
27
103
|
- CONTEXT → Dev / Staging / Production
|
|
28
104
|
- SCOPE → Entire code / Single module
|
|
@@ -31,6 +107,7 @@ Execute on every audit request:
|
|
|
31
107
|
**STEP 2 — MODE LOADING**
|
|
32
108
|
- Web → Load web checklist + framework-specific guide
|
|
33
109
|
- Mobile → Load mobile checklist + framework-specific guide
|
|
110
|
+
- API → Load API checklist + type-specific guide (REST/GraphQL/WebSocket)
|
|
34
111
|
|
|
35
112
|
**STEP 3 — STRUCTURED AUDIT**
|
|
36
113
|
Follow the loaded philosophy. Never skip a phase. Document each finding immediately.
|
|
@@ -116,6 +193,11 @@ Every report must include:
|
|
|
116
193
|
- **Express**: CORS, helmet, input validation, error handling
|
|
117
194
|
- **NestJS**: Guards, pipes, serialization, GraphQL security
|
|
118
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
|
+
|
|
119
201
|
### Mobile Frameworks
|
|
120
202
|
- **React Native**: AsyncStorage, deep links, WebView XSS, JS bundle exposure
|
|
121
203
|
- **Flutter**: Method channels, root detection, local storage, obfuscation
|
|
@@ -155,9 +237,24 @@ This skill lives at `~/.skills/cyberaudit/`. Additional sub-skills:
|
|
|
155
237
|
├── MASTER.md (full vulnerability taxonomy + scoring)
|
|
156
238
|
├── USAGE-GUIDE.md (user-facing documentation)
|
|
157
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
|
|
158
254
|
├── reports/
|
|
159
255
|
│ ├── REPORT-TEMPLATE-WEB.md
|
|
160
256
|
│ ├── REPORT-TEMPLATE-MOBILE.md
|
|
257
|
+
│ ├── REPORT-TEMPLATE-API.md
|
|
161
258
|
│ └── EXECUTIVE-SUMMARY-TEMPLATE.md
|
|
162
259
|
├── shared/
|
|
163
260
|
│ ├── COMPLIANCE.md
|
|
@@ -192,7 +289,8 @@ This skill lives at `~/.skills/cyberaudit/`. Additional sub-skills:
|
|
|
192
289
|
```
|
|
193
290
|
|
|
194
291
|
For detailed framework-specific checks, load the appropriate file from `web/frameworks/` or `mobile/frameworks/`.
|
|
195
|
-
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).
|
|
196
294
|
|
|
197
295
|
---
|
|
198
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)
|