Security Architecture Lens
Cognitive Mode: Security
Primary Question: "Where are the trust boundaries?"
Focus: Trust Boundaries, Validation Layers, Path Contracts, Process Isolation
When to Use
- Need to understand security architecture
- Documenting trust boundaries and validation
- Analyzing path contracts and isolation
- User invokes
/arch-lens-security or /make-arch-diag security
Critical Constraints
NEVER:
- Modify any source code files
- Expose actual secrets or credentials
- Show implementation details that could aid attacks
ALWAYS:
- Focus on TRUST BOUNDARIES
- Show validation layers in order
- Document path contracts and restrictions
- Include process isolation mechanisms
- BEFORE creating any diagram, LOAD the
/mermaid skill using the Skill tool - this is MANDATORY
Analysis Workflow
Step 1: Launch Parallel Exploration Subagents
Spawn Explore subagents to investigate:
Input Validation
- Find input validation code
- Identify sanitization patterns
- Look for: validate, sanitize, clean, escape, input validation
Path Security
- Find path validation/restriction code
- Identify forbidden patterns
- Look for: path, traversal, .., forbidden, whitelist, blacklist
Process Boundaries
- Find subprocess/isolation code
- Identify timeouts and guards
- Look for: subprocess, Popen, timeout, isolation, sandbox
Authentication/Authorization
- Find auth-related code
- Identify permission checks
- Look for: auth, permission, token, API key, credential
Secret Management
- Find secret handling
- Identify env var usage
- Look for: secret, API_KEY, credential, .env, gitignore
File System Security
- Find file access controls
- Identify write zone restrictions
- Look for: write_zone, allowed_paths, snapshot, file_change
Database Isolation
- Find database access controls
- Identify per-user/per-tenant isolation
- Look for: isolation, tenant, scope, multi-tenancy
Step 2: Map Trust Boundaries
Identify boundaries where trust changes:
- External -> Application (user input)
- Application -> Subprocess (code execution)
- Application -> FileSystem (file access)
- Application -> Database (data access)
- Application -> External API (outbound)
CRITICAL - Analyze Read/Write Direction:
For EVERY trust boundary crossing:
- Inbound (reads): Data entering from less trusted to more trusted
- Outbound (writes): Data leaving from more trusted to less trusted
- Validation point: Where is data validated and in which direction?
Security implications by direction:
- Reads from untrusted: Requires input validation
- Writes to untrusted: Requires output encoding/sanitization
- Reads from trusted storage: Generally safe
- Writes to trusted storage: Requires authorization check
Step 3: Document Validation Layers
For each trust boundary:
- What is validated?
- How are violations handled?
- What's the defense-in-depth strategy?
Step 4: Create the Diagram
Use flowchart with:
Direction: TB for layered security view
Subgraphs per Trust Boundary:
- Entry (CLI/API input)
- Subprocess Boundary
- FileSystem Boundary
- Path Contract
- Write Zone Enforcement
- Database Isolation
Node Styling:
cli class: Entry points, user input
detector class: Validation gates, guards
phase class: Processing after validation
gap class: Forbidden/restricted (yellow warning)
stateNode class: Enforcement points
output class: Isolated resources
Show Flow Through Boundaries:
- Sequential validation layers
- What passes vs what's blocked
Step 5: Write Output
Write the diagram to: temp/arch-lens-security/arch_diag_security_{YYYY-MM-DD_HHMMSS}.md
Output Template
# Security Diagram: {System Name}
**Lens:** Security (Trust Boundaries)
**Question:** Where are the trust boundaries?
**Date:** {YYYY-MM-DD}
**Scope:** {What was analyzed}
## Trust Boundaries Overview
| Boundary | Validation | Threat Mitigated |
|----------|------------|------------------|
| {boundary} | {validation} | {threat} |
## Security Diagram
```mermaid
%%{init: {'flowchart': {'nodeSpacing': 40, 'rankSpacing': 50, 'curve': 'basis'}}}%%
flowchart TB
%% CLASS DEFINITIONS %%
classDef cli fill:#1a237e,stroke:#7986cb,stroke-width:2px,color:#fff;
classDef stateNode fill:#004d40,stroke:#4db6ac,stroke-width:2px,color:#fff;
classDef handler fill:#e65100,stroke:#ffb74d,stroke-width:2px,color:#fff;
classDef phase fill:#6a1b9a,stroke:#ba68c8,stroke-width:2px,color:#fff;
classDef detector fill:#b71c1c,stroke:#ef5350,stroke-width:2px,color:#fff;
classDef output fill:#00695c,stroke:#4db6ac,stroke-width:2px,color:#fff;
classDef gap fill:#ff6f00,stroke:#ffa726,stroke-width:2px,color:#000;
subgraph Boundary1 ["TRUST BOUNDARY 1: Entry"]
INPUT["User Input<br/>━━━━━━━━━━<br/>Untrusted"]
VALIDATE["Validation<br/>━━━━━━━━━━<br/>Check input"]
end
subgraph Boundary2 ["TRUST BOUNDARY 2: Subprocess"]
PRECHECK["Pre-flight Check<br/>━━━━━━━━━━<br/>Limits check"]
SUBPROCESS["Subprocess<br/>━━━━━━━━━━<br/>Isolated execution"]
GUARD["Process Guard<br/>━━━━━━━━━━<br/>Timeout, cleanup"]
end
subgraph PathContract ["PATH CONTRACT"]
FORBIDDEN["Forbidden Patterns<br/>━━━━━━━━━━<br/>credentials, .pem"]
TRAVERSAL["Traversal Check<br/>━━━━━━━━━━<br/>No '..' allowed"]
WHITELIST["Directory Whitelist<br/>━━━━━━━━━━<br/>Allowed paths"]
end
subgraph WriteZone ["WRITE ZONE ENFORCEMENT"]
ZONE["Write Zone<br/>━━━━━━━━━━<br/>Restricted area"]
end
%% FLOW %%
INPUT --> VALIDATE
VALIDATE --> PRECHECK
PRECHECK --> SUBPROCESS
SUBPROCESS --> GUARD
GUARD --> FORBIDDEN
FORBIDDEN --> TRAVERSAL
TRAVERSAL --> WHITELIST
WHITELIST --> ZONE
%% CLASS ASSIGNMENTS %%
class INPUT cli;
class VALIDATE,PRECHECK,GUARD detector;
class SUBPROCESS phase;
class FORBIDDEN,TRAVERSAL gap;
class WHITELIST stateNode;
class ZONE output;
Color Legend:
| Color |
Category |
Description |
| Dark Blue |
Entry |
Untrusted input |
| Red |
Validation |
Validation gates and guards |
| Purple |
Process |
Isolated execution |
| Yellow |
Restricted |
Forbidden patterns |
| Teal |
Enforcement |
Whitelist, allowed |
| Dark Teal |
Zone |
Protected resources |
Security Validation Layers
| Layer |
Component |
Threat Mitigated |
| 1 |
{component} |
{threat} |
| 2 |
{component} |
{threat} |
Path Contract Rules
| Rule |
Description |
| Forbidden Patterns |
{patterns} |
| Traversal Prevention |
{how} |
| Whitelist |
{allowed dirs} |
---
## Pre-Diagram Checklist
Before creating the diagram, verify:
- [ ] LOADED `/mermaid` skill using the Skill tool
- [ ] Using ONLY classDef styles from the mermaid skill (no invented colors)
- [ ] Diagram will include a color legend table
---
## Related Skills
- `/make-arch-diag` - Parent skill for lens selection
- `/mermaid` - MUST BE LOADED before creating diagram
- `/arch-lens-error-resilience` - For error handling view
- `/audit-arch` - For security violation detection
1---2name: arch-lens-security3description: Create Security architecture diagram showing trust boundaries, validation layers, and process isolation. Security lens answering "Where are the trust boundaries?"4---56# Security Architecture Lens78**Cognitive Mode:** Security9**Primary Question:** "Where are the trust boundaries?"10**Focus:** Trust Boundaries, Validation Layers, Path Contracts, Process Isolation1112## When to Use1314- Need to understand security architecture15- Documenting trust boundaries and validation16- Analyzing path contracts and isolation17- User invokes `/arch-lens-security` or `/make-arch-diag security`1819## Critical Constraints2021**NEVER:**22- Modify any source code files23- Expose actual secrets or credentials24- Show implementation details that could aid attacks2526**ALWAYS:**27- Focus on TRUST BOUNDARIES28- Show validation layers in order29- Document path contracts and restrictions30- Include process isolation mechanisms31- BEFORE creating any diagram, LOAD the `/mermaid` skill using the Skill tool - this is MANDATORY3233---3435## Analysis Workflow3637### Step 1: Launch Parallel Exploration Subagents3839Spawn Explore subagents to investigate:4041**Input Validation**42- Find input validation code43- Identify sanitization patterns44- Look for: validate, sanitize, clean, escape, input validation4546**Path Security**47- Find path validation/restriction code48- Identify forbidden patterns49- Look for: path, traversal, .., forbidden, whitelist, blacklist5051**Process Boundaries**52- Find subprocess/isolation code53- Identify timeouts and guards54- Look for: subprocess, Popen, timeout, isolation, sandbox5556**Authentication/Authorization**57- Find auth-related code58- Identify permission checks59- Look for: auth, permission, token, API key, credential6061**Secret Management**62- Find secret handling63- Identify env var usage64- Look for: secret, API_KEY, credential, .env, gitignore6566**File System Security**67- Find file access controls68- Identify write zone restrictions69- Look for: write_zone, allowed_paths, snapshot, file_change7071**Database Isolation**72- Find database access controls73- Identify per-user/per-tenant isolation74- Look for: isolation, tenant, scope, multi-tenancy7576### Step 2: Map Trust Boundaries7778Identify boundaries where trust changes:791. **External -> Application** (user input)802. **Application -> Subprocess** (code execution)813. **Application -> FileSystem** (file access)824. **Application -> Database** (data access)835. **Application -> External API** (outbound)8485**CRITICAL - Analyze Read/Write Direction:**86For EVERY trust boundary crossing:87- **Inbound (reads)**: Data entering from less trusted to more trusted88- **Outbound (writes)**: Data leaving from more trusted to less trusted89- **Validation point**: Where is data validated and in which direction?9091Security implications by direction:92- **Reads from untrusted**: Requires input validation93- **Writes to untrusted**: Requires output encoding/sanitization94- **Reads from trusted storage**: Generally safe95- **Writes to trusted storage**: Requires authorization check9697### Step 3: Document Validation Layers9899For each trust boundary:100- What is validated?101- How are violations handled?102- What's the defense-in-depth strategy?103104### Step 4: Create the Diagram105106Use flowchart with:107108**Direction:** `TB` for layered security view109110**Subgraphs per Trust Boundary:**111- Entry (CLI/API input)112- Subprocess Boundary113- FileSystem Boundary114- Path Contract115- Write Zone Enforcement116- Database Isolation117118**Node Styling:**119- `cli` class: Entry points, user input120- `detector` class: Validation gates, guards121- `phase` class: Processing after validation122- `gap` class: Forbidden/restricted (yellow warning)123- `stateNode` class: Enforcement points124- `output` class: Isolated resources125126**Show Flow Through Boundaries:**127- Sequential validation layers128- What passes vs what's blocked129130### Step 5: Write Output131132Write the diagram to: `temp/arch-lens-security/arch_diag_security_{YYYY-MM-DD_HHMMSS}.md`133134---135136## Output Template137138```markdown139# Security Diagram: {System Name}140141**Lens:** Security (Trust Boundaries)142**Question:** Where are the trust boundaries?143**Date:** {YYYY-MM-DD}144**Scope:** {What was analyzed}145146## Trust Boundaries Overview147148| Boundary | Validation | Threat Mitigated |149|----------|------------|------------------|150| {boundary} | {validation} | {threat} |151152## Security Diagram153154```mermaid155%%{init: {'flowchart': {'nodeSpacing': 40, 'rankSpacing': 50, 'curve': 'basis'}}}%%156flowchart TB157 %% CLASS DEFINITIONS %%158 classDef cli fill:#1a237e,stroke:#7986cb,stroke-width:2px,color:#fff;159 classDef stateNode fill:#004d40,stroke:#4db6ac,stroke-width:2px,color:#fff;160 classDef handler fill:#e65100,stroke:#ffb74d,stroke-width:2px,color:#fff;161 classDef phase fill:#6a1b9a,stroke:#ba68c8,stroke-width:2px,color:#fff;162 classDef detector fill:#b71c1c,stroke:#ef5350,stroke-width:2px,color:#fff;163 classDef output fill:#00695c,stroke:#4db6ac,stroke-width:2px,color:#fff;164 classDef gap fill:#ff6f00,stroke:#ffa726,stroke-width:2px,color:#000;165166 subgraph Boundary1 ["TRUST BOUNDARY 1: Entry"]167 INPUT["User Input<br/>━━━━━━━━━━<br/>Untrusted"]168 VALIDATE["Validation<br/>━━━━━━━━━━<br/>Check input"]169 end170171 subgraph Boundary2 ["TRUST BOUNDARY 2: Subprocess"]172 PRECHECK["Pre-flight Check<br/>━━━━━━━━━━<br/>Limits check"]173 SUBPROCESS["Subprocess<br/>━━━━━━━━━━<br/>Isolated execution"]174 GUARD["Process Guard<br/>━━━━━━━━━━<br/>Timeout, cleanup"]175 end176177 subgraph PathContract ["PATH CONTRACT"]178 FORBIDDEN["Forbidden Patterns<br/>━━━━━━━━━━<br/>credentials, .pem"]179 TRAVERSAL["Traversal Check<br/>━━━━━━━━━━<br/>No '..' allowed"]180 WHITELIST["Directory Whitelist<br/>━━━━━━━━━━<br/>Allowed paths"]181 end182183 subgraph WriteZone ["WRITE ZONE ENFORCEMENT"]184 ZONE["Write Zone<br/>━━━━━━━━━━<br/>Restricted area"]185 end186187 %% FLOW %%188 INPUT --> VALIDATE189 VALIDATE --> PRECHECK190 PRECHECK --> SUBPROCESS191 SUBPROCESS --> GUARD192193 GUARD --> FORBIDDEN194 FORBIDDEN --> TRAVERSAL195 TRAVERSAL --> WHITELIST196197 WHITELIST --> ZONE198199 %% CLASS ASSIGNMENTS %%200 class INPUT cli;201 class VALIDATE,PRECHECK,GUARD detector;202 class SUBPROCESS phase;203 class FORBIDDEN,TRAVERSAL gap;204 class WHITELIST stateNode;205 class ZONE output;206```207208**Color Legend:**209| Color | Category | Description |210|-------|----------|-------------|211| Dark Blue | Entry | Untrusted input |212| Red | Validation | Validation gates and guards |213| Purple | Process | Isolated execution |214| Yellow | Restricted | Forbidden patterns |215| Teal | Enforcement | Whitelist, allowed |216| Dark Teal | Zone | Protected resources |217218## Security Validation Layers219220| Layer | Component | Threat Mitigated |221|-------|-----------|------------------|222| 1 | {component} | {threat} |223| 2 | {component} | {threat} |224225## Path Contract Rules226227| Rule | Description |228|------|-------------|229| Forbidden Patterns | {patterns} |230| Traversal Prevention | {how} |231| Whitelist | {allowed dirs} |232```233234---235236## Pre-Diagram Checklist237238Before creating the diagram, verify:239240- [ ] LOADED `/mermaid` skill using the Skill tool241- [ ] Using ONLY classDef styles from the mermaid skill (no invented colors)242- [ ] Diagram will include a color legend table243244---245246## Related Skills247248- `/make-arch-diag` - Parent skill for lens selection249- `/mermaid` - MUST BE LOADED before creating diagram250- `/arch-lens-error-resilience` - For error handling view251- `/audit-arch` - For security violation detection