strix-agent 0.4.0__py3-none-any.whl

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.
Files changed (118) hide show
  1. strix/__init__.py +0 -0
  2. strix/agents/StrixAgent/__init__.py +4 -0
  3. strix/agents/StrixAgent/strix_agent.py +89 -0
  4. strix/agents/StrixAgent/system_prompt.jinja +404 -0
  5. strix/agents/__init__.py +10 -0
  6. strix/agents/base_agent.py +518 -0
  7. strix/agents/state.py +163 -0
  8. strix/interface/__init__.py +4 -0
  9. strix/interface/assets/tui_styles.tcss +694 -0
  10. strix/interface/cli.py +230 -0
  11. strix/interface/main.py +500 -0
  12. strix/interface/tool_components/__init__.py +39 -0
  13. strix/interface/tool_components/agents_graph_renderer.py +123 -0
  14. strix/interface/tool_components/base_renderer.py +62 -0
  15. strix/interface/tool_components/browser_renderer.py +120 -0
  16. strix/interface/tool_components/file_edit_renderer.py +99 -0
  17. strix/interface/tool_components/finish_renderer.py +31 -0
  18. strix/interface/tool_components/notes_renderer.py +108 -0
  19. strix/interface/tool_components/proxy_renderer.py +255 -0
  20. strix/interface/tool_components/python_renderer.py +34 -0
  21. strix/interface/tool_components/registry.py +72 -0
  22. strix/interface/tool_components/reporting_renderer.py +53 -0
  23. strix/interface/tool_components/scan_info_renderer.py +64 -0
  24. strix/interface/tool_components/terminal_renderer.py +131 -0
  25. strix/interface/tool_components/thinking_renderer.py +29 -0
  26. strix/interface/tool_components/user_message_renderer.py +43 -0
  27. strix/interface/tool_components/web_search_renderer.py +28 -0
  28. strix/interface/tui.py +1274 -0
  29. strix/interface/utils.py +559 -0
  30. strix/llm/__init__.py +15 -0
  31. strix/llm/config.py +20 -0
  32. strix/llm/llm.py +465 -0
  33. strix/llm/memory_compressor.py +212 -0
  34. strix/llm/request_queue.py +87 -0
  35. strix/llm/utils.py +87 -0
  36. strix/prompts/README.md +64 -0
  37. strix/prompts/__init__.py +109 -0
  38. strix/prompts/cloud/.gitkeep +0 -0
  39. strix/prompts/coordination/root_agent.jinja +41 -0
  40. strix/prompts/custom/.gitkeep +0 -0
  41. strix/prompts/frameworks/fastapi.jinja +142 -0
  42. strix/prompts/frameworks/nextjs.jinja +126 -0
  43. strix/prompts/protocols/graphql.jinja +215 -0
  44. strix/prompts/reconnaissance/.gitkeep +0 -0
  45. strix/prompts/technologies/firebase_firestore.jinja +177 -0
  46. strix/prompts/technologies/supabase.jinja +189 -0
  47. strix/prompts/vulnerabilities/authentication_jwt.jinja +147 -0
  48. strix/prompts/vulnerabilities/broken_function_level_authorization.jinja +146 -0
  49. strix/prompts/vulnerabilities/business_logic.jinja +171 -0
  50. strix/prompts/vulnerabilities/csrf.jinja +174 -0
  51. strix/prompts/vulnerabilities/idor.jinja +195 -0
  52. strix/prompts/vulnerabilities/information_disclosure.jinja +222 -0
  53. strix/prompts/vulnerabilities/insecure_file_uploads.jinja +188 -0
  54. strix/prompts/vulnerabilities/mass_assignment.jinja +141 -0
  55. strix/prompts/vulnerabilities/open_redirect.jinja +177 -0
  56. strix/prompts/vulnerabilities/path_traversal_lfi_rfi.jinja +142 -0
  57. strix/prompts/vulnerabilities/race_conditions.jinja +164 -0
  58. strix/prompts/vulnerabilities/rce.jinja +154 -0
  59. strix/prompts/vulnerabilities/sql_injection.jinja +151 -0
  60. strix/prompts/vulnerabilities/ssrf.jinja +135 -0
  61. strix/prompts/vulnerabilities/subdomain_takeover.jinja +155 -0
  62. strix/prompts/vulnerabilities/xss.jinja +169 -0
  63. strix/prompts/vulnerabilities/xxe.jinja +184 -0
  64. strix/runtime/__init__.py +19 -0
  65. strix/runtime/docker_runtime.py +399 -0
  66. strix/runtime/runtime.py +29 -0
  67. strix/runtime/tool_server.py +205 -0
  68. strix/telemetry/__init__.py +4 -0
  69. strix/telemetry/tracer.py +337 -0
  70. strix/tools/__init__.py +64 -0
  71. strix/tools/agents_graph/__init__.py +16 -0
  72. strix/tools/agents_graph/agents_graph_actions.py +621 -0
  73. strix/tools/agents_graph/agents_graph_actions_schema.xml +226 -0
  74. strix/tools/argument_parser.py +121 -0
  75. strix/tools/browser/__init__.py +4 -0
  76. strix/tools/browser/browser_actions.py +236 -0
  77. strix/tools/browser/browser_actions_schema.xml +183 -0
  78. strix/tools/browser/browser_instance.py +533 -0
  79. strix/tools/browser/tab_manager.py +342 -0
  80. strix/tools/executor.py +305 -0
  81. strix/tools/file_edit/__init__.py +4 -0
  82. strix/tools/file_edit/file_edit_actions.py +141 -0
  83. strix/tools/file_edit/file_edit_actions_schema.xml +128 -0
  84. strix/tools/finish/__init__.py +4 -0
  85. strix/tools/finish/finish_actions.py +174 -0
  86. strix/tools/finish/finish_actions_schema.xml +45 -0
  87. strix/tools/notes/__init__.py +14 -0
  88. strix/tools/notes/notes_actions.py +191 -0
  89. strix/tools/notes/notes_actions_schema.xml +150 -0
  90. strix/tools/proxy/__init__.py +20 -0
  91. strix/tools/proxy/proxy_actions.py +101 -0
  92. strix/tools/proxy/proxy_actions_schema.xml +267 -0
  93. strix/tools/proxy/proxy_manager.py +785 -0
  94. strix/tools/python/__init__.py +4 -0
  95. strix/tools/python/python_actions.py +47 -0
  96. strix/tools/python/python_actions_schema.xml +131 -0
  97. strix/tools/python/python_instance.py +172 -0
  98. strix/tools/python/python_manager.py +131 -0
  99. strix/tools/registry.py +196 -0
  100. strix/tools/reporting/__init__.py +6 -0
  101. strix/tools/reporting/reporting_actions.py +63 -0
  102. strix/tools/reporting/reporting_actions_schema.xml +30 -0
  103. strix/tools/terminal/__init__.py +4 -0
  104. strix/tools/terminal/terminal_actions.py +35 -0
  105. strix/tools/terminal/terminal_actions_schema.xml +146 -0
  106. strix/tools/terminal/terminal_manager.py +151 -0
  107. strix/tools/terminal/terminal_session.py +447 -0
  108. strix/tools/thinking/__init__.py +4 -0
  109. strix/tools/thinking/thinking_actions.py +18 -0
  110. strix/tools/thinking/thinking_actions_schema.xml +52 -0
  111. strix/tools/web_search/__init__.py +4 -0
  112. strix/tools/web_search/web_search_actions.py +80 -0
  113. strix/tools/web_search/web_search_actions_schema.xml +83 -0
  114. strix_agent-0.4.0.dist-info/LICENSE +201 -0
  115. strix_agent-0.4.0.dist-info/METADATA +282 -0
  116. strix_agent-0.4.0.dist-info/RECORD +118 -0
  117. strix_agent-0.4.0.dist-info/WHEEL +4 -0
  118. strix_agent-0.4.0.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,147 @@
