Skip to content

CLI Reference

The middleBrick CLI lets you run security scans from your terminal, pipe results to scripts, and gate CI/CD builds on security scores.

Terminal window
npm install -g middlebrick

Requires Node.js 18 or later. Verify the installation:

Terminal window
mb --version

Opens your browser to authenticate with your middleBrick account. Your API key is stored locally in ~/.middlebrick/config.json.

Terminal window
mb login

Alternatively, set the MIDDLEBRICK_API_KEY environment variable to skip interactive login:

Terminal window
export MIDDLEBRICK_API_KEY=mb_your_api_key_here

This is the recommended approach for CI/CD environments where interactive login isn’t possible.

Clears stored credentials.

Terminal window
mb logout

Submit a URL for security scanning.

Terminal window
mb scan https://api.example.com/v1/users

Options:

FlagDescription
--spec <url>OpenAPI/Swagger spec URL for deeper analysis
--context <type>API context: financial, medical, public, internal
--format <fmt>Output format: pretty (default), json, table
--waitWait for scan to complete and show results (default)
--no-waitReturn immediately with the scan ID

Example output (pretty format):

middleBrick Security Scan
─────────────────────────
URL: https://api.example.com/v1/users
Score: 72 / 100
Grade: C
Findings (7):
┌──────────┬──────────────────────────────────┬──────────┐
│ Severity │ Finding │ Category │
├──────────┼──────────────────────────────────┼──────────┤
│ CRITICAL │ No authentication required │ Auth │
│ HIGH │ PII in response (email, phone) │ Data │
│ HIGH │ Sequential numeric IDs │ BOLA │
│ MEDIUM │ No rate limiting detected │ Rate │
│ MEDIUM │ Missing HSTS header │ Encrypt │
│ LOW │ Server header exposed │ Invent │
│ INFO │ API version not in URL │ Invent │
└──────────┴──────────────────────────────────┴──────────┘
Full report: https://app.middlebrick.com/scan/scan_abc123

More examples:

Terminal window
# Scan with OpenAPI spec
mb scan https://api.example.com/v1/users \
--spec https://api.example.com/openapi.json
# Financial API with JSON output
mb scan https://api.bank.com/v1/accounts \
--context financial --format json
# Non-blocking scan — returns immediately with scan ID
mb scan https://api.example.com/v1/users --no-wait
# Pipe JSON output to jq
mb scan https://api.example.com/v1/users --format json | jq '.findings[] | select(.severity == "critical")'

List your recent scans with scores and timestamps.

Terminal window
mb scans

Example output:

Recent Scans
────────────
scan_abc123 72/100 (C) https://api.example.com/v1/users 2m ago
scan_def456 91/100 (A) https://api.example.com/v1/health 1h ago
scan_ghi789 45/100 (D) https://staging.example.com/v1/pay 3d ago

Retrieve results for a previous scan by ID.

Terminal window
mb scan scan_abc123

Returns the same output format as mb scan <url>, using the stored results.

View or update CLI configuration.

Terminal window
# View current config
mb config
# Set default output format
mb config set format json
# Set default context
mb config set context financial
VariableDescription
MIDDLEBRICK_API_KEYAPI key (overrides mb login)
MIDDLEBRICK_API_URLCustom API base URL (default: https://api.middlebrick.com/v1)
NO_COLORDisable colored output when set to any value

The CLI returns meaningful exit codes for CI/CD integration:

CodeMeaning
0Scan completed successfully (no critical findings)
1Scan completed with critical findings
2Scan failed or errored
3Authentication error
Terminal window
mb scan https://api.example.com/v1/users --format json || exit 1

Exit code 1 means critical findings were detected. Your CI pipeline treats this as a failed step.

Terminal window
RESULT=$(mb scan https://api.example.com/v1/users --format json)
SCORE=$(echo "$RESULT" | jq '.score')
GRADE=$(echo "$RESULT" | jq -r '.grade')
echo "Security score: $SCORE ($GRADE)"
if [ "$SCORE" -lt 75 ]; then
echo "FAILED: Score $SCORE is below threshold (75)"
echo "$RESULT" | jq '.findings[] | select(.severity == "critical" or .severity == "high")'
exit 1
fi
security-scan:
stage: test
image: node:20
script:
- npm install -g middlebrick
- mb scan $API_URL --format json --context financial
variables:
MIDDLEBRICK_API_KEY: $MIDDLEBRICK_API_KEY
stage('API Security') {
environment {
MIDDLEBRICK_API_KEY = credentials('middlebrick-api-key')
}
steps {
sh 'npm install -g middlebrick'
sh 'mb scan $API_URL --format json'
}
}

For GitHub Actions, see the dedicated GitHub Action integration, which is simpler than using the CLI in a workflow.