|
1 | | -# inspect |
| 1 | +<p align="center"> |
| 2 | + <h1 align="center">Inspect</h1> |
| 3 | + <p align="center"> |
| 4 | + <strong>Security vulnerability scanner for code</strong> |
| 5 | + </p> |
| 6 | + <p align="center"> |
| 7 | + <a href="https://golang.org/"><img src="https://img.shields.io/badge/Go-1.23+-00ADD8?style=flat-square&logo=go&logoColor=white" alt="Go"></a> |
| 8 | + <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square" alt="License"></a> |
| 9 | + <a href="https://github.com/GrayCodeAI/inspect/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/GrayCodeAI/inspect/ci.yml?style=flat-square&label=tests" alt="CI"></a> |
| 10 | + </p> |
| 11 | +</p> |
2 | 12 |
|
3 | | -Website security auditing and crawling library for Go. Crawls sites concurrently, runs checks and declarative rules, generates findings with severity and CWE references. |
| 13 | +--- |
4 | 14 |
|
5 | | -## Design |
| 15 | +Inspect scans code for security vulnerabilities, anti-patterns, and potential issues. It provides actionable findings with severity ratings and remediation guidance. |
6 | 16 |
|
7 | | -- **Library + CLI** — importable library with optional `inspect-ci` binary |
8 | | -- **No LLM dependency** — pure static analysis on crawled pages |
9 | | -- **Extensible** — custom checks (Go code) + declarative rules (no code required) |
| 17 | +## Features |
10 | 18 |
|
11 | | -## Install |
| 19 | +- **Multi-language support** - Scans Go, Python, JavaScript, TypeScript, and more |
| 20 | +- **OWASP coverage** - Detects common vulnerability patterns |
| 21 | +- **Custom rules** - Define project-specific security policies |
| 22 | +- **CI/CD integration** - Fails builds on critical issues |
| 23 | + |
| 24 | +## Quick Start |
12 | 25 |
|
13 | 26 | ```bash |
14 | | -go get github.com/GrayCodeAI/inspect@latest |
| 27 | +go get github.com/GrayCodeAI/inspect |
15 | 28 | ``` |
16 | 29 |
|
17 | | -## Usage |
| 30 | +```go |
| 31 | +import "github.com/GrayCodeAI/inspect" |
18 | 32 |
|
19 | | -### One-shot scan |
| 33 | +scanner := inspect.NewScanner( |
| 34 | + inspect.WithRules(inspect.DefaultRules), |
| 35 | +) |
20 | 36 |
|
21 | | -```go |
22 | | -report, err := inspect.Scan(ctx, "https://example.com", inspect.Standard) |
| 37 | +report, err := scanner.Scan(ctx, "./path/to/code") |
23 | 38 | for _, f := range report.Findings { |
24 | | - fmt.Printf("[%s] %s: %s\n", f.Severity, f.URL, f.Message) |
| 39 | + fmt.Printf("[%s] %s - %s\n", f.Severity, f.Rule, f.Message) |
25 | 40 | } |
26 | | -if report.Failed() { |
27 | | - os.Exit(1) |
28 | | -} |
29 | | -``` |
30 | | - |
31 | | -### Reusable scanner |
32 | | - |
33 | | -```go |
34 | | -scanner := inspect.NewScanner(inspect.Standard) |
35 | | -r1, _ := scanner.Scan(ctx, "https://site-a.com") |
36 | | -r2, _ := scanner.Scan(ctx, "https://site-b.com") |
37 | | -``` |
38 | | - |
39 | | -### Directory scan (local files) |
40 | | - |
41 | | -```go |
42 | | -report, _ := scanner.ScanDir(ctx, "./public") |
43 | 41 | ``` |
44 | 42 |
|
45 | | -## Presets |
| 43 | +## Examples |
46 | 44 |
|
47 | | -| Preset | Depth | Checks | Use case | |
48 | | -|--------|-------|--------|----------| |
49 | | -| Quick | 1 | security | Fast header check | |
50 | | -| Standard | 3 | all (default) | Balanced audit | |
51 | | -| Deep | 10 | all | Comprehensive crawl | |
52 | | -| SecurityOnly | 3 | security | Security audit | |
53 | | -| CI | 3 | all + fail-on | CI/CD gates | |
54 | | - |
55 | | -## Built-in Checks |
56 | | - |
57 | | -| Check | Detects | |
58 | | -|-------|---------| |
59 | | -| Security Headers | Missing CSP, HSTS, X-Frame-Options, X-Content-Type-Options | |
60 | | -| TLS/Certificates | Weak ciphers, expired certs, mixed content | |
61 | | -| CORS | Overly permissive Access-Control-Allow-Origin | |
62 | | -| Broken Links | 404s, timeouts, unreachable URLs | |
63 | | -| Forms | Missing CSRF tokens, insecure action URLs | |
64 | | -| Accessibility | Missing alt text, contrast issues, ARIA violations | |
65 | | -| Performance | Large resources, render-blocking scripts | |
66 | | -| SEO | Missing meta tags, broken structured data | |
67 | | -| SRI | Missing subresource integrity on CDN scripts | |
68 | | - |
69 | | -## Custom Checks |
70 | | - |
71 | | -```go |
72 | | -type Checker interface { |
73 | | - Name() string |
74 | | - Run(ctx context.Context, pages []*Page) []Finding |
75 | | -} |
76 | | - |
77 | | -inspect.RegisterCheck(&MyCustomChecker{}) |
78 | | -``` |
79 | | - |
80 | | -## Declarative Rules |
81 | | - |
82 | | -```go |
83 | | -inspect.RegisterRule(inspect.RuleCheck{ |
84 | | - RuleName: "HSTS Missing", |
85 | | - RuleSeverity: inspect.High, |
86 | | - HeaderMissing: []string{"Strict-Transport-Security"}, |
87 | | - FixSuggestion: "Add HSTS header with max-age >= 31536000", |
88 | | -}) |
89 | | -``` |
| 45 | +See the [examples/](examples/) directory for runnable code samples. |
90 | 46 |
|
91 | 47 | ## Configuration |
92 | 48 |
|
93 | | -File-based config via `.inspect.toml`: |
94 | | - |
95 | | -```toml |
96 | | -depth = 5 |
97 | | -concurrency = 10 |
98 | | -timeout = "30s" |
99 | | -fail-on = "high" |
100 | | -checks = ["security", "links", "forms"] |
101 | | -exclude = ["/admin/*", "/api/*"] |
102 | | -``` |
103 | | - |
104 | | -## Output Formats |
105 | | - |
106 | | -- Terminal (colored, human-readable) |
107 | | -- JSON |
108 | | -- JUnit XML (CI integration) |
109 | | -- HTML report |
110 | | -- Markdown |
111 | | - |
112 | | -## CI/CD Integration |
113 | | - |
114 | | -### GitHub Action |
| 49 | +Create `.inspect.yaml` to customize scanning: |
115 | 50 |
|
116 | 51 | ```yaml |
117 | | -- uses: GrayCodeAI/inspect@v0.4.0 |
118 | | - with: |
119 | | - url: https://staging.example.com |
120 | | - fail-on: high |
121 | | - format: junit |
122 | | -``` |
123 | | -
|
124 | | -### CLI |
125 | | -
|
126 | | -```bash |
127 | | -inspect-ci --url https://example.com --fail-on high --format junit |
128 | | -``` |
129 | | - |
130 | | -## Testing |
131 | | - |
132 | | -```bash |
133 | | -make test # Unit tests |
134 | | -make test-race # With race detector |
135 | | -make bench # Benchmarks |
136 | | -make cover # Coverage report |
| 52 | +rules: |
| 53 | + - name: no-hardcoded-secrets |
| 54 | + severity: critical |
| 55 | + - name: sql-injection |
| 56 | + severity: high |
| 57 | +ignore: |
| 58 | + - vendor/ |
| 59 | + - testdata/ |
137 | 60 | ``` |
138 | 61 |
|
139 | 62 | ## License |
140 | 63 |
|
141 | | -MIT |
142 | | - |
143 | | -## New Features (Wave 1-4) |
144 | | - |
145 | | -### Soft 404 Detection |
146 | | -Inspect detects "soft 404s" — pages that return HTTP 200 but actually contain error messages or empty content. This reduces false positives in link checking and accessibility audits. |
147 | | - |
148 | | -### Per-Host Circuit Breaker |
149 | | -When a host starts returning errors, inspect automatically throttles requests to that host to prevent cascading failures. The circuit breaker: |
150 | | -- Opens after N consecutive errors (default: 5) |
151 | | -- Resets after a cooldown period (default: 30s) |
152 | | -- Tracks per-host health metrics |
153 | | - |
154 | | -### Scan Result Archive Format |
155 | | -Inspect can export scan results as a gzipped JSON archive (.inspect.gz) containing: |
156 | | -- Full scan metadata (host, duration, URL counts) |
157 | | -- Per-URL results (status code, content type, body hash, headers) |
158 | | -- Summary statistics (status code distribution, error rate) |
159 | | - |
160 | | -Archives can be read back with ReadArchive() for analysis or comparison. |
161 | | - |
162 | | -### Findings Storage Bridge |
163 | | -Scan findings can be persisted to an external store (yaad-compatible) for tracking security posture over time. Supports batch writes and auto-flush. |
164 | | - |
165 | | -## Ecosystem |
166 | | -Inspect is part of the hawk-eco platform: |
167 | | -- **hawk** — CLI/REPL that orchestrates all tools |
168 | | -- **sight** — code review and security analysis |
169 | | -- **eyrie** — LLM provider layer |
170 | | -- **yaad** — memory/recall engine |
171 | | -- **tok** — token counting and cost estimation |
172 | | -- **trace** — session capture and replay |
| 64 | +MIT - see [LICENSE](LICENSE) for details. |
0 commit comments