1
+ <authentication_jwt_guide>
2
+ <title>AUTHENTICATION AND JWT/OIDC</title>
3
+
4
+ <critical>JWT/OIDC failures often enable token forgery, token confusion, cross-service acceptance, and durable account takeover. Do not trust headers, claims, or token opacity without strict validation bound to issuer, audience, key, and context.</critical>
5
+
6
+ <scope>
7
+ - Web/mobile/API authentication using JWT (JWS/JWE) and OIDC/OAuth2
8
+ - Access vs ID tokens, refresh tokens, device/PKCE/Backchannel flows
9
+ - First-party and microservices verification, gateways, and JWKS distribution
10
+ </scope>
11
+
12
+ <methodology>
13
+ 1. Inventory issuers and consumers: identity providers, API gateways, services, mobile/web clients.
14
+ 2. Capture real tokens (access and ID) for multiple roles. Note header, claims, signature, and verification endpoints (/.well-known, /jwks.json).
15
+ 3. Build a matrix: Token Type × Audience × Service; attempt cross-use (wrong audience/issuer/service) and observe acceptance.
16
+ 4. Mutate headers (alg, kid, jku/x5u/jwk, typ/cty/crit), claims (iss/aud/azp/sub/nbf/iat/exp/scope/nonce), and signatures; verify what is actually enforced.
17
+ </methodology>
18
+
19
+ <discovery_techniques>
20
+ <endpoints>
21
+ - Well-known: /.well-known/openid-configuration, /oauth2/.well-known/openid-configuration
22
+ - Keys: /jwks.json, rotating key endpoints, tenant-specific JWKS
23
+ - Auth: /authorize, /token, /introspect, /revoke, /logout, device code endpoints
24
+ - App: /login, /callback, /refresh, /me, /session, /impersonate
25
+ </endpoints>
26
+
27
+ <token_features>
28
+ - Headers: {% raw %}{"alg":"RS256","kid":"...","typ":"JWT","jku":"...","x5u":"...","jwk":{...}}{% endraw %}
29
+ - Claims: {% raw %}{"iss":"...","aud":"...","azp":"...","sub":"user","scope":"...","exp":...,"nbf":...,"iat":...}{% endraw %}
30
+ - Formats: JWS (signed), JWE (encrypted). Note unencoded payload option ("b64":false) and critical headers ("crit").
31
+ </token_features>
32
+ </discovery_techniques>
33
+
34
+ <exploitation_techniques>
35
+ <signature_verification>
36
+ - RS256→HS256 confusion: change alg to HS256 and use the RSA public key as HMAC secret if algorithm is not pinned
37
+ - "none" algorithm acceptance: set {% raw %}"alg":"none"{% endraw %} and drop the signature if libraries accept it
38
+ - ECDSA malleability/misuse: weak verification settings accepting non-canonical signatures
39
+ </signature_verification>
40
+
41
+ <header_manipulation>
42
+ - kid injection: path traversal {% raw %}../../../../keys/prod.key{% endraw %}, SQL/command/template injection in key lookup, or pointing to world-readable files
43
+ - jku/x5u abuse: host attacker-controlled JWKS/X509 chain; if not pinned/whitelisted, server fetches and trusts attacker keys
44
+ - jwk header injection: embed attacker JWK in header; some libraries prefer inline JWK over server-configured keys
45
+ - SSRF via remote key fetch: exploit JWKS URL fetching to reach internal hosts
46
+ </header_manipulation>
47
+
48
+ <key_and_cache_issues>
49
+ - JWKS caching TTL and key rollover: accept obsolete keys; race rotation windows; missing kid pinning → accept any matching kty/alg
50
+ - Mixed environments: same secrets across dev/stage/prod; key reuse across tenants or services
51
+ - Fallbacks: verification succeeds when kid not found by trying all keys or no keys (implementation bugs)
52
+ </key_and_cache_issues>
53
+
54
+ <claims_validation_gaps>
55
+ - iss/aud/azp not enforced: cross-service token reuse; accept tokens from any issuer or wrong audience
56
+ - scope/roles fully trusted from token: server does not re-derive authorization; privilege inflation via claim edits when signature checks are weak
57
+ - exp/nbf/iat not enforced or large clock skew tolerance; accept long-expired or not-yet-valid tokens
58
+ - typ/cty not enforced: accept ID token where access token required (token confusion)
59
+ </claims_validation_gaps>
60
+
61
+ <token_confusion_and_oidc>
62
+ - Access vs ID token swap: use ID token against APIs when they only verify signature but not audience/typ
63
+ - OIDC mix-up: redirect_uri and client mix-ups causing tokens for Client A to be redeemed at Client B
64
+ - PKCE downgrades: missing S256 requirement; accept plain or absent code_verifier
65
+ - State/nonce weaknesses: predictable or missing → CSRF/logical interception of login\n- Device/Backchannel flows: codes and tokens accepted by unintended clients or services
66
+ </token_confusion_and_oidc>
67
+
68
+ <refresh_and_session>
69
+ - Refresh token rotation not enforced: reuse old refresh token indefinitely; no reuse detection
70
+ - Long-lived JWTs with no revocation: persistent access post-logout
71
+ - Session fixation: bind new tokens to attacker-controlled session identifiers or cookies
72
+ </refresh_and_session>
73
+
74
+ <transport_and_storage>
75
+ - Token in localStorage/sessionStorage: susceptible to XSS exfiltration; cookie vs header trade-offs with SameSite/CSRF
76
+ - Insecure CORS: wildcard origins with credentialed requests expose tokens and protected responses
77
+ - TLS and cookie flags: missing Secure/HttpOnly; lack of mTLS or DPoP/"cnf" binding permits replay from another device
78
+ </transport_and_storage>
79
+ </exploitation_techniques>
80
+
81
+ <advanced_techniques>
82
+ <microservices_and_gateways>
83
+ - Audience mismatch: internal services verify signature but ignore aud → accept tokens for other services
84
+ - Header trust: edge or gateway injects X-User-Id; backend trusts it over token claims
85
+ - Asynchronous consumers: workers process messages with bearer tokens but skip verification on replay
86
+ </microservices_and_gateways>
87
+
88
+ <jws_edge_cases>
89
+ - Unencoded payload (b64=false) with crit header: libraries mishandle verification paths
90
+ - Nested JWT (JWT-in-JWT) verification order errors; outer token accepted while inner claims ignored
91
+ </jws_edge_cases>
92
+
93
+ <special_contexts>
94
+ <mobile>
95
+ - Deep-link/redirect handling bugs leak codes/tokens; insecure WebView bridges exposing tokens
96
+ - Token storage in plaintext files/SQLite/Keychain/SharedPrefs; backup/adb accessible
97
+ </mobile>
98
+
99
+ <sso_federation>
100
+ - Misconfigured trust between multiple IdPs/SPs, mixed metadata, or stale keys lead to acceptance of foreign tokens
101
+ </sso_federation>
102
+ </special_contexts>
103
+
104
+ <chaining_attacks>
105
+ - XSS → token theft → replay across services with weak audience checks
106
+ - SSRF → fetch private JWKS → sign tokens accepted by internal services
107
+ - Host header poisoning → OIDC redirect_uri poisoning → code capture
108
+ - IDOR in sessions/impersonation endpoints → mint tokens for other users
109
+ </chaining_attacks>
110
+
111
+ <validation>
112
+ 1. Show forged or cross-context token acceptance (wrong alg, wrong audience/issuer, or attacker-signed JWKS).
113
+ 2. Demonstrate access token vs ID token confusion at an API.
114
+ 3. Prove refresh token reuse without rotation detection or revocation.
115
+ 4. Confirm header abuse (kid/jku/x5u/jwk) leading to key selection under attacker control.
116
+ 5. Provide owner vs non-owner evidence with identical requests differing only in token context.
117
+ </validation>
118
+
119
+ <false_positives>
120
+ - Token rejected due to strict audience/issuer enforcement
121
+ - Key pinning with JWKS whitelist and TLS validation
122
+ - Short-lived tokens with rotation and revocation on logout
123
+ - ID token not accepted by APIs that require access tokens
124
+ </false_positives>
125
+
126
+ <impact>
127
+ - Account takeover and durable session persistence
128
+ - Privilege escalation via claim manipulation or cross-service acceptance
129
+ - Cross-tenant or cross-application data access
130
+ - Token minting by attacker-controlled keys or endpoints
131
+ </impact>
132
+
133
+ <pro_tips>
134
+ 1. Pin verification to issuer and audience; log and diff claim sets across services.
135
+ 2. Attempt RS256→HS256 and "none" first only if algorithm pinning is unclear; otherwise focus on header key control (kid/jku/x5u/jwk).
136
+ 3. Test token reuse across all services; many backends only check signature, not audience/typ.
137
+ 4. Exploit JWKS caching and rotation races; try retired keys and missing kid fallbacks.
138
+ 5. Exercise OIDC flows with PKCE/state/nonce variants and mixed clients; look for mix-up.
139
+ 6. Try DPoP/mTLS absence to replay tokens from different devices.
140
+ 7. Treat refresh as its own surface: rotation, reuse detection, and audience scoping.
141
+ 8. Validate every acceptance path: gateway, service, worker, WebSocket, and gRPC.
142
+ 9. Favor minimal PoCs that clearly show cross-context acceptance and durable access.
143
+ 10. When in doubt, assume verification differs per stack (mobile vs web vs gateway) and test each.
144
+ </pro_tips>
145
+
146
+ <remember>Verification must bind the token to the correct issuer, audience, key, and client context on every acceptance path. Any missing binding enables forgery or confusion.</remember>
147
+ </authentication_jwt_guide>
@@ -0,0 +1,146 @@
1
+ <broken_function_level_authorization_guide>
2
+ <title>BROKEN FUNCTION LEVEL AUTHORIZATION (BFLA)</title>
3
+
4
+ <critical>BFLA is action-level authorization failure: callers invoke functions (endpoints, mutations, admin tools) they are not entitled to. It appears when enforcement differs across transports, gateways, roles, or when services trust client hints. Bind subject × action at the service that performs the action.</critical>
5
+
6
+ <scope>
7
+ - Vertical authz: privileged/admin/staff-only actions reachable by basic users
8
+ - Feature gates: toggles enforced at edge/UI, not at core services
9
+ - Transport drift: REST vs GraphQL vs gRPC vs WebSocket with inconsistent checks
10
+ - Gateway trust: backends trust X-User-Id/X-Role injected by proxies/edges
11
+ - Background workers/jobs performing actions without re-checking authz
12
+ </scope>
13
+
14
+ <methodology>
15
+ 1. Build an Actor × Action matrix with at least: unauth, basic, premium, staff/admin. Enumerate actions (create/update/delete, approve/cancel, impersonate, export, invite, role-change, credit/refund).
16
+ 2. Obtain tokens/sessions for each role. Exercise every action across all transports and encodings (JSON, form, multipart), including method overrides.
17
+ 3. Vary headers and contextual selectors (org/tenant/project) and test behavior behind gateway vs direct-to-service.
18
+ 4. Include background flows: job creation/finalization, webhooks, queues. Confirm re-validation of authz in consumers.
19
+ </methodology>
20
+
21
+ <discovery_techniques>
22
+ <surface_enumeration>
23
+ - Admin/staff consoles and APIs, support tools, internal-only endpoints exposed via gateway
24
+ - Hidden buttons and disabled UI paths (feature-flagged) mapped to still-live endpoints
25
+ - GraphQL schemas: mutations and admin-only fields/types; gRPC service descriptors (reflection)
26
+ - Mobile clients often reveal extra endpoints/roles in app bundles or network logs
27
+ </surface_enumeration>
28
+
29
+ <signals>
30
+ - 401/403 on UI but 200 via direct API call; differing status codes across transports
31
+ - Actions succeed via background jobs when direct call is denied
32
+ - Changing only headers (role/org) alters access without token change
33
+ </signals>
34
+
35
+ <high_value_actions>
36
+ - Role/permission changes, impersonation/sudo, invite/accept into orgs
37
+ - Approve/void/refund/credit issuance, price/plan overrides
38
+ - Export/report generation, data deletion, account suspension/reactivation
39
+ - Feature flag toggles, quota/grant adjustments, license/seat changes
40
+ - Security settings: 2FA reset, email/phone verification overrides
41
+ </high_value_actions>
42
+
43
+ <exploitation_techniques>
44
+ <verb_drift_and_aliases>
45
+ - Alternate methods: GET performing state change; POST vs PUT vs PATCH differences; X-HTTP-Method-Override/_method
46
+ - Alternate endpoints performing the same action with weaker checks (legacy vs v2, mobile vs web)
47
+ </verb_drift_and_aliases>
48
+
49
+ <edge_vs_core_mismatch>
50
+ - Edge blocks an action but core service RPC accepts it directly; call internal service via exposed API route or SSRF
51
+ - Gateway-injected identity headers override token claims; supply conflicting headers to test precedence
52
+ </edge_vs_core_mismatch>
53
+
54
+ <feature_flag_bypass>
55
+ - Client-checked feature gates; call backend endpoints directly
56
+ - Admin-only mutations exposed but hidden in UI; invoke via GraphQL or gRPC tools
57
+ </feature_flag_bypass>
58
+
59
+ <batch_job_paths>
60
+ - Create export/import jobs where creation is allowed but finalize/approve lacks authz; finalize others' jobs
61
+ - Replay webhooks/background tasks endpoints that perform privileged actions without verifying caller
62
+ </batch_job_paths>
63
+
64
+ <content_type_paths>
65
+ - JSON vs form vs multipart handlers using different middleware: send the action via the most permissive parser
66
+ </content_type_paths>
67
+ </exploitation_techniques>
68
+
69
+ <advanced_techniques>
70
+ <graphql>
71
+ - Resolver-level checks per mutation/field; do not assume top-level auth covers nested mutations or admin fields
72
+ - Abuse aliases/batching to sneak privileged fields; persisted queries sometimes bypass auth transforms
73
+ - Example:
74
+ {% raw %}
75
+ mutation Promote($id:ID!){
76
+ a: updateUser(id:$id, role: ADMIN){ id role }
77
+ }
78
+ {% endraw %}
79
+ </graphql>
80
+
81
+ <grpc>
82
+ - Method-level auth via interceptors must enforce audience/roles; probe direct gRPC with tokens of lower role
83
+ - Reflection lists services/methods; call admin methods that the gateway hid
84
+ </grpc>
85
+
86
+ <websocket>
87
+ - Handshake-only auth: ensure per-message authorization on privileged events (e.g., admin:impersonate)
88
+ - Try emitting privileged actions after joining standard channels
89
+ </websocket>
90
+
91
+ <multi_tenant>
92
+ - Actions requiring tenant admin enforced only by header/subdomain; attempt cross-tenant admin actions by switching selectors with same token
93
+ </multi_tenant>
94
+
95
+ <microservices>
96
+ - Internal RPCs trust upstream checks; reach them through exposed endpoints or SSRF; verify each service re-enforces authz
97
+ </microservices>
98
+
99
+ <bypass_techniques>
100
+ <header_trust>
101
+ - Supply X-User-Id/X-Role/X-Organization headers; remove or contradict token claims; observe which source wins
102
+ </header_trust>
103
+
104
+ <route_shadowing>
105
+ - Legacy/alternate routes (e.g., /admin/v1 vs /v2/admin) that skip new middleware chains
106
+ </route_shadowing>
107
+
108
+ <idempotency_and_retries>
109
+ - Retry or replay finalize/approve endpoints that apply state without checking actor on each call
110
+ </idempotency_and_retries>
111
+
112
+ <cache_key_confusion>
113
+ - Cached authorization decisions at edge leading to cross-user reuse; test with Vary and session swaps
114
+ </cache_key_confusion>
115
+ </bypass_techniques>
116
+
117
+ <validation>
118
+ 1. Show a lower-privileged principal successfully invokes a restricted action (same inputs) while the proper role succeeds and another lower role fails.
119
+ 2. Provide evidence across at least two transports or encodings demonstrating inconsistent enforcement.
120
+ 3. Demonstrate that removing/altering client-side gates (buttons/flags) does not affect backend success.
121
+ 4. Include durable state change proof: before/after snapshots, audit logs, and authoritative sources.
122
+ </validation>
123
+
124
+ <false_positives>
125
+ - Read-only endpoints mislabeled as admin but publicly documented
126
+ - Feature toggles intentionally open to all roles for preview/beta with clear policy
127
+ - Simulated environments where admin endpoints are stubbed with no side effects
128
+ </false_positives>
129
+
130
+ <impact>
131
+ - Privilege escalation to admin/staff actions
132
+ - Monetary/state impact: refunds/credits/approvals without authorization
133
+ - Tenant-wide configuration changes, impersonation, or data deletion
134
+ - Compliance and audit violations due to bypassed approval workflows
135
+ </impact>
136
+
137
+ <pro_tips>
138
+ 1. Start from the role matrix; test every action with basic vs admin tokens across REST/GraphQL/gRPC.
139
+ 2. Diff middleware stacks between routes; weak chains often exist on legacy or alternate encodings.
140
+ 3. Inspect gateways for identity header injection; never trust client-provided identity.
141
+ 4. Treat jobs/webhooks as first-class: finalize/approve must re-check the actor.
142
+ 5. Prefer minimal PoCs: one request that flips a privileged field or invokes an admin method with a basic token.
143
+ </pro_tips>
144
+
145
+ <remember>Authorization must bind the actor to the specific action at the service boundary on every request and message. UI gates, gateways, or prior steps do not substitute for function-level checks.</remember>
146
+ </broken_function_level_authorization_guide>
@@ -0,0 +1,171 @@
1
+ <business_logic_flaws_guide>
2
+ <title>BUSINESS LOGIC FLAWS</title>
3
+
4
+ <critical>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.</critical>
5
+
6
+ <scope>
7
+ - Financial logic: pricing, discounts, payments, refunds, credits, chargebacks
8
+ - Account lifecycle: signup, upgrade/downgrade, trial, suspension, deletion
9
+ - Authorization-by-logic: feature gates, role transitions, approval workflows
10
+ - Quotas/limits: rate/usage limits, inventory, entitlements, seat licensing
11
+ - Multi-tenant isolation: cross-organization data or action bleed
12
+ - Event-driven flows: jobs, webhooks, sagas, compensations, idempotency
13
+ </scope>
14
+
15
+ <methodology>
16
+ 1. Enumerate a state machine per critical workflow (states, transitions, pre/post-conditions). Note invariants (e.g., "refund ≤ captured amount").
17
+ 2. Build an Actor × Action × Resource matrix with at least: unauth, basic user, premium, staff/admin; identify actions per role.
18
+ 3. For each transition, test step skipping, repetition, reordering, and late mutation (modify inputs after validation but before commit).
19
+ 4. Introduce time, concurrency, and channel variance: repeat with parallel requests, different content-types, mobile/web/API/GraphQL.
20
+ 5. Validate persistence boundaries: verify that all services, queues, and jobs re-enforce invariants (no trust in upstream validation).
21
+ </methodology>
22
+
23
+ <discovery_techniques>
24
+ <workflow_mapping>
25
+ - Derive endpoints from the UI and proxy/network logs; map hidden/undocumented API calls, especially finalize/confirm endpoints
26
+ - Identify tokens/flags: stepToken, paymentIntentId, orderStatus, reviewState, approvalId; test reuse across users/sessions
27
+ - Document invariants: conservation of value (ledger balance), uniqueness (idempotency), monotonicity (non-decreasing counters), exclusivity (one active subscription)
28
+ </workflow_mapping>
29
+
30
+ <input_surface>
31
+ - Hidden fields and client-computed totals; server must recompute on trusted sources
32
+ - Alternate encodings and shapes: arrays instead of scalars, objects with unexpected keys, null/empty/0/negative, scientific notation
33
+ - Business selectors: currency, locale, timezone, tax region; vary to trigger rounding and ruleset changes
34
+ </input_surface>
35
+
36
+ <state_time_axes>
37
+ - Replays: resubmit stale finalize/confirm requests
38
+ - Out-of-order: call finalize before verify; refund before capture; cancel after ship
39
+ - Time windows: end-of-day/month cutovers, daylight saving, grace periods, trial expiry edges
40
+ </state_time_axes>
41
+ </discovery_techniques>
42
+
43
+ <high_value_targets>
44
+ - Pricing/cart: price locks, quote to order, tax/shipping computation
45
+ - Discount engines: stacking, mutual exclusivity, scope (cart vs item), once-per-user enforcement
46
+ - Payments: auth/capture/void/refund sequences, partials, split tenders, chargebacks, idempotency keys
47
+ - Credits/gift cards/vouchers: issuance, redemption, reversal, expiry, transferability
48
+ - Subscriptions: proration, upgrade/downgrade, trial extension, seat counts, meter reporting
49
+ - Refunds/returns/RMAs: multi-item partials, restocking fees, return window edges
50
+ - Admin/staff operations: impersonation, manual adjustments, credit/refund issuance, account flags
51
+ - Quotas/limits: daily/monthly usage, inventory reservations, feature usage counters
52
+ </high_value_targets>
53
+
54
+ <exploitation_techniques>
55
+ <state_machine_abuse>
56
+ - Skip or reorder steps via direct API calls; verify server enforces preconditions on each transition
57
+ - Replay prior steps with altered parameters (e.g., swap price after approval but before capture)
58
+ - Split a single constrained action into many sub-actions under the threshold (limit slicing)
59
+ </state_machine_abuse>
60
+
61
+ <concurrency_and_idempotency>
62
+ - Parallelize identical operations to bypass atomic checks (create, apply, redeem, transfer)
63
+ - Abuse idempotency: key scoped to path but not principal → reuse other users' keys; or idempotency stored only in cache
64
+ - Message reprocessing: queue workers re-run tasks on retry without idempotent guards; cause duplicate fulfillment/refund
65
+ </concurrency_and_idempotency>
66
+
67
+ <numeric_and_currency>
68
+ - Floating point vs decimal rounding; rounding/truncation favoring attacker at boundaries
69
+ - Cross-currency arbitrage: buy in currency A, refund in B at stale rates; tax rounding per-item vs per-order
70
+ - Negative amounts, zero-price, free shipping thresholds, minimum/maximum guardrails
71
+ </numeric_and_currency>
72
+
73
+ <quotas_limits_inventory>
74
+ - Off-by-one and time-bound resets (UTC vs local); pre-warm at T-1s and post-fire at T+1s
75
+ - Reservation/hold leaks: reserve multiple, complete one, release not enforced; backorder logic inconsistencies
76
+ - Distributed counters without strong consistency enabling double-consumption
77
+ </quotas_limits_inventory>
78
+
79
+ <refunds_chargebacks>
80
+ - Double-refund: refund via UI and support tool; refund partials summing above captured amount
81
+ - Refund after benefits consumed (downloaded digital goods, shipped items) due to missing post-consumption checks
82
+ </refunds_chargebacks>
83
+
84
+ <feature_gates_and_roles>
85
+ - Feature flags enforced client-side or at edge but not in core services; toggle names guessed or fallback to default-enabled
86
+ - Role transitions leaving stale capabilities (retain premium after downgrade; retain admin endpoints after demotion)
87
+ </feature_gates_and_roles>
88
+
89
+ <advanced_techniques>
90
+ <event_driven_sagas>
91
+ - Saga/compensation gaps: trigger compensation without original success; or execute success twice without compensation
92
+ - Outbox/Inbox patterns missing idempotency → duplicate downstream side effects
93
+ - Cron/backfill jobs operating outside request-time authorization; mutate state broadly
94
+ </event_driven_sagas>
95
+
96
+ <microservices_boundaries>
97
+ - Cross-service assumption mismatch: one service validates total, another trusts line items; alter between calls
98
+ - Header trust: internal services trusting X-Role or X-User-Id from untrusted edges
99
+ - Partial failure windows: two-phase actions where phase 1 commits without phase 2, leaving exploitable intermediate state
100
+ </microservices_boundaries>
101
+
102
+ <multi_tenant_isolation>
103
+ - Tenant-scoped counters and credits updated without tenant key in the where-clause; leak across orgs
104
+ - Admin aggregate views allowing actions that impact other tenants due to missing per-tenant enforcement
105
+ </multi_tenant_isolation>
106
+
107
+ <bypass_techniques>
108
+ - Content-type switching (json/form/multipart) to hit different code paths
109
+ - Method alternation (GET performing state change; overrides via X-HTTP-Method-Override)
110
+ - Client recomputation: totals, taxes, discounts computed on client and accepted by server
111
+ - Cache/gateway differentials: stale decisions from CDN/APIM that are not identity-aware
112
+ </bypass_techniques>
113
+
114
+ <special_contexts>
115
+ <ecommerce>
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
+ </ecommerce>
119
+
120
+ <banking_fintech>
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
+ </banking_fintech>
124
+
125
+ <saas_b2b>
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
+ </saas_b2b>
129
+ </special_contexts>
130
+
131
+ <chaining_attacks>
132
+ - Business logic + race: duplicate benefits before state updates
133
+ - Business logic + IDOR: operate on others' resources once a workflow leak reveals IDs
134
+ - Business logic + CSRF: force a victim to complete a sensitive step sequence
135
+ </chaining_attacks>
136
+
137
+ <validation>
138
+ 1. Show an invariant violation (e.g., two refunds for one charge, negative inventory, exceeding quotas).
139
+ 2. Provide side-by-side evidence for intended vs abused flows with the same principal.
140
+ 3. Demonstrate durability: the undesired state persists and is observable in authoritative sources (ledger, emails, admin views).
141
+ 4. Quantify impact per action and at scale (unit loss × feasible repetitions).
142
+ </validation>
143
+
144
+ <false_positives>
145
+ - Promotional behavior explicitly allowed by policy (documented free trials, goodwill credits)
146
+ - Visual-only inconsistencies with no durable or exploitable state change
147
+ - Admin-only operations with proper audit and approvals
148
+ </false_positives>
149
+
150
+ <impact>
151
+ - Direct financial loss (fraud, arbitrage, over-refunds, unpaid consumption)
152
+ - Regulatory/contractual violations (billing accuracy, consumer protection)
153
+ - Denial of inventory/services to legitimate users through resource exhaustion
154
+ - Privilege retention or unauthorized access to premium features
155
+ </impact>
156
+
157
+ <pro_tips>
158
+ 1. Start from invariants and ledgers, not UI—prove conservation of value breaks.
159
+ 2. Test with time and concurrency; many bugs only appear under pressure.
160
+ 3. Recompute totals server-side; never accept client math—flag when you observe otherwise.
161
+ 4. Treat idempotency and retries as first-class: verify key scope and persistence.
162
+ 5. Probe background workers and webhooks separately; they often skip auth and rule checks.
163
+ 6. Validate role/feature gates at the service that mutates state, not only at the edge.
164
+ 7. Explore end-of-period edges (month-end, trial end, DST) for rounding and window issues.
165
+ 8. Use minimal, auditable PoCs that demonstrate durable state change and exact loss.
166
+ 9. Chain with authorization tests (IDOR/Function-level access) to magnify impact.
167
+ 10. When in doubt, map the state machine; gaps appear where transitions lack server-side guards.
168
+ </pro_tips>
169
+
170
+ <remember>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.</remember>
171
+ </business_logic_flaws_guide>
@@ -0,0 +1,174 @@
1
+ <csrf_vulnerability_guide>
2
+ <title>CROSS-SITE REQUEST FORGERY (CSRF)</title>
3
+
4
+ <critical>CSRF 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.</critical>
5
+
6
+ <scope>
7
+ - Web apps with cookie-based sessions and HTTP auth
8
+ - JSON/REST, GraphQL (GET/persisted queries), file upload endpoints
9
+ - Authentication flows: login/logout, password/email change, MFA toggles
10
+ - OAuth/OIDC: authorize, token, logout, disconnect/connect
11
+ </scope>
12
+
13
+ <methodology>
14
+ 1. Inventory all state-changing endpoints (including admin/staff) and note method, content-type, and whether they are reachable via top-level navigation or simple requests (no preflight).
15
+ 2. For each, determine session model (cookies with SameSite attrs, custom headers, tokens) and whether server enforces anti-CSRF tokens and Origin/Referer.
16
+ 3. Attempt preflightless delivery (form POST, text/plain, multipart/form-data) and top-level GET navigation.
17
+ 4. Validate across browsers; behavior differs by SameSite and navigation context.
18
+ </methodology>
19
+
20
+ <high_value_targets>
21
+ - Credentials and profile changes (email/password/phone)
22
+ - Payment and money movement, subscription/plan changes
23
+ - API key/secret generation, PAT rotation, SSH keys
24
+ - 2FA/TOTP enable/disable; backup codes; device trust
25
+ - OAuth connect/disconnect; logout; account deletion
26
+ - Admin/staff actions and impersonation flows
27
+ - File uploads/deletes; access control changes
28
+ </high_value_targets>
29
+
30
+ <discovery_techniques>
31
+ <session_and_cookies>
32
+ - Inspect cookies: HttpOnly, Secure, SameSite (Strict/Lax/None). Note that Lax allows cookies on top-level cross-site GET; None requires Secure.
33
+ - Determine if Authorization headers or bearer tokens are used (generally not CSRF-prone) versus cookies (CSRF-prone).
34
+ </session_and_cookies>
35
+
36
+ <token_and_header_checks>
37
+ - Locate anti-CSRF tokens (hidden inputs, meta tags, custom headers). Test removal, reuse across requests, reuse across sessions, and binding to method/path.
38
+ - Verify server checks Origin and/or Referer on state changes; test null/missing and cross-origin values.
39
+ </token_and_header_checks>
40
+
41
+ <method_and_content_types>
42
+ - Confirm whether GET, HEAD, or OPTIONS perform state changes.
43
+ - Try simple content-types to avoid preflight: application/x-www-form-urlencoded, multipart/form-data, text/plain.
44
+ - Probe parsers that auto-coerce text/plain or form-encoded bodies into JSON.
45
+ </method_and_content_types>
46
+
47
+ <cors_profile>
48
+ - Identify Access-Control-Allow-Origin and -Credentials. Overly permissive CORS is not a CSRF fix and can turn CSRF into data exfiltration.
49
+ - Test per-endpoint CORS differences; preflight vs simple request behavior can diverge.
50
+ </cors_profile>
51
+ </discovery_techniques>
52
+
53
+ <exploitation_techniques>
54
+ <navigation_csrf>
55
+ - Auto-submitting form to target origin; works when cookies are sent and no token/origin checks are enforced.
56
+ - Top-level GET navigation can trigger state if server misuses GET or links actions to GET callbacks.
57
+ </navigation_csrf>
58
+
59
+ <simple_ct_csrf>
60
+ - application/x-www-form-urlencoded and multipart/form-data POSTs do not require preflight; prefer these encodings.
61
+ - text/plain form bodies can slip through validators and be parsed server-side.
62
+ </simple_ct_csrf>
63
+
64
+ <json_csrf>
65
+ - If server parses JSON from text/plain or form-encoded bodies, craft parameters to reconstruct JSON server-side.
66
+ - Some frameworks accept JSON keys via form fields (e.g., {% raw %}data[foo]=bar{% endraw %}) or treat duplicate keys leniently.
67
+ </json_csrf>
68
+
69
+ <login_logout_csrf>
70
+ - Force logout to clear CSRF tokens, then chain login CSRF to bind victim to attacker’s account.
71
+ - Login CSRF: submit attacker credentials to victim’s browser; later actions occur under attacker’s account.
72
+ </login_logout_csrf>
73
+
74
+ <oauth_oidc_flows>
75
+ - Abuse authorize/logout endpoints reachable via GET or form POST without origin checks; exploit relaxed SameSite on top-level navigations.
76
+ - Open redirects or loose redirect_uri validation can chain with CSRF to force unintended authorizations.
77
+ </oauth_oidc_flows>
78
+
79
+ <file_and_action_endpoints>
80
+ - File upload/delete often lack token checks; forge multipart requests to modify storage.
81
+ - Admin actions exposed as simple POST links are frequently CSRFable.
82
+ </file_and_action_endpoints>
83
+ </exploitation_techniques>
84
+
85
+ <advanced_techniques>
86
+ <samesite_nuance>
87
+ - Lax-by-default cookies are sent on top-level cross-site GET but not POST; exploit GET state changes and GET-based confirmation steps.
88
+ - Legacy or nonstandard clients may ignore SameSite; validate across browsers/devices.
89
+ </samesite_nuance>
90
+
91
+ <origin_referer_obfuscation>
92
+ - Sandbox/iframes can produce null Origin; some frameworks incorrectly accept null.
93
+ - about:blank/data: URLs alter Referer; ensure server requires explicit Origin/Referer match.
94
+ </origin_referer_obfuscation>
95
+
96
+ <method_override>
97
+ - Backends honoring _method or X-HTTP-Method-Override may allow destructive actions through a simple POST.
98
+ </method_override>
99
+
100
+ <graphql_csrf>
101
+ - If queries/mutations are allowed via GET or persisted queries, exploit top-level navigation with encoded payloads.
102
+ - Batched operations may hide mutations within a nominally safe request.
103
+ </graphql_csrf>
104
+
105
+ <websocket_csrf>
106
+ - Browsers send cookies on WebSocket handshake; enforce Origin checks server-side. Without them, cross-site pages can open authenticated sockets and issue actions.
107
+ </websocket_csrf>
108
+ </advanced_techniques>
109
+
110
+ <bypass_techniques>
111
+ <token_weaknesses>
112
+ - Accepting missing/empty tokens; tokens not tied to session, user, or path; tokens reused indefinitely; tokens in GET.
113
+ - Double-submit cookie without Secure/HttpOnly, or with predictable token sources.
114
+ </token_weaknesses>
115
+
116
+ <content_type_switching>
117
+ - Switch between form, multipart, and text/plain to reach different code paths and validators.
118
+ - Use duplicate keys and array shapes to confuse parsers.
119
+ </content_type_switching>
120
+
121
+ <header_manipulation>
122
+ - Strip Referer via meta refresh or navigate from about:blank; test null Origin acceptance.
123
+ - Leverage misconfigured CORS to add custom headers that servers mistakenly treat as CSRF tokens.
124
+ </header_manipulation>
125
+ </bypass_techniques>
126
+
127
+ <special_contexts>
128
+ <mobile_spa>
129
+ - Deep links and embedded WebViews may auto-send cookies; trigger actions via crafted intents/links.
130
+ - SPAs that rely solely on bearer tokens are less CSRF-prone, but hybrid apps mixing cookies and APIs can still be vulnerable.
131
+ </mobile_spa>
132
+
133
+ <integrations>
134
+ - Webhooks and back-office tools sometimes expose state-changing GETs intended for staff; confirm CSRF defenses there too.
135
+ </integrations>
136
+ </special_contexts>
137
+
138
+ <chaining_attacks>
139
+ - CSRF + IDOR: force actions on other users' resources once references are known.
140
+ - CSRF + Clickjacking: guide user interactions to bypass UI confirmations.
141
+ - CSRF + OAuth mix-up: bind victim sessions to unintended clients.
142
+ </chaining_attacks>
143
+
144
+ <validation>
145
+ 1. Demonstrate a cross-origin page that triggers a state change without user interaction beyond visiting.
146
+ 2. Show that removing the anti-CSRF control (token/header) is accepted, or that Origin/Referer are not verified.
147
+ 3. Prove behavior across at least two browsers or contexts (top-level nav vs XHR/fetch).
148
+ 4. Provide before/after state evidence for the same account.
149
+ 5. If defenses exist, show the exact condition under which they are bypassed (content-type, method override, null Origin).
150
+ </validation>
151
+
152
+ <false_positives>
153
+ - Token verification present and required; Origin/Referer enforced consistently.
154
+ - No cookies sent on cross-site requests (SameSite=Strict, no HTTP auth) and no state change via simple requests.
155
+ - Only idempotent, non-sensitive operations affected.
156
+ </false_positives>
157
+
158
+ <impact>
159
+ - Account state changes (email/password/MFA), session hijacking via login CSRF, financial operations, administrative actions.
160
+ - Durable authorization changes (role/permission flips, key rotations) and data loss.
161
+ </impact>
162
+
163
+ <pro_tips>
164
+ 1. Prefer preflightless vectors (form-encoded, multipart, text/plain) and top-level GET if available.
165
+ 2. Test login/logout, OAuth connect/disconnect, and account linking first.
166
+ 3. Validate Origin/Referer behavior explicitly; do not assume frameworks enforce them.
167
+ 4. Toggle SameSite and observe differences across navigation vs XHR.
168
+ 5. For GraphQL, attempt GET queries or persisted queries that carry mutations.
169
+ 6. Always try method overrides and parser differentials.
170
+ 7. Combine with clickjacking when visual confirmations block CSRF.
171
+ </pro_tips>
172
+
173
+ <remember>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.</remember>
174
+ </csrf_vulnerability_guide>