# Scan code and pull requests for leaked secrets

URL: https://docs.hanzo.ai/docs/guides/cyber/secret-leak-scanning

> Scan commits, pull requests, and candidate training files for leaked credentials via POST /v1/security/scans and inspect masked findings.

**Catch leaked keys before they land in git history or model weights.** `POST /v1/security/scans` runs Hanzo's rule engine over any file batch and returns structured, masked findings with line numbers and stable fingerprints.

## Architecture & contract

Findings store only masked previews and fingerprints — never raw secret material — scoped strictly to your org. Pair with CI pre-commit hooks and dataset upload pipelines.

**Primary endpoint:** `POST /v1/security/scans` · \*_Status:_\* `shipped` · \*_Level:_\* `practitioner`

## Run it across all four surfaces

**CLI**

```bash
hanzo security rules
hanzo security scans create --data '{"files":[{"path":"deploy.sh","content":"export DATABASE_URL=postgres://app@db.internal/prod"}]}'
hanzo security findings list
```

**SDK**

**TypeScript**

```ts
import { Configuration, SecurityApi } from 'hanzoai';

const sec = new SecurityApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data: scan } = await sec.postSecurityScans({
  files: [{ path: 'deploy.sh', content: 'export DATABASE_URL=postgres://app@db.internal/prod' }],
});
console.log(scan);
```

**Python**

```python
import os
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import SecurityApi

api = SecurityApi(ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"])))
print(api.post_security_scans({"files": [{"path": "deploy.sh", "content": "export DATABASE_URL=postgres://app@db.internal/prod"}]}))
```

**HTTP**

```bash
curl -s -X POST https://api.hanzo.ai/v1/security/scans \
  -H "Authorization: Bearer $HANZO_API_KEY" -H "Content-Type: application/json" \
  -d '{"files":[{"path":"deploy.sh","content":"export DATABASE_URL=postgres://app@db.internal/prod"}]}' | jq '.'

curl -s https://api.hanzo.ai/v1/security/findings \
  -H "Authorization: Bearer $HANZO_API_KEY" | jq '.'
```

**MCP**

```bash
curl -s -X POST https://api.hanzo.ai/v1/mcp \
  -H "Authorization: Bearer $HANZO_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "security",
      "arguments": {"op": "get_security_scans", "input": {}}
    }
  }'
```

## Verify the outcome

- Run a scan against a clean file (expect `0` findings) and verify `GET /v1/security/scans/{id}` returns full scan metadata.

## Production guardrails

- Whenever a real credential triggers a finding, rotate it immediately in Hanzo KMS (`/v1/kms/secrets`) — deleting the commit alone is never sufficient.

## Next steps & Hanzo University

- [OpenCyber Architecture](https://docs.hanzo.ai/docs/cybersecurity/opencyber)

- **[CYB 201 — Agentic Cybersecurity](https://hanzo.university/agentic-cybersecurity)** ([Launch interactive lab on hanzo.app/learn](https://hanzo.app/learn/agentic-cybersecurity))
