Threat Surface Analysis
Systematic codebase investigation to discover the attack surface — services, dependencies, authentication, and trust boundaries. Language-agnostic, works across any ecosystem.
When to Use
- Security review of a new or unfamiliar codebase
- Threat modeling preparation (discovering what to model)
- Architecture discovery for legacy systems
- Identifying external service connections and auth mechanisms
- Finding unprotected endpoints or misconfigured trust boundaries
Core Principles
- Intent-based classification — classify by runtime purpose and behavior, not project name
- Evidence, not conclusions — record what was found; defer interpretation
- Unknowns are valuable — "Auth: Unknown" is better than guessing
- Source projects are anchors — entry points (web apps, functions, CLIs) become threat surfaces. Libraries are invisible.
- Config flows DOWN — a source project's config covers all its library dependencies
Phase 1: Ecosystem Detection
Discover all programming languages, build systems, and infrastructure-as-code in the repository.
Procedure (aim for ~5 tool calls)
- List workspace root — one level deep
- Scan for manifests using the table below (1–2 calls)
- Identify ecosystem groups — a repo may contain multiple (e.g., .NET + React + Terraform)
- Read workspace descriptors —
.sln, package.json workspaces, go.work, etc.
- Form hypothesis — 2–3 sentences on what the system does
Manifest → Ecosystem Mapping
| Manifest Pattern |
Ecosystem |
*.sln, *.csproj, *.fsproj |
.NET |
package.json |
Node.js / TypeScript |
go.mod |
Go |
pyproject.toml, requirements.txt, Pipfile |
Python |
pom.xml, build.gradle, build.gradle.kts |
Java / Kotlin |
Cargo.toml |
Rust |
Gemfile |
Ruby |
*.bicep, *.tf, *.tfvars |
Infrastructure as Code |
docker-compose.yml, Dockerfile |
Container / Docker |
azure-pipelines.yml, .github/workflows/*.yml |
CI/CD Pipeline |
Output
## Ecosystem Groups
Group 1: <Ecosystem>
Workspace descriptor: <path>
Projects: <list>
Dependency format: <e.g., PackageReference in .csproj>
Config patterns: <e.g., appsettings.json>
Shared / Cross-cutting:
IaC files: <list>
CI/CD files: <list>
Phase 2: Project Classification
Classify every project by type and assign preliminary trust boundaries.
Classification Priority (first match wins)
| Priority |
Signal |
ProjectType |
| 1 |
Test framework dependency (xunit, jest, pytest, etc.) |
Test (exclude) |
| 2 |
HTTP server framework (Express, ASP.NET, Flask, etc.) |
WebApplication |
| 2 |
Serverless function framework |
FunctionApp |
| 2 |
Background worker / task processor |
WorkerService |
| 2 |
Client-side SPA (React, Angular, Blazor WASM) |
ClientApp |
| 2 |
gRPC server |
GrpcService |
| 3 |
Produces executable + CLI entrypoint |
ConsoleApplication |
| 4 |
No executable output, exports only |
Library |
Trust Boundary Defaults
| Deployment Pattern |
Trust Boundary |
| Cloud-hosted (Azure, AWS, GCP) |
Cloud |
| Runs locally / dev tooling |
On-Premises |
| CI/CD pipeline tooling |
DevOps |
| Client-side / browser |
Client |
Source vs Library Rule
- Source projects = entry points (web apps, functions, CLIs, workers). These become threat-surface components.
- Libraries = internal code compiled into source projects. Not standalone components.
- Transitive dependency rule: SourceProject → Library → SDK → External Service. Only the SourceProject and External Service matter for threat modeling.
Phase 3: Code Investigation
Produce a structured evidence artifact identifying services, dependencies, and authentication.
Sub-phases
3a — Dependency Graph (3–4 reads)
For each source project:
- Read project manifests — extract internal references + external packages
- Resolve transitive dependencies — walk library chain to find all external SDKs
- Read infrastructure files (Bicep, Terraform, Docker) — reveal services not in code
SDK-to-Service reasoning: Every SDK package name reveals the service it connects to. Reason from the service brand name in the package.
3b — Configuration & Auth (2–3 reads)
For each source project, read config from:
- Project's own directory (authoritative)
- Library dependencies (transitive)
- Shared/root config (
.env, docker-compose.yml)
- IaC files
URL discovery: Any config key whose value is a URL or whose name suggests an endpoint (*BaseUrl, *Endpoint, *ApiUrl) points to an external service.
3c — Code Confirmation (2–3 reads)
Read entry points and DI/service registration to confirm:
- Service client construction
- HTTP client usage and targets
- Database connections
- Message broker clients
- Auth middleware
- Telemetry setup
Authentication Evidence Hierarchy
| Evidence |
Classification |
| Endpoint URL only, no credentials |
Auth: Unknown |
| Endpoint + key/secret/token |
Auth: API Key |
| Endpoint + client ID + secret |
Auth: Service Principal |
| Endpoint + client ID + certificate |
Auth: Certificate |
| Endpoint + managed identity / default credential |
Auth: Managed Identity |
| OAuth scopes without credential |
Auth: OAuth (unconfirmed) |
Phase 4: Investigation Evidence Output
# Investigation Evidence
## System Overview
- **Service Name:** <name>
- **Description:** <1–2 sentences>
- **Ecosystems:** <detected groups>
## Project Topology
| Project | Ecosystem | Type | Role | Trust Boundary | Key External Packages |
| ------- | --------- | ---- | ---- | -------------- | --------------------- |
| MyApp.Api | .NET | WebApplication | Source | Cloud | Azure.Storage, MSAL |
| MyApp.Core | .NET | Library | Library | N/A | — |
## Discovered Services & Resources
### 1. <Service Name>
- **SDK:** <package, which project>
- **Config:** <key, value, which file>
- **IaC:** <resource type, which file>
- **Code:** <client construction, which file>
- **Auth:** <mechanism and evidence>
## Cross-Project Links
- <how source projects relate to each other>
## Auth Summary
| Service | Mechanism | Evidence |
| ------- | --------- | -------- |
## Trust Boundary Diagram
(Generate a Mermaid flowchart showing trust boundaries and data flows)
## Confidence & Open Questions
- **Confidence:** High | Medium | Low
- **Open items:** <unresolved findings>
Threat Surface Indicators
After investigation, flag these threat surface concerns:
| Indicator |
Risk |
Priority |
External endpoint with Auth: Unknown |
Unauthenticated access |
Critical |
| API key in config file (not secrets store) |
Credential exposure |
High |
| No input validation on HTTP endpoints |
Injection attacks |
High |
| Cross-boundary data flow without encryption |
Data in transit exposure |
High |
| Service with broad permissions (admin/owner) |
Excessive privilege |
Medium |
| Unmonitored external dependency |
Supply chain risk |
Medium |
| Missing rate limiting on public endpoints |
DoS vulnerability |
Medium |
Integration with Other Skills
| Skill |
Relationship |
security-review |
Uses this skill's output as input for STRIDE analysis |
security-threat-modeler |
Produces formal threat model from investigation evidence |
semantic-codebase-intelligence |
Complements with coupling/cohesion metrics |
architecture-audit |
Verifies docs match discovered architecture |
Limitations
- Does not produce a formal threat model (use
security-threat-modeler for that)
- Cannot discover runtime-only services not reflected in code or config
- Auth classification is evidence-based — production secrets are not read
- IaC resources without code references may be missed if not in scanned directories
1---2name: threat-surface-analysis3description: Discover a codebase's threat surface through systematic investigation — map ecosystem groups, dependency graphs, service connections, authentication mechanisms, and trust boundaries. Use when performing threat modeling, security review, or architectural analysis of any multi-ecosystem repository.4---5
6# Threat Surface Analysis
7
8Systematic codebase investigation to discover the attack surface — services, dependencies, authentication, and trust boundaries. Language-agnostic, works across any ecosystem.
9
10## When to Use
11
12- Security review of a new or unfamiliar codebase
13- Threat modeling preparation (discovering what to model)
14- Architecture discovery for legacy systems
15- Identifying external service connections and auth mechanisms
16- Finding unprotected endpoints or misconfigured trust boundaries
17
18---
19
20## Core Principles
21
22- **Intent-based classification** — classify by runtime purpose and behavior, not project name
23- **Evidence, not conclusions** — record what was found; defer interpretation
24- **Unknowns are valuable** — "Auth: Unknown" is better than guessing
25- **Source projects are anchors** — entry points (web apps, functions, CLIs) become threat surfaces. Libraries are invisible.
26- **Config flows DOWN** — a source project's config covers all its library dependencies
27
28---
29
30## Phase 1: Ecosystem Detection
31
32Discover all programming languages, build systems, and infrastructure-as-code in the repository.
33
34### Procedure (aim for ~5 tool calls)
35
361. **List workspace root** — one level deep
372. **Scan for manifests** using the table below (1–2 calls)
383. **Identify ecosystem groups** — a repo may contain multiple (e.g., .NET + React + Terraform)
394. **Read workspace descriptors** — `.sln`, `package.json` workspaces, `go.work`, etc.
405. **Form hypothesis** — 2–3 sentences on what the system does
41
42### Manifest → Ecosystem Mapping
43
44| Manifest Pattern | Ecosystem |
45| ---------------- | --------- |
46| `*.sln`, `*.csproj`, `*.fsproj` | .NET |
47| `package.json` | Node.js / TypeScript |
48| `go.mod` | Go |
49| `pyproject.toml`, `requirements.txt`, `Pipfile` | Python |
50| `pom.xml`, `build.gradle`, `build.gradle.kts` | Java / Kotlin |
51| `Cargo.toml` | Rust |
52| `Gemfile` | Ruby |
53| `*.bicep`, `*.tf`, `*.tfvars` | Infrastructure as Code |
54| `docker-compose.yml`, `Dockerfile` | Container / Docker |
55| `azure-pipelines.yml`, `.github/workflows/*.yml` | CI/CD Pipeline |
56
57### Output
58
59```markdown
60## Ecosystem Groups
61
62Group 1: <Ecosystem>
63 Workspace descriptor: <path>
64 Projects: <list>
65 Dependency format: <e.g., PackageReference in .csproj>
66 Config patterns: <e.g., appsettings.json>
67
68Shared / Cross-cutting:
69 IaC files: <list>
70 CI/CD files: <list>
71```
72
73---
74
75## Phase 2: Project Classification
76
77Classify every project by type and assign preliminary trust boundaries.
78
79### Classification Priority (first match wins)
80
81| Priority | Signal | ProjectType |
82| -------- | ------ | ----------- |
83| 1 | Test framework dependency (xunit, jest, pytest, etc.) | Test (exclude) |
84| 2 | HTTP server framework (Express, ASP.NET, Flask, etc.) | WebApplication |
85| 2 | Serverless function framework | FunctionApp |
86| 2 | Background worker / task processor | WorkerService |
87| 2 | Client-side SPA (React, Angular, Blazor WASM) | ClientApp |
88| 2 | gRPC server | GrpcService |
89| 3 | Produces executable + CLI entrypoint | ConsoleApplication |
90| 4 | No executable output, exports only | Library |
91
92### Trust Boundary Defaults
93
94| Deployment Pattern | Trust Boundary |
95| ------------------ | -------------- |
96| Cloud-hosted (Azure, AWS, GCP) | Cloud |
97| Runs locally / dev tooling | On-Premises |
98| CI/CD pipeline tooling | DevOps |
99| Client-side / browser | Client |
100
101### Source vs Library Rule
102
103- **Source projects** = entry points (web apps, functions, CLIs, workers). These become threat-surface components.
104- **Libraries** = internal code compiled into source projects. Not standalone components.
105- **Transitive dependency rule**: SourceProject → Library → SDK → External Service. Only the SourceProject and External Service matter for threat modeling.
106
107---
108
109## Phase 3: Code Investigation
110
111Produce a structured evidence artifact identifying services, dependencies, and authentication.
112
113### Sub-phases
114
115#### 3a — Dependency Graph (3–4 reads)
116
117For each source project:
1181. Read project manifests — extract internal references + external packages
1192. Resolve transitive dependencies — walk library chain to find all external SDKs
1203. Read infrastructure files (Bicep, Terraform, Docker) — reveal services not in code
121
122**SDK-to-Service reasoning**: Every SDK package name reveals the service it connects to. Reason from the service brand name in the package.
123
124#### 3b — Configuration & Auth (2–3 reads)
125
126For each source project, read config from:
1271. Project's own directory (authoritative)
1282. Library dependencies (transitive)
1293. Shared/root config (`.env`, `docker-compose.yml`)
1304. IaC files
131
132**URL discovery**: Any config key whose value is a URL or whose name suggests an endpoint (`*BaseUrl`, `*Endpoint`, `*ApiUrl`) points to an external service.
133
134#### 3c — Code Confirmation (2–3 reads)
135
136Read entry points and DI/service registration to confirm:
137- Service client construction
138- HTTP client usage and targets
139- Database connections
140- Message broker clients
141- Auth middleware
142- Telemetry setup
143
144### Authentication Evidence Hierarchy
145
146| Evidence | Classification |
147| -------- | -------------- |
148| Endpoint URL only, no credentials | `Auth: Unknown` |
149| Endpoint + key/secret/token | `Auth: API Key` |
150| Endpoint + client ID + secret | `Auth: Service Principal` |
151| Endpoint + client ID + certificate | `Auth: Certificate` |
152| Endpoint + managed identity / default credential | `Auth: Managed Identity` |
153| OAuth scopes without credential | `Auth: OAuth (unconfirmed)` |
154
155---
156
157## Phase 4: Investigation Evidence Output
158
159```markdown
160# Investigation Evidence
161
162## System Overview
163- **Service Name:** <name>
164- **Description:** <1–2 sentences>
165- **Ecosystems:** <detected groups>
166
167## Project Topology
168
169| Project | Ecosystem | Type | Role | Trust Boundary | Key External Packages |
170| ------- | --------- | ---- | ---- | -------------- | --------------------- |
171| MyApp.Api | .NET | WebApplication | Source | Cloud | Azure.Storage, MSAL |
172| MyApp.Core | .NET | Library | Library | N/A | — |
173
174## Discovered Services & Resources
175
176### 1. <Service Name>
177- **SDK:** <package, which project>
178- **Config:** <key, value, which file>
179- **IaC:** <resource type, which file>
180- **Code:** <client construction, which file>
181- **Auth:** <mechanism and evidence>
182
183## Cross-Project Links
184- <how source projects relate to each other>
185
186## Auth Summary
187
188| Service | Mechanism | Evidence |
189| ------- | --------- | -------- |
190
191## Trust Boundary Diagram
192
193(Generate a Mermaid flowchart showing trust boundaries and data flows)
194
195## Confidence & Open Questions
196- **Confidence:** High | Medium | Low
197- **Open items:** <unresolved findings>
198```
199
200---
201
202## Threat Surface Indicators
203
204After investigation, flag these threat surface concerns:
205
206| Indicator | Risk | Priority |
207| --------- | ---- | -------- |
208| External endpoint with `Auth: Unknown` | Unauthenticated access | Critical |
209| API key in config file (not secrets store) | Credential exposure | High |
210| No input validation on HTTP endpoints | Injection attacks | High |
211| Cross-boundary data flow without encryption | Data in transit exposure | High |
212| Service with broad permissions (admin/owner) | Excessive privilege | Medium |
213| Unmonitored external dependency | Supply chain risk | Medium |
214| Missing rate limiting on public endpoints | DoS vulnerability | Medium |
215
216---
217
218## Integration with Other Skills
219
220| Skill | Relationship |
221| ----- | ------------ |
222| `security-review` | Uses this skill's output as input for STRIDE analysis |
223| `security-threat-modeler` | Produces formal threat model from investigation evidence |
224| `semantic-codebase-intelligence` | Complements with coupling/cohesion metrics |
225| `architecture-audit` | Verifies docs match discovered architecture |
226
227---
228
229## Limitations
230
231- Does not produce a formal threat model (use `security-threat-modeler` for that)
232- Cannot discover runtime-only services not reflected in code or config
233- Auth classification is evidence-based — production secrets are not read
234- IaC resources without code references may be missed if not in scanned directories