@gpzhang2001/sharpkit-skills 0.2.1
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/LICENSE +201 -0
- package/README.md +12 -0
- package/THIRD_PARTY_NOTICES.md +48 -0
- package/lib/index.d.ts +2027 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +70 -0
- package/lib/index.js.map +1 -0
- package/package.json +46 -0
- package/skills/analysis/counterevidence.md +185 -0
- package/skills/analysis/fix_verification.md +129 -0
- package/skills/analysis/severity_calibration.md +130 -0
- package/skills/analysis/source_aware_discovery.md +211 -0
- package/skills/cloud/aws.md +231 -0
- package/skills/cloud/azure.md +262 -0
- package/skills/cloud/gcp.md +194 -0
- package/skills/cloud/kubernetes.md +223 -0
- package/skills/coordination/root_agent.md +105 -0
- package/skills/coordination/source_aware_whitebox.md +47 -0
- package/skills/custom/api_spec_testing.md +61 -0
- package/skills/custom/dependency_cve_scanning.md +341 -0
- package/skills/custom/npx_confusion.md +233 -0
- package/skills/custom/source_aware_sast.md +192 -0
- package/skills/frameworks/django.md +214 -0
- package/skills/frameworks/fastapi.md +191 -0
- package/skills/frameworks/nestjs.md +225 -0
- package/skills/frameworks/nextjs.md +228 -0
- package/skills/protocols/graphql.md +276 -0
- package/skills/protocols/oauth.md +185 -0
- package/skills/reconnaissance/asset_discovery.md +150 -0
- package/skills/reconnaissance/infrastructure_lifecycle.md +226 -0
- package/skills/scan_modes/deep.md +164 -0
- package/skills/scan_modes/diff.md +86 -0
- package/skills/scan_modes/quick.md +68 -0
- package/skills/scan_modes/standard.md +99 -0
- package/skills/technologies/active_directory.md +233 -0
- package/skills/technologies/auth0.md +188 -0
- package/skills/technologies/electron_desktop_apps.md +181 -0
- package/skills/technologies/firebase.md +263 -0
- package/skills/technologies/grafana_prometheus.md +189 -0
- package/skills/technologies/llm_applications.md +257 -0
- package/skills/technologies/supabase.md +268 -0
- package/skills/tooling/agent_browser.md +551 -0
- package/skills/tooling/ffuf.md +72 -0
- package/skills/tooling/httpx.md +82 -0
- package/skills/tooling/hurl.md +99 -0
- package/skills/tooling/hypothesis.md +100 -0
- package/skills/tooling/katana.md +102 -0
- package/skills/tooling/naabu.md +68 -0
- package/skills/tooling/nmap.md +66 -0
- package/skills/tooling/nuclei.md +67 -0
- package/skills/tooling/python.md +109 -0
- package/skills/tooling/semgrep.md +72 -0
- package/skills/tooling/sqlmap.md +67 -0
- package/skills/tooling/subfinder.md +66 -0
- package/skills/vulnerabilities/agentic_system_security.md +207 -0
- package/skills/vulnerabilities/argument_injection.md +157 -0
- package/skills/vulnerabilities/authentication_jwt.md +166 -0
- package/skills/vulnerabilities/broken_function_level_authorization.md +154 -0
- package/skills/vulnerabilities/browser_security.md +192 -0
- package/skills/vulnerabilities/business_logic.md +178 -0
- package/skills/vulnerabilities/csrf.md +198 -0
- package/skills/vulnerabilities/header_injection.md +216 -0
- package/skills/vulnerabilities/http_request_smuggling.md +255 -0
- package/skills/vulnerabilities/idor.md +217 -0
- package/skills/vulnerabilities/information_disclosure.md +187 -0
- package/skills/vulnerabilities/insecure_deserialization.md +210 -0
- package/skills/vulnerabilities/insecure_file_uploads.md +194 -0
- package/skills/vulnerabilities/llm_prompt_injection.md +187 -0
- package/skills/vulnerabilities/mass_assignment.md +153 -0
- package/skills/vulnerabilities/nosql_injection.md +288 -0
- package/skills/vulnerabilities/open_redirect.md +165 -0
- package/skills/vulnerabilities/path_traversal_lfi_rfi.md +218 -0
- package/skills/vulnerabilities/prototype_pollution.md +142 -0
- package/skills/vulnerabilities/race_conditions.md +181 -0
- package/skills/vulnerabilities/rce.md +250 -0
- package/skills/vulnerabilities/semantic_confusion.md +189 -0
- package/skills/vulnerabilities/sql_injection.md +190 -0
- package/skills/vulnerabilities/ssrf.md +186 -0
- package/skills/vulnerabilities/ssti.md +270 -0
- package/skills/vulnerabilities/subdomain_takeover.md +167 -0
- package/skills/vulnerabilities/weak_password_detection.md +200 -0
- package/skills/vulnerabilities/xss.md +206 -0
- package/skills/vulnerabilities/xxe.md +223 -0
- package/src/index.ts +89 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: browser-security
|
|
3
|
+
description: Browser-internals security testing for browsing-context relationships, postMessage, client-side path traversal, XS-Leaks, service workers, Web Workers, navigation behavior, CSP interactions, caches, and cross-origin state machines
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Browser Security
|
|
7
|
+
|
|
8
|
+
Use this skill when exploitability depends on browser behavior beyond a basic HTML injection. Model origins, browsing contexts, navigation history, workers, caches, router decoding, request metadata, and user activation as explicit state.
|
|
9
|
+
|
|
10
|
+
Pair this skill with `xss`, `oauth`, `open_redirect`, `csrf`, or `semantic_confusion` when one of those is the primary vulnerability class. For an Electron renderer with a preload or IPC bridge, load `electron_desktop_apps` to analyze whether navigation and origin transitions reach native capability.
|
|
11
|
+
|
|
12
|
+
## Safety Boundary
|
|
13
|
+
|
|
14
|
+
- Use a controlled browser profile, synthetic account/data, explicit target allowlist, and a fresh assessment-specific proxy/CA when interception is required.
|
|
15
|
+
- Redact tokens, cookies, message contents, storage values, and personal data from console logs, captures, recordings, and reports.
|
|
16
|
+
- Treat oversized URLs/headers, cookie inflation, redirect loops, cache exhaustion, and high-rate timing trials as resource/denial-of-service tests; run them only with strict ceilings in a restartable lab.
|
|
17
|
+
- Do not attempt to set or spoof browser-generated `event.origin`. Vary the sender URL and record the serialized origin supplied by the browser.
|
|
18
|
+
- Restore monkey-patched browser APIs and unregister test workers/caches after validation.
|
|
19
|
+
|
|
20
|
+
## Browser State Model
|
|
21
|
+
|
|
22
|
+
For each relevant page or worker, record:
|
|
23
|
+
|
|
24
|
+
- origin and site, including transitions after navigation
|
|
25
|
+
- top-level window, opener, parent, child frames, named contexts, and retained references
|
|
26
|
+
- sandbox flags, CSP `frame-ancestors`, COOP, COEP, CORP, and X-Frame-Options
|
|
27
|
+
- service-worker controller and scope
|
|
28
|
+
- storage access: cookies, local/session storage, IndexedDB, Cache API
|
|
29
|
+
- navigation/history entries and redirect type: HTTP, JavaScript, form, meta refresh
|
|
30
|
+
- user-activation and interaction requirements
|
|
31
|
+
- browser family/version and enabled experimental features
|
|
32
|
+
|
|
33
|
+
Draw the context graph. Security checks on `event.origin`, `event.source`, or a popup reference are meaningful only when the lifetime and ownership of that context are understood.
|
|
34
|
+
|
|
35
|
+
## High-Value Surfaces
|
|
36
|
+
|
|
37
|
+
### postMessage and Window Relationships
|
|
38
|
+
|
|
39
|
+
- Enumerate listeners and senders; record message schema, origin check, source check, and reachable sinks/actions.
|
|
40
|
+
- Validate origins after URL parsing and canonicalization, not with raw-string regexes.
|
|
41
|
+
- Test numeric/alternate IP forms, userinfo, path masquerading as a host suffix, and redirects.
|
|
42
|
+
- Treat predictable `window.open()` target names and iframe names as potentially shared namespace entries. Confirm reuse within the same browsing-context group, opener chain, COOP state, and relevant navigation/message timing.
|
|
43
|
+
- Check whether a blocked intermediate frame leaves a useful browsing-context relationship intact.
|
|
44
|
+
- Use random per-flow names or `_blank` with `noopener` where an opener relationship is unnecessary.
|
|
45
|
+
|
|
46
|
+
### Client-Side Path Traversal
|
|
47
|
+
|
|
48
|
+
Trace the complete source-to-request pipeline:
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
browser URL -> router parser -> route/query/hash accessor -> app interpolation -> fetch/XHR -> final normalized URL
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- Test path parameters, query parameters, and hashes independently.
|
|
55
|
+
- Determine exactly where `%2F`, `%5C`, `%2E`, and double-encoded forms decode or re-encode.
|
|
56
|
+
- Instrument `fetch`, XHR, Axios, router navigation, and server-side fetch wrappers to capture the final URL.
|
|
57
|
+
- Escalate only after identifying the sink: state-changing API for CSRF-like impact, HTML/attachment response rendered in an unsafe sink for XSS, or server-side fetch for SSRF.
|
|
58
|
+
- Do not assume the same framework API behaves identically in client components, server components, and route handlers.
|
|
59
|
+
|
|
60
|
+
### XS-Leaks and Cross-Origin Oracles
|
|
61
|
+
|
|
62
|
+
Inventory observable signals that do not require reading the cross-origin response:
|
|
63
|
+
|
|
64
|
+
- load/error events for script, image, stylesheet, frame, media, and module elements
|
|
65
|
+
- timing, connection reuse, cache state, redirect count, and navigation success
|
|
66
|
+
- window/frame count, focus, history length, and resource dimensions
|
|
67
|
+
- browser-generated error pages and status-dependent behavior
|
|
68
|
+
- request headers such as `Sec-Fetch-Dest`, `Sec-Fetch-Mode`, and `Origin`
|
|
69
|
+
|
|
70
|
+
Test controls such as ORB, CORP, COEP, and MIME enforcement. A service worker or alternate fetch path can change request destination metadata and therefore change whether a blocked response becomes a network error or an empty response. Validate the oracle across authenticated and unauthenticated control cases.
|
|
71
|
+
|
|
72
|
+
### Service Workers and Caches
|
|
73
|
+
|
|
74
|
+
- Map service-worker registration scope, update lifecycle, controller acquisition, and fetch handlers.
|
|
75
|
+
- Inspect Cache API keys and responses; determine whether HTML or JavaScript is served directly from a writable cache.
|
|
76
|
+
- Test whether a constrained script context can poison app-managed cache entries later consumed by a normal page or service worker.
|
|
77
|
+
- Treat service-worker persistence as high impact, but prove registration/control scope and update survivability.
|
|
78
|
+
- Compare a direct subresource request with the same request proxied through `fetch(event.request)`; request destination and mode can differ.
|
|
79
|
+
|
|
80
|
+
### Web Workers and Constrained Script Execution
|
|
81
|
+
|
|
82
|
+
When script runs inside a worker, inventory capabilities instead of dismissing it as low impact:
|
|
83
|
+
|
|
84
|
+
- credentialed same-origin `fetch` for data access and state changes
|
|
85
|
+
- `postMessage` gadgets into the main page
|
|
86
|
+
- IndexedDB and Cache API shared with other same-origin contexts
|
|
87
|
+
- Blob construction and object URLs
|
|
88
|
+
- import mechanisms, WebSocket, and available browser-specific APIs
|
|
89
|
+
|
|
90
|
+
Prove the strongest reliable capability first. If escalation requires a user gesture, document the exact gesture, timing, browser, and visibility rather than calling it zero-click XSS.
|
|
91
|
+
|
|
92
|
+
### Navigation and Redirect Control
|
|
93
|
+
|
|
94
|
+
- Distinguish HTTP 30x, script navigation, form submission, meta refresh, and popup navigation.
|
|
95
|
+
- Test invalid or blocked URL schemes and WAF-generated error pages only when they support a real flow. Oversized URLs/headers, cookie-path-specific header inflation, redirect limits, and navigation throttling are restartable-lab-only tests with strict size/iteration limits and health checks.
|
|
96
|
+
- A sandbox inherited by a new top-level context can selectively block forms, scripts, popups, or navigation; enumerate the exact flag set.
|
|
97
|
+
- Preserve and inspect history when a built-in error page replaces the active document; do not assume the errored URL is lost.
|
|
98
|
+
|
|
99
|
+
### CSP and Browser Parsing
|
|
100
|
+
|
|
101
|
+
- Evaluate the delivered policy on the exact response, including redirects and error/API/static paths.
|
|
102
|
+
- Map nonces, hashes, `strict-dynamic`, allowed schemes, trusted script gadgets, `base-uri`, `frame-ancestors`, and Trusted Types.
|
|
103
|
+
- Test parser namespaces and repairs in HTML, SVG, and MathML. A protected attribute or sanitizer rule in the HTML namespace may behave differently after namespace transitions.
|
|
104
|
+
- Treat scriptless disclosure of a nonce or trusted URL as a primitive; prove a second controllable sink before claiming bypass.
|
|
105
|
+
- For response splitting, consider whether a same-origin endpoint can be turned into a script resource with a controlled body length or framing.
|
|
106
|
+
|
|
107
|
+
### JavaScript Gadget Discovery
|
|
108
|
+
|
|
109
|
+
- When direct calls are blocked, inspect implicit coercions (`toString`, `valueOf`, iterators, getters, proxies) and callbacks invoked by accessible library functions.
|
|
110
|
+
- Search for functions whose `this` object and arguments can be attacker-shaped.
|
|
111
|
+
- Build a bounded harness to enumerate reachable globals and observe property reads/calls; avoid assuming one library gadget is universal.
|
|
112
|
+
- Validate the complete call chain to a dangerous sink such as navigation, HTML insertion, `eval`, `Function`, or a privileged API.
|
|
113
|
+
|
|
114
|
+
## Reconnaissance
|
|
115
|
+
|
|
116
|
+
### Runtime Instrumentation
|
|
117
|
+
|
|
118
|
+
Instrument in a controlled browser session:
|
|
119
|
+
|
|
120
|
+
```javascript
|
|
121
|
+
const realFetch = window.fetch;
|
|
122
|
+
window.fetch = (...args) => {
|
|
123
|
+
const input = args[0];
|
|
124
|
+
const rawUrl = typeof input === 'string' ? input : input.url;
|
|
125
|
+
const url = new URL(rawUrl, location.href);
|
|
126
|
+
const method = args[1]?.method || input?.method || 'GET';
|
|
127
|
+
console.log('fetch', {method, origin: url.origin, path: url.pathname});
|
|
128
|
+
return realFetch(...args);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
window.addEventListener('message', e => {
|
|
132
|
+
const keys = e.data && typeof e.data === 'object' ? Object.keys(e.data) : [];
|
|
133
|
+
console.log('message', {origin: e.origin, sourceMatches: e.source === window.opener, keys});
|
|
134
|
+
}, true);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Use the wrapper only in the controlled profile and restore `window.fetch = realFetch` afterward. Do not log bodies, message values, credentials, or query strings.
|
|
138
|
+
|
|
139
|
+
Also inspect DevTools network initiators, service workers, storage, CSP violations, frame tree, and navigation history. Use raw browser behavior for validation; command-line HTTP clients cannot reproduce origin/window/worker semantics.
|
|
140
|
+
|
|
141
|
+
### Source Review
|
|
142
|
+
|
|
143
|
+
- Search for `postMessage`, message listeners, `window.open`, named targets, opener/parent access, frame creation, and sandbox attributes.
|
|
144
|
+
- Search for router parameter APIs flowing into `fetch`, Axios, navigation, or HTML rendering.
|
|
145
|
+
- Search for service-worker registration, Cache API writes, worker constructors, Blob URLs, and dynamic imports.
|
|
146
|
+
- Search for raw HTML sinks and trust escape hatches in every supported frontend framework.
|
|
147
|
+
- Compare CSP and framing headers across document, API, static, callback, redirect, and error routes.
|
|
148
|
+
|
|
149
|
+
## Testing Methodology
|
|
150
|
+
|
|
151
|
+
1. **Define the browser state** - Origin/site, context graph, policies, workers, storage, and activation.
|
|
152
|
+
2. **Identify a source and observable sink** - Message, URL component, cache entry, navigation, load/error event, or implicit call.
|
|
153
|
+
3. **Trace transformations** - URL parsing, framework decode, browser normalization, request destination, and document replacement.
|
|
154
|
+
4. **Build paired controls** - Same-origin/cross-origin, status success/error, worker/direct, unique/predictable window name, encoded/raw path.
|
|
155
|
+
5. **Prove the primitive** - Data transfer, path change, state oracle, cache modification, or context capture.
|
|
156
|
+
6. **Escalate deliberately** - Chain to a privileged action, sensitive disclosure, SSRF, or executable DOM sink.
|
|
157
|
+
7. **Cross-browser check** - At minimum record Chromium/Firefox/Safari applicability when the primitive is browser-specific.
|
|
158
|
+
8. **State interaction requirements** - Click, drag, popup permission, timing window, login state, and visual deception.
|
|
159
|
+
|
|
160
|
+
## Validation
|
|
161
|
+
|
|
162
|
+
1. Capture the context graph and relevant policies at exploit time.
|
|
163
|
+
2. Show the exact browser-parsed origin or final request URL, not just the attacker-supplied string.
|
|
164
|
+
3. For postMessage, prove both message origin and source/context ownership.
|
|
165
|
+
4. For XS-Leaks, repeat randomized success/failure trials and quantify separation and noise.
|
|
166
|
+
5. For workers/caches, show which later context consumes the modified data.
|
|
167
|
+
6. For client-side traversal, capture the final network request and the security-relevant response/action.
|
|
168
|
+
7. For interaction-dependent chains, provide a screen recording or deterministic event trace.
|
|
169
|
+
|
|
170
|
+
## False Positives
|
|
171
|
+
|
|
172
|
+
- A message reaches a listener but fails schema, origin, source, or state validation before any action
|
|
173
|
+
- A router decodes traversal characters but the value never reaches a URL/path sink
|
|
174
|
+
- Different load/error behavior caused by unstable network rather than protected state
|
|
175
|
+
- Worker script execution with no sensitive API, shared state, main-thread gadget, or meaningful action
|
|
176
|
+
- CSP nonce disclosure without a controllable way to reuse it in an executable sink
|
|
177
|
+
- Named-window collision blocked by origin scoping, randomized names, COOP, or `noopener`
|
|
178
|
+
- Browser-specific behavior reported without the required version, flag, or user interaction
|
|
179
|
+
|
|
180
|
+
## Pro Tips
|
|
181
|
+
|
|
182
|
+
1. Treat browsing-context names as attacker-contestable identifiers unless randomized.
|
|
183
|
+
2. Query parameters are usually decoded automatically; path parameters vary by router and execution context.
|
|
184
|
+
3. Compare request metadata, not just URLs. Service workers can alter destination/mode semantics.
|
|
185
|
+
4. A strict origin check does not compensate for attacker control of the supposedly trusted window reference.
|
|
186
|
+
5. Error pages, redirects, and blocked frames still mutate history and context relationships.
|
|
187
|
+
6. Keep browser-version claims narrow and retest; these behaviors change faster than server-side primitives.
|
|
188
|
+
7. Prefer a small state-machine explanation over a large payload catalog.
|
|
189
|
+
|
|
190
|
+
## Summary
|
|
191
|
+
|
|
192
|
+
Browser exploitation is state-machine exploitation. Map origins, context references, policies, workers, storage, navigation, and decoding as one system. Prove each state transition with browser evidence, then chain only the primitives that survive the target's browser and interaction constraints.
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: business-logic
|
|
3
|
+
description: Business logic testing for workflow bypass, state manipulation, and domain invariant violations
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Business Logic Flaws
|
|
7
|
+
|
|
8
|
+
Business logic flaws exploit intended functionality to violate domain invariants: move money without paying, exceed limits, retain privileges, or bypass reviews. They require a model of the business, not just payloads.
|
|
9
|
+
|
|
10
|
+
## Attack Surface
|
|
11
|
+
|
|
12
|
+
- Financial logic: pricing, discounts, payments, refunds, credits, chargebacks
|
|
13
|
+
- Account lifecycle: signup, upgrade/downgrade, trial, suspension, deletion
|
|
14
|
+
- Authorization-by-logic: feature gates, role transitions, approval workflows
|
|
15
|
+
- Quotas/limits: rate/usage limits, inventory, entitlements, seat licensing
|
|
16
|
+
- Multi-tenant isolation: cross-organization data or action bleed
|
|
17
|
+
- Event-driven flows: jobs, webhooks, sagas, compensations, idempotency
|
|
18
|
+
|
|
19
|
+
## High-Value Targets
|
|
20
|
+
|
|
21
|
+
- Pricing/cart: price locks, quote to order, tax/shipping computation
|
|
22
|
+
- Discount engines: stacking, mutual exclusivity, scope (cart vs item), once-per-user enforcement
|
|
23
|
+
- Payments: auth/capture/void/refund sequences, partials, split tenders, chargebacks, idempotency keys
|
|
24
|
+
- Credits/gift cards/vouchers: issuance, redemption, reversal, expiry, transferability
|
|
25
|
+
- Subscriptions: proration, upgrade/downgrade, trial extension, seat counts, meter reporting
|
|
26
|
+
- Refunds/returns/RMAs: multi-item partials, restocking fees, return window edges
|
|
27
|
+
- Admin/staff operations: impersonation, manual adjustments, credit/refund issuance, account flags
|
|
28
|
+
- Quotas/limits: daily/monthly usage, inventory reservations, feature usage counters
|
|
29
|
+
|
|
30
|
+
## Reconnaissance
|
|
31
|
+
|
|
32
|
+
### Workflow Mapping
|
|
33
|
+
|
|
34
|
+
- Derive endpoints from the UI and proxy/network logs; map hidden/undocumented API calls, especially finalize/confirm endpoints
|
|
35
|
+
- Identify tokens/flags: stepToken, paymentIntentId, orderStatus, reviewState, approvalId; test reuse across users/sessions
|
|
36
|
+
- Document invariants: conservation of value (ledger balance), uniqueness (idempotency), monotonicity (non-decreasing counters), exclusivity (one active subscription)
|
|
37
|
+
|
|
38
|
+
### Input Surface
|
|
39
|
+
|
|
40
|
+
- Hidden fields and client-computed totals; server must recompute on trusted sources
|
|
41
|
+
- Alternate encodings and shapes: arrays instead of scalars, objects with unexpected keys, null/empty/0/negative, scientific notation
|
|
42
|
+
- Business selectors: currency, locale, timezone, tax region; vary to trigger rounding and ruleset changes
|
|
43
|
+
|
|
44
|
+
### State and Time Axes
|
|
45
|
+
|
|
46
|
+
- Replays: resubmit stale finalize/confirm requests
|
|
47
|
+
- Out-of-order: call finalize before verify; refund before capture; cancel after ship
|
|
48
|
+
- Time windows: end-of-day/month cutovers, daylight saving, grace periods, trial expiry edges
|
|
49
|
+
|
|
50
|
+
## Key Vulnerabilities
|
|
51
|
+
|
|
52
|
+
### State Machine Abuse
|
|
53
|
+
|
|
54
|
+
- Skip or reorder steps via direct API calls; verify server enforces preconditions on each transition
|
|
55
|
+
- Replay prior steps with altered parameters (e.g., swap price after approval but before capture)
|
|
56
|
+
- Split a single constrained action into many sub-actions under the threshold (limit slicing)
|
|
57
|
+
|
|
58
|
+
### Concurrency and Idempotency
|
|
59
|
+
|
|
60
|
+
- Parallelize identical operations to bypass atomic checks (create, apply, redeem, transfer)
|
|
61
|
+
- Abuse idempotency: key scoped to path but not principal → reuse other users' keys; or idempotency stored only in cache
|
|
62
|
+
- Message reprocessing: queue workers re-run tasks on retry without idempotent guards; cause duplicate fulfillment/refund
|
|
63
|
+
|
|
64
|
+
### Numeric and Currency
|
|
65
|
+
|
|
66
|
+
- Floating point vs decimal rounding; rounding/truncation favoring attacker at boundaries
|
|
67
|
+
- Cross-currency arbitrage: buy in currency A, refund in B at stale rates; tax rounding per-item vs per-order
|
|
68
|
+
- Negative amounts, zero-price, free shipping thresholds, minimum/maximum guardrails
|
|
69
|
+
|
|
70
|
+
### Quotas, Limits, and Inventory
|
|
71
|
+
|
|
72
|
+
- Off-by-one and time-bound resets (UTC vs local); pre-warm at T-1s and post-fire at T+1s
|
|
73
|
+
- Reservation/hold leaks: reserve multiple, complete one, release not enforced; backorder logic inconsistencies
|
|
74
|
+
- Distributed counters without strong consistency enabling double-consumption
|
|
75
|
+
|
|
76
|
+
### Refunds and Chargebacks
|
|
77
|
+
|
|
78
|
+
- Double-refund: refund via UI and support tool; refund partials summing above captured amount
|
|
79
|
+
- Refund after benefits consumed (downloaded digital goods, shipped items) due to missing post-consumption checks
|
|
80
|
+
|
|
81
|
+
### Feature Gates and Roles
|
|
82
|
+
|
|
83
|
+
- Feature flags enforced client-side or at edge but not in core services; toggle names guessed or fallback to default-enabled
|
|
84
|
+
- Role transitions leaving stale capabilities (retain premium after downgrade; retain admin endpoints after demotion)
|
|
85
|
+
|
|
86
|
+
## Advanced Techniques
|
|
87
|
+
|
|
88
|
+
### Event-Driven Sagas
|
|
89
|
+
|
|
90
|
+
- Saga/compensation gaps: trigger compensation without original success; or execute success twice without compensation
|
|
91
|
+
- Outbox/Inbox patterns missing idempotency → duplicate downstream side effects
|
|
92
|
+
- Cron/backfill jobs operating outside request-time authorization; mutate state broadly
|
|
93
|
+
|
|
94
|
+
### Microservices Boundaries
|
|
95
|
+
|
|
96
|
+
- Cross-service assumption mismatch: one service validates total, another trusts line items; alter between calls
|
|
97
|
+
- Header trust: internal services trusting X-Role or X-User-Id from untrusted edges
|
|
98
|
+
- Partial failure windows: two-phase actions where phase 1 commits without phase 2, leaving exploitable intermediate state
|
|
99
|
+
|
|
100
|
+
### Multi-Tenant Isolation
|
|
101
|
+
|
|
102
|
+
- Tenant-scoped counters and credits updated without tenant key in the where-clause; leak across orgs
|
|
103
|
+
- Admin aggregate views allowing actions that impact other tenants due to missing per-tenant enforcement
|
|
104
|
+
|
|
105
|
+
## Bypass Techniques
|
|
106
|
+
|
|
107
|
+
- Content-type switching (JSON/form/multipart) to hit different code paths
|
|
108
|
+
- Method alternation (GET performing state change; overrides via X-HTTP-Method-Override)
|
|
109
|
+
- Client recomputation: totals, taxes, discounts computed on client and accepted by server
|
|
110
|
+
- Cache/gateway differentials: stale decisions from CDN/APIM that are not identity-aware
|
|
111
|
+
|
|
112
|
+
## Special Contexts
|
|
113
|
+
|
|
114
|
+
### E-commerce
|
|
115
|
+
|
|
116
|
+
- Stack incompatible discounts via parallel apply; remove qualifying item after discount applied; retain free shipping after cart changes
|
|
117
|
+
- Modify shipping tier post-quote; abuse returns to keep product and refund
|
|
118
|
+
|
|
119
|
+
### Banking/Fintech
|
|
120
|
+
|
|
121
|
+
- Split transfers to bypass per-transaction threshold; schedule vs instant path inconsistencies
|
|
122
|
+
- Exploit grace periods on holds/authorizations to withdraw again before settlement
|
|
123
|
+
|
|
124
|
+
### SaaS/B2B
|
|
125
|
+
|
|
126
|
+
- Seat licensing: race seat assignment to exceed purchased seats; stale license checks in background tasks
|
|
127
|
+
- Usage metering: report late or duplicate usage to avoid billing or to over-consume
|
|
128
|
+
|
|
129
|
+
## Chaining Attacks
|
|
130
|
+
|
|
131
|
+
- Business logic + race: duplicate benefits before state updates
|
|
132
|
+
- Business logic + IDOR: operate on others' resources once a workflow leak reveals IDs
|
|
133
|
+
- Business logic + CSRF: force a victim to complete a sensitive step sequence
|
|
134
|
+
|
|
135
|
+
## Testing Methodology
|
|
136
|
+
|
|
137
|
+
1. **Enumerate state machine** - Per critical workflow (states, transitions, pre/post-conditions); note invariants
|
|
138
|
+
2. **Build Actor × Action × Resource matrix** - Unauth, basic user, premium, staff/admin; identify actions per role
|
|
139
|
+
3. **Test transitions** - Step skipping, repetition, reordering, late mutation
|
|
140
|
+
4. **Introduce variance** - Time, concurrency, channel (mobile/web/API/GraphQL), content-types
|
|
141
|
+
5. **Validate persistence boundaries** - All services, queues, and jobs re-enforce invariants
|
|
142
|
+
|
|
143
|
+
## Validation
|
|
144
|
+
|
|
145
|
+
1. Show an invariant violation (e.g., two refunds for one charge, negative inventory, exceeding quotas)
|
|
146
|
+
2. Provide side-by-side evidence for intended vs abused flows with the same principal
|
|
147
|
+
3. Demonstrate durability: the undesired state persists and is observable in authoritative sources (ledger, emails, admin views)
|
|
148
|
+
4. Quantify impact per action and at scale (unit loss × feasible repetitions)
|
|
149
|
+
|
|
150
|
+
## False Positives
|
|
151
|
+
|
|
152
|
+
- Promotional behavior explicitly allowed by policy (documented free trials, goodwill credits)
|
|
153
|
+
- Visual-only inconsistencies with no durable or exploitable state change
|
|
154
|
+
- Admin-only operations with proper audit and approvals
|
|
155
|
+
|
|
156
|
+
## Impact
|
|
157
|
+
|
|
158
|
+
- Direct financial loss (fraud, arbitrage, over-refunds, unpaid consumption)
|
|
159
|
+
- Regulatory/contractual violations (billing accuracy, consumer protection)
|
|
160
|
+
- Denial of inventory/services to legitimate users through resource exhaustion
|
|
161
|
+
- Privilege retention or unauthorized access to premium features
|
|
162
|
+
|
|
163
|
+
## Pro Tips
|
|
164
|
+
|
|
165
|
+
1. Start from invariants and ledgers, not UI—prove conservation of value breaks
|
|
166
|
+
2. Test with time and concurrency; many bugs only appear under pressure
|
|
167
|
+
3. Recompute totals server-side; never accept client math—flag when you observe otherwise
|
|
168
|
+
4. Treat idempotency and retries as first-class: verify key scope and persistence
|
|
169
|
+
5. Probe background workers and webhooks separately; they often skip auth and rule checks
|
|
170
|
+
6. Validate role/feature gates at the service that mutates state, not only at the edge
|
|
171
|
+
7. Explore end-of-period edges (month-end, trial end, DST) for rounding and window issues
|
|
172
|
+
8. Use minimal, auditable PoCs that demonstrate durable state change and exact loss
|
|
173
|
+
9. Chain with authorization tests (IDOR/Function-level access) to magnify impact
|
|
174
|
+
10. When in doubt, map the state machine; gaps appear where transitions lack server-side guards
|
|
175
|
+
|
|
176
|
+
## Summary
|
|
177
|
+
|
|
178
|
+
Business logic security is the enforcement of domain invariants under adversarial sequencing, timing, and inputs. If any step trusts the client or prior steps, expect abuse.
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: csrf
|
|
3
|
+
description: CSRF testing covering token bypass, SameSite cookies, CORS misconfigurations, and state-changing request abuse
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# CSRF
|
|
7
|
+
|
|
8
|
+
Cross-site request forgery abuses ambient authority (cookies, HTTP auth) across origins. Do not rely on CORS alone; enforce non-replayable tokens and strict origin checks for every state change.
|
|
9
|
+
|
|
10
|
+
## Attack Surface
|
|
11
|
+
|
|
12
|
+
**Session Types**
|
|
13
|
+
- Web apps with cookie-based sessions and HTTP auth
|
|
14
|
+
- JSON/REST, GraphQL (GET/persisted queries), file upload endpoints
|
|
15
|
+
|
|
16
|
+
**Authentication Flows**
|
|
17
|
+
- Login/logout, password/email change, MFA toggles
|
|
18
|
+
|
|
19
|
+
**OAuth/OIDC**
|
|
20
|
+
- Authorize, token, logout, disconnect/connect endpoints
|
|
21
|
+
|
|
22
|
+
## High-Value Targets
|
|
23
|
+
|
|
24
|
+
- Credentials and profile changes (email/password/phone)
|
|
25
|
+
- Payment and money movement, subscription/plan changes
|
|
26
|
+
- API key/secret generation, PAT rotation, SSH keys
|
|
27
|
+
- 2FA/TOTP enable/disable; backup codes; device trust
|
|
28
|
+
- OAuth connect/disconnect; logout; account deletion
|
|
29
|
+
- Admin/staff actions and impersonation flows
|
|
30
|
+
- File uploads/deletes; access control changes
|
|
31
|
+
|
|
32
|
+
## Reconnaissance
|
|
33
|
+
|
|
34
|
+
### Session and Cookies
|
|
35
|
+
|
|
36
|
+
- Inspect cookies: HttpOnly, Secure, SameSite (Strict/Lax/None)
|
|
37
|
+
- Lax allows cookies on top-level cross-site GET; None requires Secure
|
|
38
|
+
- Determine if Authorization headers or bearer tokens are used (generally not CSRF-prone) versus cookies (CSRF-prone)
|
|
39
|
+
|
|
40
|
+
### Token and Header Checks
|
|
41
|
+
|
|
42
|
+
- Locate anti-CSRF tokens (hidden inputs, meta tags, custom headers)
|
|
43
|
+
- Test removal, reuse across requests, reuse across sessions, binding to method/path
|
|
44
|
+
- Verify server checks Origin and/or Referer on state changes
|
|
45
|
+
- Test null/missing and cross-origin values
|
|
46
|
+
|
|
47
|
+
### Method and Content-Types
|
|
48
|
+
|
|
49
|
+
- Confirm whether GET, HEAD, or OPTIONS perform state changes
|
|
50
|
+
- Try simple content-types to avoid preflight: `application/x-www-form-urlencoded`, `multipart/form-data`, `text/plain`
|
|
51
|
+
- Probe parsers that auto-coerce `text/plain` or form-encoded bodies into JSON
|
|
52
|
+
|
|
53
|
+
### CORS Profile
|
|
54
|
+
|
|
55
|
+
- Identify `Access-Control-Allow-Origin` and `-Credentials`
|
|
56
|
+
- Overly permissive CORS is not a CSRF fix and can turn CSRF into data exfiltration
|
|
57
|
+
- Test per-endpoint CORS differences; preflight vs simple request behavior can diverge
|
|
58
|
+
|
|
59
|
+
## Key Vulnerabilities
|
|
60
|
+
|
|
61
|
+
### Navigation CSRF
|
|
62
|
+
|
|
63
|
+
- Auto-submitting form to target origin; works when cookies are sent and no token/origin checks are enforced
|
|
64
|
+
- Top-level GET navigation can trigger state if server misuses GET or links actions to GET callbacks
|
|
65
|
+
|
|
66
|
+
### Simple Content-Type CSRF
|
|
67
|
+
|
|
68
|
+
- `application/x-www-form-urlencoded` and `multipart/form-data` POSTs do not require preflight
|
|
69
|
+
- `text/plain` form bodies can slip through validators and be parsed server-side
|
|
70
|
+
|
|
71
|
+
### JSON CSRF
|
|
72
|
+
|
|
73
|
+
- If server parses JSON from `text/plain` or form-encoded bodies, craft parameters to reconstruct JSON
|
|
74
|
+
- Some frameworks accept JSON keys via form fields (e.g., `data[foo]=bar`) or treat duplicate keys leniently
|
|
75
|
+
|
|
76
|
+
### Login/Logout CSRF
|
|
77
|
+
|
|
78
|
+
- Force logout to clear CSRF tokens, then chain login CSRF to bind victim to attacker's account
|
|
79
|
+
- Login CSRF: submit attacker credentials to victim's browser; later actions occur under attacker's account
|
|
80
|
+
|
|
81
|
+
### OAuth/OIDC Flows
|
|
82
|
+
|
|
83
|
+
- Abuse authorize/logout endpoints reachable via GET or form POST without origin checks
|
|
84
|
+
- Exploit relaxed SameSite on top-level navigations
|
|
85
|
+
- Open redirects or loose redirect_uri validation can chain with CSRF to force unintended authorizations
|
|
86
|
+
|
|
87
|
+
### File and Action Endpoints
|
|
88
|
+
|
|
89
|
+
- File upload/delete often lack token checks; forge multipart requests to modify storage
|
|
90
|
+
- Admin actions exposed as simple POST links are frequently CSRFable
|
|
91
|
+
|
|
92
|
+
### GraphQL CSRF
|
|
93
|
+
|
|
94
|
+
- If queries/mutations are allowed via GET or persisted queries, exploit top-level navigation with encoded payloads
|
|
95
|
+
- Batched operations may hide mutations within a nominally safe request
|
|
96
|
+
|
|
97
|
+
### WebSocket CSRF
|
|
98
|
+
|
|
99
|
+
- Browsers send cookies on WebSocket handshake
|
|
100
|
+
- Enforce Origin checks server-side; without them, cross-site pages can open authenticated sockets and issue actions
|
|
101
|
+
|
|
102
|
+
## Bypass Techniques
|
|
103
|
+
|
|
104
|
+
### SameSite Nuance
|
|
105
|
+
|
|
106
|
+
- Lax-by-default cookies are sent on top-level cross-site GET but not POST
|
|
107
|
+
- Exploit GET state changes and GET-based confirmation steps
|
|
108
|
+
- Legacy or nonstandard clients may ignore SameSite; validate across browsers/devices
|
|
109
|
+
|
|
110
|
+
### Origin/Referer Obfuscation
|
|
111
|
+
|
|
112
|
+
- Sandbox/iframes can produce null Origin; some frameworks incorrectly accept null
|
|
113
|
+
- `about:blank`/`data:` URLs alter Referer
|
|
114
|
+
- Ensure server requires explicit Origin/Referer match
|
|
115
|
+
|
|
116
|
+
### Method Override
|
|
117
|
+
|
|
118
|
+
- Backends honoring `_method` or `X-HTTP-Method-Override` may allow destructive actions through a simple POST
|
|
119
|
+
|
|
120
|
+
### Token Weaknesses
|
|
121
|
+
|
|
122
|
+
- Accepting missing/empty tokens
|
|
123
|
+
- Tokens not tied to session, user, or path
|
|
124
|
+
- Tokens reused indefinitely; tokens in GET
|
|
125
|
+
- Double-submit cookie without Secure/HttpOnly, or with predictable token sources
|
|
126
|
+
|
|
127
|
+
### Content-Type Switching
|
|
128
|
+
|
|
129
|
+
- Switch between form, multipart, and `text/plain` to reach different code paths
|
|
130
|
+
- Use duplicate keys and array shapes to confuse parsers
|
|
131
|
+
|
|
132
|
+
### Header Manipulation
|
|
133
|
+
|
|
134
|
+
- Strip Referer via meta refresh or navigate from `about:blank`
|
|
135
|
+
- Test null Origin acceptance
|
|
136
|
+
- Leverage misconfigured CORS to add custom headers that servers mistakenly treat as CSRF tokens
|
|
137
|
+
|
|
138
|
+
## Special Contexts
|
|
139
|
+
|
|
140
|
+
### Mobile/SPA
|
|
141
|
+
|
|
142
|
+
- Deep links and embedded WebViews may auto-send cookies; trigger actions via crafted intents/links
|
|
143
|
+
- SPAs that rely solely on bearer tokens are less CSRF-prone, but hybrid apps mixing cookies and APIs can still be vulnerable
|
|
144
|
+
|
|
145
|
+
### Integrations
|
|
146
|
+
|
|
147
|
+
- Webhooks and back-office tools sometimes expose state-changing GETs intended for staff
|
|
148
|
+
- Confirm CSRF defenses there too
|
|
149
|
+
|
|
150
|
+
## Chaining Attacks
|
|
151
|
+
|
|
152
|
+
- CSRF + IDOR: force actions on other users' resources once references are known
|
|
153
|
+
- CSRF + Clickjacking: guide user interactions to bypass UI confirmations
|
|
154
|
+
- CSRF + OAuth mix-up: bind victim sessions to unintended clients
|
|
155
|
+
|
|
156
|
+
## Testing Methodology
|
|
157
|
+
|
|
158
|
+
1. **Inventory endpoints** - All state-changing endpoints including admin/staff
|
|
159
|
+
2. **Note request details** - Method, content-type, whether reachable via simple requests
|
|
160
|
+
3. **Assess session model** - Cookies with SameSite attrs, custom headers, tokens
|
|
161
|
+
4. **Check defenses** - Anti-CSRF tokens and Origin/Referer enforcement
|
|
162
|
+
5. **Attempt preflightless delivery** - Form POST, text/plain, multipart/form-data
|
|
163
|
+
6. **Test navigation** - Top-level GET navigation
|
|
164
|
+
7. **Cross-browser validation** - Behavior differs by SameSite and navigation context
|
|
165
|
+
|
|
166
|
+
## Validation
|
|
167
|
+
|
|
168
|
+
1. Demonstrate a cross-origin page that triggers a state change without user interaction beyond visiting
|
|
169
|
+
2. Show that removing the anti-CSRF control (token/header) is accepted, or that Origin/Referer are not verified
|
|
170
|
+
3. Prove behavior across at least two browsers or contexts (top-level nav vs XHR/fetch)
|
|
171
|
+
4. Provide before/after state evidence for the same account
|
|
172
|
+
5. If defenses exist, show the exact condition under which they are bypassed (content-type, method override, null Origin)
|
|
173
|
+
|
|
174
|
+
## False Positives
|
|
175
|
+
|
|
176
|
+
- Token verification present and required; Origin/Referer enforced consistently
|
|
177
|
+
- No cookies sent on cross-site requests (SameSite=Strict, no HTTP auth) and no state change via simple requests
|
|
178
|
+
- Only idempotent, non-sensitive operations affected
|
|
179
|
+
|
|
180
|
+
## Impact
|
|
181
|
+
|
|
182
|
+
- Account state changes (email/password/MFA), session hijacking via login CSRF
|
|
183
|
+
- Financial operations, administrative actions
|
|
184
|
+
- Durable authorization changes (role/permission flips, key rotations) and data loss
|
|
185
|
+
|
|
186
|
+
## Pro Tips
|
|
187
|
+
|
|
188
|
+
1. Prefer preflightless vectors (form-encoded, multipart, text/plain) and top-level GET if available
|
|
189
|
+
2. Test login/logout, OAuth connect/disconnect, and account linking first
|
|
190
|
+
3. Validate Origin/Referer behavior explicitly; do not assume frameworks enforce them
|
|
191
|
+
4. Toggle SameSite and observe differences across navigation vs XHR
|
|
192
|
+
5. For GraphQL, attempt GET queries or persisted queries that carry mutations
|
|
193
|
+
6. Always try method overrides and parser differentials
|
|
194
|
+
7. Combine with clickjacking when visual confirmations block CSRF
|
|
195
|
+
|
|
196
|
+
## Summary
|
|
197
|
+
|
|
198
|
+
CSRF is eliminated only when state changes require a secret the attacker cannot supply and the server verifies the caller's origin. Tokens and Origin checks must hold across methods, content-types, and transports.
|