Details
# 42Crunch API Security Plugin
Automate API security directly in Claude Code with 42Crunch - audit OpenAPI specs, detect vulnerabilities aligned with OWASP API Security risks (including BOLA/BFLA), and apply AI-powered fixes.
## Overview
The `api-security-testing` plugin is designed for AI-assisted development workflows, it provides continuous guardrails through an **audit->scan->remediate->validate** loop, ensuring APIs meet enterprise security standards before deployment.
## Commands
| Skill | Description |
|---|---|
| [`/42crunch-setup`](./README.md#42crunch-setup) | Install the `42c-ast` binary and configure credentials (one-time) |
| [`/42crunch-audit`](./README.md#42crunch-audit) | Static security audit of an OpenAPI Specification file with scored findings and AI-assisted fixes |
| [`/42crunch-scan`](./README.md#42crunch-scan) | Live conformance and authorization scan (BOLA/BFLA) against a running API |
| [`/42crunch-api-security-testing`](./README.md#42crunch-api-security-testing) | Full audit + scan pipeline in a single session |
| [`/code-to-oas`](./README.md#code-to-oas) | Generate a complete `openapi.json` from your API source code|
## Prerequisites
- [Claude Code](https://claude.ai/code) (CLI, desktop app, or IDE extension)
- A 42Crunch account — [freemium](https://42crunch.com/freemium/) or paid (Platform API key)
- For `42crunch-scan`: a running API server reachable at the URL in `servers[0]` of your OAS (or via `SCAN42C_HOST`)
The `42c-ast` binary is downloaded and kept up to date automatically on first use.
## Installation
Add the 42Crunch marketplace:
```
/plugin marketplace add 42Crunch-AI/claude-plugins
```
Install the `api-security-testing` plugin:
```
/plugin install api-security-testing@42crunch-marketplace
```
## Quick Start
1. **Install the plugin** — add this marketplace to Claude Code.
2. **Set up the environment** — say: *"set up 42crunch"*
3. **Audit your API** — say: *"run a 42Crunch audit"* (Claude will offer to generate an OAS from source code if you don't have one)
4. **Fix issues** — Claude presents findings by severity and asks your consent before changing anything
5. **Scan your API** — say: *"run a conformance scan"* against your running server
## Skills
### `42crunch-setup`
Installs the `42c-ast` binary for your OS/architecture, verifies its checksum, and walks you through credential configuration. Supports Platform (API key) and Freemium (token) modes. Credentials are stored in `~/.42crunch/conf/env` with `600` permissions.
> **Trigger:** "set up 42crunch", "configure 42crunch", "install 42c-ast", "update 42c-ast", "set api key", "42crunch not working", "binary not found"
**Usage:**
```
/42crunch-setup
```
---
### `42crunch-audit`
Runs a static analysis of an OpenAPI Specification and produces a 0–100 security score. Findings are classified into three tiers:
- **SQG-Blocking** — must fix to pass the Security Quality Gate
- **Security** — recommended fixes
- **Data Validation** — informational
Claude asks your explicit consent before applying any changes, then re-runs the audit to confirm passage.
**Platform mode:** SQG threshold enforced from your platform policy.
**Freemium mode:** No automated SQG gate; you set the target score and blocking severity for the session.
> **Trigger:** "run audit", "42crunch audit", "fix audit issues", "SQG audit", "audit score"
**Usage:**
```
/42crunch-audit
```
---
### `42crunch-scan`
Runs a live conformance and authorization test against a running API server. Claude confirms the target URL, checks reachability, analyses the OAS (operations, auth schemes, BOLA candidates), and presents a scan preview before any configuration begins. After a happy-path validation run, Claude asks your consent before starting the full fuzzing scan.
Findings are classified into three tiers:
- **Authorization failures** — BOLA/BFLA confirmed
- **SQG-Blocking conformance** — must fix to pass the Security Quality Gate
- **Informational conformance** — surfaced for review
Claude asks your consent before applying any fixes — both OAS contract updates and server-side code changes.
**Platform mode:** SQG enforced from platform policy.
**Freemium mode:** All findings presented informally; you decide what to fix.
> **Trigger:** "run scan", "scan only", "conformance test", "BOLA test", "BFLA test", "42crunch scan", "scan config"
**Usage:**
```
/42crunch-scan
```
---
### `42crunch-api-security-testing`
Orchestrates Audit (Phase 1) and Scan (Phase 2) in sequence. Resolves the OAS file and confirms the scan target URL up front. Each phase requires separate user consent. Produces a combined summary covering both phases.
> **Trigger:** "run audit and scan", "full 42crunch pipeline", "full security check", "audit then scan", "SQG"
**Usage:**
```
/42crunch-api-security-testing
```
---
### `code-to-oas`
Analyses your API codebase and generates a complete `openapi.json`. Detects routes, parameters, request/response schemas, auth middleware, data models, and server config. Performs a self-review pass before writing the file.
Supported frameworks: Express, Fastify, Koa, Hapi, NestJS, FastAPI, Flask, Django, Starlette, Spring Boot, Quarkus, Micronaut, Gin, Echo, Chi, Gorilla/mux, Rails, Sinatra, Grape, ASP.NET Core, and more.
> **Trigger:** "generate OAS from code", "create OpenAPI spec", "document my API", "reverse-engineer spec", "write openapi.json from my codebase"
**Usage:**
```
/code-to-oas
```
---
## Configuration
Credentials are read from `~/.42crunch/conf/env` (macOS/Linux) or `%APPDATA%\42Crunch\conf\env` (Windows), written by `42crunch-setup`. Never edit this file manually while a skill is running.
| Variable | Description | Mode |
|---|---|---|
| `API_KEY` | Platform token (`api_*` or `ide_*`) | Platform |
| `PLATFORM_HOST` | 42Crunch platform base URL (e.g. `https://us.42crunch.cloud`) | Platform |
| `FREEMIUM_TOKEN` | Freemium token (Base64) | Freemium |
| `SCAN42C_HOST` | Override scan target URL (overrides `servers[0]` in OAS) | Both |
Credentials are never printed in plaintext after entry.
---
## Links
- [42Crunch](https://42crunch.com/)
- [42Crunch Documentation](https://docs.42crunch.com)
- [42Crunch on GitHub](https://github.com/42Crunch)
- Support: support@42crunch.com
## License
Apache 2.0 — see [LICENSE](./LICENSE) for details.
## skills/42crunch-api-security-testing/SKILL.md
---
name: 42crunch-api-security-testing
description: >
Run both a 42Crunch Audit and a live Scan together in a single pipeline.
Use this skill when the user wants to run audit and scan together, complete
the full security pipeline, or when the request is ambiguous about which
phase to run. Triggers on phrases like "run audit and scan", "full 42crunch
pipeline", "full security check", "audit then scan", "42crunch", or "SQG".
Do NOT use this skill if the user explicitly requests only an audit (use
42crunch-audit) or only a scan (use 42crunch-scan).
---
# 42Crunch API Security Skill
Orchestrates two phases: **Audit** (static OAS analysis and SQG fix loop) and
**Scan** (live conformance + authorization testing). Each phase requires
explicit user permission before execution.
---
## Entry Point
1. **Pre-flight checks.** Read `../../references/pre-flight.md` and complete
all steps (setup, OAS resolution, tag detection). When prompting for OAS
file selection, use the context `"pipeline"` (e.g. "Which one should I run
through the pipeline?"). Do not proceed if any step fails or the user cancels.
2. **Ask for Phase 1 permission.** Call `AskUserQuestion`:
- **question**: `"Ready to run a 42Crunch Audit on <filename>. This will analyse your OAS file and produce a scored report. Shall I proceed?"`
- **options**: `["Yes, proceed", "No, cancel"]`
3. **Execute Phase 1 — Audit.** Mode is already resolved from pre-flight — do
not re-derive it. Read `../../references/audit-workflow.md` and apply only
the commands for the identified mode throughout.
The workflow runs the audit, then presents a **developer-readable,
risk-classified report** (SQG-Blocking / Security / Data Validation tiers)
with plain-English titles and risk descriptions — no raw rule IDs. It then
pauses and asks the user to consent before applying any fixes. Fixes are
only applied after explicit confirmation.
4. **Resolve the scan target URL.**
Read `servers[0].url` from the OAS file.
- If `SCAN42C_HOST` environment variable is set → announce silently:
> "Using scan target from SCAN42C_HOST: `<url>`"
Store as `SCAN_TARGET_URL` and proceed.
- If not set → call `AskUserQuestion`:
- **question**: `"The OAS points to <servers[0].url> as the API target. Is this the right URL to scan against?"` — options: `["Yes — use this URL", "No — I'll provide a different URL"]`
- If **No** → ask the user to provide the URL and store it as `SCAN_TARGET_URL`.
- If **Yes** → store `servers[0].url` as `SCAN_TARGET_URL`.
**Reachability check** — run immediately after `SCAN_TARGET_URL` is confirmed.
Uses a two-stage probe to distinguish "server is down" from "wrong base URL".
**Stage 1** — probe the base URL:
```bash
curl -s -o /dev/null -w "%{http_code}" --max-time 5 <SCAN_TARGET_URL>/
```
- **2xx, 3xx, 401, 403, or 405** → API is reachable. Proceed silently.
- **Connection refused or timeout** → call `AskUserQuestion`:
- **question**: `"I couldn't reach <SCAN_TARGET_URL> — the connection timed out or was refused. How would you like to proceed?"`
- **options**: `["Try a different URL", "Continue anyway — the API may be temporarily down", "Cancel"]`
- If **Try a different URL** → ask for new URL, store as `SCAN_TARGET_URL`, re-run from Stage 1.
- If **Continue anyway** → proceed with warning noted.
- If **Cancel** → stop.
- **404** → ambiguous (server may be up but nothing is mounted at root). Proceed to Stage 2.
**Stage 2** — probe the first simple OAS path (only reached when Stage 1 returns 404):
Find the first `GET` path in the OAS that has no required path parameters. Strip any
`{param}`-style segments and probe:
```bash
curl -s -o /dev/null -w "%{http_code}" --max-time 5 <SCAN_TARGET_URL><first_simple_path>
```
- **Any HTTP response** → server is up; root just has no handler. Proceed silently.
- **Connection refused or timeout** → same `AskUserQuestion` as Stage 1.
- **404 again** → call `AskUserQuestion`:
- **question**: `"The server responded but both / and <path> returned 404 — the base URL may be incorrect (the API may be mounted at a different prefix). How would you like to proceed?"`
- **options**: `["Try a different URL", "Continue anyway", "Cancel"]`
- If **Try a different URL** → ask for new URL, store as `SCAN_TARGET_URL`, re-run from Stage 1.
- If **Continue anyway** → proceed with warning noted.
- If **Cancel** → stop.
5. **OAS analysis for Phase 2 preview** — run silently after Phase 1 completes,
before asking for Phase 2 permission.
Read the OAS file and collect:
- Total operation count
- Auth scheme types from `securitySchemes` (Bearer/JWT, API Key, Basic, OAuth2)
- BOLA candidate count: operations where the path has `{…Id}`, `{…Key}`, `{…Ref}`, or similar resource-ID placeholders AND the method is GET, PUT, PATCH, or DELETE
- Whether the OAS contains sample data: any operation with `example`, `examples`, or `default` values on its request body or parameter schemas
6. **Ask for Phase 2 permission.** Call `AskUserQuestion`:
- **question**: (show the scan preview first, then ask)
```
Ready to configure the scan?
Target: <SCAN_TARGET_URL> ✓ reachable / ⚠ reachability unknown
OAS: <filename> (<N> operations)
Auth: <scheme types> [+ second user needed — <N> BOLA candidate(s)]
Samples: OAS has sample data / No samples — you'll need to provide test data
Tag: <category>:<tagname> ← platform mode only, when a tag is assigned; omit if no tag
Mode: Platform / Freemium
```
`"I'm ready to start configuring the scan. I'll ask for credentials, classify your operations, and set up test scenarios — then run a happy path validation before the full scan. Shall I proceed?"`
- **options**: `["Yes, let's configure", "No, cancel"]`
7. **Execute Phase 2 — Scan.** Mode is already resolved from pre-flight — do
not re-derive it. Read `../../references/scan-workflow.md` and apply only
the commands for the identified mode throughout.
The workflow runs the scan, then presents a **risk-classified findings
report** (Authorization failures / SQG-blocking conformance /
informational conformance). Fix candidates are determined by SQG-blocking
rules and authorization failures — not severity alone. The skill pauses and
asks the user to consent before applying any OAS changes.
**Mandatory checkpoint:** during Phase 2, after any direct edit to
`CONF_FILE` (including `environments.default.variables.*`, auth wiring, or
scenario chains), run `scan conf validate` and resolve all validation
errors before continuing to happy-path or full scan runs.
8. **Present the final combined summary** (see Output Format below).
9. **Recommend next steps** based on the outcome:
**If both phases passed and fixes were applied:**
> "Both audit and scan are passing. Your OAS is more precise and your
> security contract is enforced. Consider committing the updated OAS file
> and rerunning `42crunch-api-security-testing` after any significant API change."
**If either phase failed or the user declined fixes:**
> "Here's what's still open: [list remaining SQG-failing issues or unfixed
> scan findings by tier]. When you're ready to address them, run
> `42crunch-audit` or `42crunch-scan` individually."
**If no issues were found in either phase:**
> "Clean result — your API passed both static analysis and live testing.
> This is a good baseline to maintain."
Only continue after explicit user confirmation at each permission prompt.
---
## Output Format
After both phases complete, produce a summary in this shape:
```
Phase 1 — Audit Complete
Score: <score> / 100 (Security: <sec-score> · Data Validation: <data-score>)
Score change: <initial-score> → <score> (<delta>) | Data: <initial-data> → <data-score> (<data-delta>) ← omit if no fixes applied
Mode: Platform ← or "Freemium"
SQG: PASSED (<sqg-name> — your org's security quality gate is met) ← platform mode, passed
SQG: FAILED (<sqg-name> — the quality gate is not met; fixes above are required) ← platform mode, failed
SQG: N/A (Freemium — no automated gate; user-defined thresholds applied this session) ← freemium mode
Tag: <category>:<tagname> ← platform mode only, when a tag is assigned; omit this row if no tag
Issues fixed: 2 SQG-blocking (0 security · 2 data validation)
OAS updated: <path/to/openapi.json>
Phase 2 — Scan Complete
Mode: Platform ← or "Freemium"
SQG: PASSED (<sqg-name> — your org's security quality gate is met) ← platform mode, passed
SQG: FAILED (<sqg-name> — the quality gate is not met; fixes above are required) ← platform mode, failed
SQG: N/A (Freemium — scan findings are informational; no gate enforced) ← freemium mode
Authorization: BOLA confirmed on 1 operation — OAS updated · server-side fix applied
Conformance: 1 SQG-blocking issue fixed (OAS + code) · 3 informational findings surfaced
OAS updated: <path/to/openapi.json>
```
Show only the one SQG line per phase that matches the current mode and result.
The `Score change:` row in Phase 1 is produced from the delta values computed in
Step 4 of `../../references/audit-workflow.md`. Omit it when no audit fixes were
applied (user declined at the consent gate, or there were no SQG-blocking issues).
If a phase was skipped (user declined), note that instead of its results.
---
## Environment Variables
| Variable | Purpose |
|----------------|---------|
| `SCAN42C_HOST` | Scan target base URL (overrides OAS `servers[0]`) — Both modes |
All other variables (`API_KEY`, `PLATFORM_HOST`, `FREEMIUM_TOKEN`) and general
constraints are defined in `../../references/pre-flight.md`.
## skills/42crunch-audit/SKILL.md
---
name: 42crunch-audit
description: >
Run a 42Crunch API Security Audit and fix SQG-blocking issues in an OpenAPI
Specification file. Use this skill whenever the user wants to audit an OAS
file for security issues, fix SQG-blocking issues, score an API, apply data
dictionary enrichment, or remediate audit findings. Triggers on phrases like
"run audit", "audit only", "fix audit issues", "SQG audit", "42crunch audit",
"audit score", or any request focused on static OAS analysis and remediation
without running a live scan.
---
# 42Crunch Audit Skill
Runs a single phase: **Audit** (static OAS analysis, SQG reporting, and
SQG-blocking fix loop). Requires explicit user permission before execution.
Does **not** run a live scan — use the `42crunch-scan` skill for that.
---
## Entry Point
1. **Pre-flight checks.** Read `../../references/pre-flight.md` and complete
all steps (setup, OAS resolution, tag detection). When prompting for OAS
file selection, use the context `"audit"` (e.g. "Which one should I audit?").
Do not proceed if any step fails or the user cancels.
2. **Ask for permission.** Call `AskUserQuestion`:
- **question**: `"Ready to run a 42Crunch Audit on <filename>. This will analyse your OAS file and produce a scored report. Shall I proceed?"`
- **options**: `["Yes, proceed", "No, cancel"]`
3. **Execute the Audit.** Mode is already resolved from pre-flight — do not
re-derive it. Read `../../references/audit-workflow.md` and apply only the
commands for the identified mode throughout.
The workflow runs the audit, then presents a **developer-readable,
risk-classified report** (SQG-Blocking / Security / Data Validation tiers)
with plain-English titles and risk descriptions — no raw rule IDs. It then
pauses and asks the user to consent before applying any fixes. Fixes are
only applied after explicit confirmation.
4. **Present the final audit summary** (see Output Format below).
5. **Recommend next steps** based on the outcome:
**If SQG PASSED:**
> "Your audit is complete and the SQG is passing. The natural next step is to
> run a live scan to test conformance and authorization against a running
> instance of your API. Just say `run scan` when your API server is available."
**If SQG FAILED (user declined to fix):**
> "Your audit findings are saved above. When you're ready to address the
> SQG-blocking issues, run `42crunch-audit` again on this file and I'll apply
> the fixes. Once the audit passes, run `42crunch-scan` to test the live API."
**If no issues found:**
> "No issues found — your API has a clean audit result. Run `42crunch-scan`
> to verify the live API matches its contract."
Only continue after explicit user confirmation at each permission prompt.
---
## Output Format
After the audit completes, produce a summary in this shape:
```
Audit Complete
Score: <score> / 100 (Security: <sec-score> · Data Validation: <data-score>)
Score change: <initial-score> → <score> (<delta>) | Data: <initial-data> → <data-score> (<data-delta>) ← omit if no fixes applied
SQG: PASSED (<sqg-name> — your org's security quality gate is met) ← platform mode, passed
SQG: FAILED (<sqg-name> — the quality gate is not met; fixes above are required) ← platform mode, failed
SQG: N/A (Freemium — no automated gate; user-defined thresholds applied this session) ← freemium mode
Mode: Platform / Freemium
Tag: <category>:<tagname> ← platform mode only, when a tag is assigned; omit this row if no tag
Issues fixed: 2 SQG-blocking (0 security · 2 data validation)
OAS updated: <path/to/openapi.json>
```
Show only the one SQG line that matches the current mode and result.
The `Score change:` row is produced from the delta values computed in Step 4 of
`../../references/audit-workflow.md`. Omit it when no fixes were applied (user
declined at the consent gate, or there were no SQG-blocking issues).
If the user declined to apply fixes, note that instead.
## skills/42crunch-scan/SKILL.md
---
name: 42crunch-scan
description: >
Run a 42Crunch live conformance and authorization scan against an API and fix
SQG-blocking scan findings. Use this skill whenever the user wants to run a
conformance test, authorization scan, BOLA test, BFLA test, generate or
configure a scan config, or fix scan-reported issues. Triggers on phrases
like "run scan", "scan only", "conformance test", "BOLA test", "BFLA test",
"42crunch scan", "scan config", or any request focused on live API testing
without running a static audit. Use 42crunch-api-security-testing when the user wants both
audit and scan together.
---
# 42Crunch Scan Skill
Runs a single phase: **Scan** (live conformance + authorization testing and
SQG-blocking fix loop). Requires explicit user permission before execution.
Does **not** run a static audit — use the `42crunch-audit` skill for that.
Assumes the OAS file is already audit-clean (or the user is explicitly
running scan only). If the user mentions audit issues before scanning, suggest
running `42crunch-audit` first.
---
## Entry Point
1. **Pre-flight checks.** Read `../../references/pre-flight.md` and complete
all steps (setup, OAS resolution, tag detection). When prompting for OAS
file selection, use the context `"scan"` (e.g. "Which one should I scan?").
Do not proceed if any step fails or the user cancels.
2. **Resolve the scan target URL.**
Read `servers[0].url` from the OAS file.
- If `SCAN42C_HOST` environment variable is set → announce silently:
> "Using scan target from SCAN42C_HOST: `<url>`"
Store as `SCAN_TARGET_URL` and proceed.
- If not set → call `AskUserQuestion`:
- **question**: `"The OAS points to <servers[0].url> as the API target. Is this the right URL to scan against?"` — options: `["Yes — use this URL", "No — I'll provide a different URL"]`
- If **No** → ask the user to provide the URL and store it as `SCAN_TARGET_URL`.
- If **Yes** → store `servers[0].url` as `SCAN_TARGET_URL`.
**Reachability check** — run immediately after `SCAN_TARGET_URL` is confirmed.
Uses a two-stage probe to distinguish "server is down" from "wrong base URL".
**Stage 1** — probe the base URL:
```bash
curl -s -o /dev/null -w "%{http_code}" --max-time 5 <SCAN_TARGET_URL>/
```
- **2xx, 3xx, 401, 403, or 405** → API is reachable. Proceed silently.
- **Connection refused or timeout** → call `AskUserQuestion`:
- **question**: `"I couldn't reach <SCAN_TARGET_URL> — the connection timed out or was refused. How would you like to proceed?"`
- **options**: `["Try a different URL", "Continue anyway — the API may be temporarily down", "Cancel"]`
- If **Try a different URL** → ask for new URL, store as `SCAN_TARGET_URL`, re-run from Stage 1.
- If **Continue anyway** → proceed with warning noted.
- If **Cancel** → stop.
- **404** → ambiguous (server may be up but nothing is mounted at root). Proceed to Stage 2.
**Stage 2** — probe the first simple OAS path (only reached when Stage 1 returns 404):
Find the first `GET` path in the OAS that has no required path parameters. Strip any
`{param}`-style segments and probe:
```bash
curl -s -o /dev/null -w "%{http_code}" --max-time 5 <SCAN_TARGET_URL><first_simple_path>
```
- **Any HTTP response** → server is up; root just has no handler. Proceed silently.
- **Connection refused or timeout** → same `AskUserQuestion` as Stage 1.
- **404 again** → call `AskUserQuestion`:
- **question**: `"The server responded but both / and <path> returned 404 — the base URL may be incorrect (the API may be mounted at a different prefix). How would you like to proceed?"`
- **options**: `["Try a different URL", "Continue anyway", "Cancel"]`
- If **Try a different URL** → ask for new URL, store as `SCAN_TARGET_URL`, re-run from Stage 1.
- If **Continue anyway** → proceed with warning noted.
- If **Cancel** → stop.
3. **OAS analysis for scan preview** — run silently before asking permission.
Read the OAS file and collect:
- Total operation count
- Auth scheme types from `securitySchemes` (Bearer/JWT, API Key, Basic, OAuth2)
- BOLA candidate count: operations where the path has `{…Id}`, `{…Key}`, `{…Ref}`, or similar resource-ID placeholders AND the method is GET, PUT, PATCH, or DELETE
- Whether the OAS contains sample data: any operation with `example`, `examples`, or `default` values on its request body or parameter schemas
4. **Ask for permission to configure the scan.** Call `AskUserQuestion`:
- **question**: (show the scan preview first, then ask)
```
Ready to configure the scan?
Target: <SCAN_TARGET_URL> ✓ reachable / ⚠ reachability unknown
OAS: <filename> (<N> operations)
Auth: <scheme types> [+ second user needed — <N> BOLA candidate(s)]
Samples: OAS has sample data / No samples — you'll need to provide test data
Tag: <category>:<tagname> ← platform mode only, when a tag is assigned; omit if no tag
Mode: Platform / Freemium
```
`"I'm ready to start configuring the scan. I'll ask for credentials, classify your operations, and set up test scenarios — then run a happy path validation before the full scan. Shall I proceed?"`
- **options**: `["Yes, let's configure", "No, cancel"]`
5. **Execute the Scan.** Mode is already resolved from pre-flight — do not
re-derive it. Read `../../references/scan-workflow.md` and apply only the
commands for the identified mode throughout.
The workflow sets up the scan config, collects credentials, gathers test data,
classifies operations, validates happy paths, then asks for permission again
before running the full scan. It presents a **risk-classified findings report**
(Authorization failures / SQG-blocking conformance / informational conformance)
and pauses for consent before applying any OAS changes.
**Mandatory checkpoint:** after any direct edit to `CONF_FILE` (including
`environments.default.variables.*`, auth wiring, or scenario chains), run
`scan conf validate` and resolve all validation errors before continuing to
happy-path or full scan runs.
**Freemium mode**: no SQG is enforced for scan. Present all findings for
information. The user decides which (if any) to fix.
6. **Present the final scan summary** (see Output Format below).
Only continue after explicit user confirmation at each permission prompt.
---
## Output Format
After the scan completes, produce a summary in this shape:
```
Scan Complete
Mode: Platform / Freemium
SQG: PASSED (<sqg-name> — your org's security quality gate is met) ← platform mode, passed
SQG: FAILED (<sqg-name> — the quality gate is not met; fixes above are required) ← platform mode, failed
SQG: N/A (Freemium — scan findings are informational; no gate enforced) ← freemium mode
Tag: <category>:<tagname> ← platform mode only, when a tag is assigned; omit this row if no tag
Authorization: BOLA confirmed on 1 operation — OAS updated · server-side fix applied
Conformance: 1 SQG-blocking issue fixed (OAS + code) · 3 informational findings surfaced
OAS updated: <path/to/openapi.json>
```
Show only the one SQG line that matches the current mode and result.
If the user declined to apply fixes or no issues were found, note that instead.
---
## Environment Variables
| Variable | Purpose |
|----------------|---------|
| `SCAN42C_HOST` | Scan target base URL (overrides OAS `servers[0]`) — Both modes |
All other variables (`API_KEY`, `PLATFORM_HOST`, `FREEMIUM_TOKEN`) and general
constraints are defined in `../../references/pre-flight.md`.
## skills/42crunch-setup/SKILL.md
---
name: 42crunch-setup
description: >
Set up the 42Crunch environment so that audit and scan skills can run
without friction. Use this skill whenever the user wants to configure
42Crunch for the first time, install or update the 42c-ast binary, configure
an API key, or troubleshoot missing credentials or binary errors. Triggers
on phrases like "setup 42crunch", "configure 42crunch", "install 42c-ast",
"update 42c-ast", "set api key", "42crunch not working", "binary not found",
or any request to prepare the environment before running an audit or scan.
---
# 42Crunch Setup
Prepares the environment for 42Crunch audit and scan workflows in two phases:
1. Ensure the `42c-ast` binary is installed at the canonical path.
2. Configure and store credentials.
---
## Entry Point
> **Caller context**: This skill may be invoked directly by the user or as a
> subroutine by another skill (e.g. `pre-flight`). Check whether a caller was
> passed. Steps 1 and 6 behave differently depending on this context — see each
> step for details.
### Step 1 — Introduce the setup
**If called directly by the user** (no caller context), greet the user and
explain what they'll be able to do once setup is complete:
> Welcome — let me get your 42Crunch environment ready. This is a one-time
> setup that takes about two minutes. Once done, you'll be able to:
>
> - **Audit** any OpenAPI file for security issues and get a scored, actionable report
> - **Scan** a live API to catch BOLA, BFLA, and conformance problems
> - **Fix** SQG-blocking issues automatically, with your approval at every step
>
> I'll handle this in two quick steps:
> 1. Install the `42c-ast` analysis binary on this machine.
> 2. Connect your 42Crunch credentials (existing platform account or free account).
>
> Let's go.
**If called as a subroutine** (caller context is set), skip this greeting entirely and proceed directly to Step 2.
### Step 2 — Binary setup
Follow `../../references/binary-setup.md` completely (verbose mode — announce each major step to the user).
Stop and surface a clear error if the binary cannot be installed. Do not proceed to Step 3.
### Step 3 — Credential setup
Follow `../../references/credential-setup.md` completely.
The procedure covers, in order:
- Silently check whether credentials are already present in
`~/.42crunch/conf/env` (macOS/Linux) or `%APPDATA%\42Crunch\conf\env`
(Windows). If already configured: show mode + masked key, offer to keep or replace.
- If not configured (or replacing): walk the user through the guided flow:
- **Are you an existing 42Crunch user?**
- Yes → enter API Key → select Platform URL (US / EU / Other)
- No → **Are you a registered 42Crunch Freemium user?**
- Yes → enter Freemium Token
- No → show registration link (`https://42crunch.com/freemium/`) and stop
- Write credentials to `~/.42crunch/conf/env`, set `chmod 600` on macOS/Linux.
### Step 4 — Final verification
Run a quick end-to-end check:
```bash
# Binary (macOS / Linux)
"$HOME/.42crunch/bin/42c-ast" --version
```
```powershell
# Binary (Windows)
& "$env:APPDATA\42Crunch\bin\42c-ast.exe" --version
```
```bash
# Credentials (macOS / Linux)
grep -E "^(API_KEY|FREEMIUM_TOKEN)=" "$HOME/.42crunch/conf/env"
```
If either check fails, report the specific failure and guide the user to resolve
it before continuing.
### Step 5 — Present summary
Display the setup summary (see Output Format below).
### Step 6 — Recommend next steps
**If called as a subroutine** (caller context is set), skip the next-steps
prompt entirely. Announce `"Setup complete — continuing."` and return control
to the caller. The caller (e.g. `pre-flight`) will resume from where it left
off.
**If called directly by the user** (no caller context), present the following:
> You're all set. Here's what you can do right now:
>
> - **`42crunch-audit`** — Hand me an OpenAPI file and I'll score it, classify
> every security issue by severity, and fix the SQG-blocking ones with your
> approval. A good first step if you haven't audited this API before.
>
> - **`42crunch-scan`** — Run a live conformance and authorization test against
> a running API. I'll check for BOLA, BFLA, and response-contract violations.
> Best run after the audit passes.
>
> - **`42crunch-api-security-testing`** — Runs both audit and scan back-to-back. The recommended
> workflow when you want the full picture in one session.
>
> Which would you like to start with?
---
## Output Format
```
## 42Crunch Setup Complete
| Item | Status |
|------------------|-----------------------------------------------------|
| Binary | <BINARY_PATH> v<version> |
| Credential mode | <Platform \| Freemium> |
| API key / Token | Platform: `api_••••••••` or `ide_••••••••` |
| | Freemium: `<first-4-chars>••••••••` |
| | (stored in <path>) |
| Platform host | <url> ← omit this row for freemium mode |
```
---
## General Constraints
- All detection steps (binary check, credential check) run silently. Surface
output only on failure or when prompting the user.
- Never print the API key or Freemium token in plaintext after the user enters
it. Always mask it (`api_••••••••` / `ide_••••••••` for platform tokens — keep
prefix, replace rest; `<first-4-chars>••••••••` for freemium tokens, e.g.
`eyJh••••••••`).
- Use `bash_tool` for all shell commands; use `str_replace_editor` or
`create_file` when writing config files — never shell redirection.
- Use `curl` for downloads; fall back to `wget` if `curl` is unavailable. On
Windows use `Invoke-WebRequest`.
- On Windows: binary filename is `42c-ast.exe`, paths use `\`, config lives in
`%APPDATA%\42Crunch\conf\env`, skip `chmod 600` (Windows ACLs protect `APPDATA`).
## Environment Variables
| Variable | Default | Mode |
|-----------------|----------------------------------|-----------------|
| `API_KEY` | *(required)* | Platform |
| `PLATFORM_HOST` | *(set during setup)* | Platform only |
| `FREEMIUM_TOKEN`| *(required)* | Freemium |
## skills/code-to-oas/SKILL.md
---
name: code-to-oas
description: >
Analyze an entire API codebase and generate an accurate OpenAPI Specification
(OAS 3.0) file from the source code. Use this skill whenever the user wants
to generate, create, or derive an OpenAPI spec from code, reverse-engineer an
API definition, or document an existing API. Triggers on phrases like "generate
OAS from code", "create OpenAPI spec", "document my API", "reverse-engineer
spec", "write openapi.json from my codebase", or any request to produce an
OAS file by reading source files rather than an existing spec.
---
# API source code to OpenAPI Specification
Analyzes an API codebase — regardless of language or framework — and produces
a complete, valid **OpenAPI 3.0.x** specification file (`openapi.json`) from
the source code. No existing OAS file is required.
---
## Entry Point
1. **Identify the root directory.** Use the directory the user specifies, or
default to the current working directory. If a specific service subdirectory
is open in the editor, use that.
2. **Detect the language and framework.** Scan for indicators without opening
every file yet:
- `package.json` → Node.js. Check `dependencies` for `express`, `fastify`,
`koa`, `hapi`, `nestjs`, `@nestjs/core`.
- `requirements.txt` / `pyproject.toml` / `setup.py` → Python. Check for
`fastapi`, `flask`, `django`, `starlette`, `tornado`.
- `pom.xml` / `build.gradle` → Java/Kotlin. Check for `spring-boot`,
`quarkus`, `micronaut`.
- `go.mod` → Go. Check for `gin`, `echo`, `chi`, `gorilla/mux`, `fiber`.
- `Gemfile` → Ruby. Check for `rails`, `sinatra`, `grape`.
- `*.csproj` / `*.sln` → C#/.NET. Check for `AspNetCore`, `WebApi`.
- Any existing partial OAS file (e.g. `openapi.yaml`, `swagger.json`) —
read it and use it as a starting scaffold, then extend/correct it.
3. **Announce the plan.**
> "I'll analyze the codebase as a `<framework>` API and generate
> `openapi.json`. I'll read route files, middleware, and model definitions.
> This may take a moment."
4. **Execute the analysis** (Steps 1–8 below), then write the OAS file.
---
## Step 1 — Discover Route / Controller Files
Locate the files that define HTTP routes or controllers. Use glob and grep
patterns matched to the detected framework:
| Framework | Look for |
|---|---|
| **Express** | Files importing `express.Router()`, `app.get/post/put/delete/patch` |
| **FastAPI** | Files with `@app.get`, `@router.get`, `APIRouter()` |
| **Flask** | Files with `@app.route`, `@blueprint.route` |
| **Django** | `urls.py` files, `path()` / `re_path()` / `url()` calls |
| **NestJS** | Files with `@Controller`, `@Get`, `@Post`, `@Put`, `@Delete`, `@Patch` |
| **Spring** | Files with `@RestController`, `@RequestMapping`, `@GetMapping`, etc. |
| **Gin/Echo/Chi** | Files calling `r.GET`, `r.POST`, `e.GET`, `r.Route`, `chi.NewRouter()` |
| **Rails** | `config/routes.rb` |
| **Sinatra/Grape** | Files with `get '/'`, `post '/'`, `resource :name` |
Read every discovered route file in full. For each route, record:
- HTTP method (`GET`, `POST`, `PUT`, `DELETE`, `PATCH`, `HEAD`, `OPTIONS`)
- Path string (convert framework-specific syntax to OAS path syntax:
`:param` → `{param}`, `<param>` → `{param}`, `{param:int}` → `{param}`)
- Handler function name (use as a seed for `operationId`)
- Middleware applied to this route or router group
---
## Step 2 — Extract Operation Details from Handlers
For each route handler identified in Step 1, read the handler implementation.
Extract:
### Path Parameters
Any segment in the path like `{id}` is a path parameter. It must appear in
`parameters` with `in: path` and `required: true`.
### Query Parameters
Look for:
- Express: `req.query.foo`, destructuring `const { foo } = req.query`
- FastAPI: function arguments without `Body()` annotation and not in the path
- Flask: `request.args.get('foo')`
- Django: `request.GET.get('foo')`
- Spring: `@RequestParam`
- Go: `c.Query("foo")`, `r.URL.Query().Get("foo")`
### Request Body
Look for:
- Express: `req.body`, `req.body.foo`
- FastAPI: `Body()` annotated params, Pydantic model params
- Flask: `request.json`, `request.get_json()`
- Django: `request.data`, `request.POST`
- Spring: `@RequestBody`
- Go: `c.ShouldBindJSON()`, `json.NewDecoder(r.Body)`
### Response Structure
Look for:
- `res.json({...})`, `res.status(200).json({...})` (Express)
- `return {...}` with type annotations (FastAPI)
- `jsonify({...})` (Flask)
- `Response(data, ...)` (Django REST)
- `return ResponseEntity<>` (Spring)
- `c.JSON(200, ...)` (Gin)
Note every distinct status code sent and the shape of each response body.
### Headers
Look for authentication headers read from the request:
- `req.headers['authorization']`, `req.headers.authorization`
- `Authorization: Bearer` checks
- Custom headers like `x-api-key`, `x-user-id`
---
## Step 3 — Identify Authentication / Middleware
Read all middleware files. Look for:
- JWT verification middleware → `securityScheme` type `http`, scheme `bearer`