Lesson 09 Architectural Defenses
Theme:

Homework: Security Architecture for an AI Code Review Assistant

Goal: Design a complete security architecture for an AI-powered code review assistant that reads repositories, posts comments on pull requests, and accesses internal documentation. Your architecture must address at least 5 defense layers.

Assignment 1: Define the System

The AI Code Review Assistant ("ReviewBot") has these capabilities:

CapabilityDescriptionRisk Level
Read repository codeClone and read files from Git repositoriesLow
Analyze codeUse LLM to identify bugs, style issues, security vulnerabilitiesLow
Post PR commentsWrite review comments on pull request diffsMedium
Approve/request changesSubmit PR review with approve/request-changes statusHigh
Access documentationQuery internal docs for coding standards and guidelinesLow
Run static analysisExecute linting and security scanning tools on codeMedium

Threat scenarios to consider:

  1. A malicious PR contains code comments with injection payloads designed to manipulate the review
  2. An attacker embeds instructions in variable names or strings to bypass security checks
  3. A PR modifies a README with hidden instructions to auto-approve the PR
  4. An attacker tries to make the bot post embarrassing or harmful comments
  5. An attacker tries to exfiltrate internal documentation through the bot's review comments

Assignment 2: Design the Architecture

Create your architecture addressing these 5 defense layers. For each layer, specify the concrete components and policies.

Layer 1: Input Validation

How do you validate the code/PR content before the LLM processes it?

Layer 2: LLM Architecture

How do you structure the LLM components?

Layer 3: Tool Permissions

What guardrails do you place on each tool?

Layer 4: Output Filtering

How do you filter the bot's output before posting?

Layer 5: Monitoring and Detection

How do you detect attacks in progress or after the fact?

Assignment 3: Draw the Architecture Diagram

Create a text-based architecture diagram that shows all components and data flows. Use this template as a starting point:

┌─────────────────────────────────────────────────────────┐
│                    REVIEWBOT ARCHITECTURE                │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  ┌──────────┐     ┌─────────────────┐                   │
│  │  GitHub   │────▶│ Input Validator  │                   │
│  │ Webhook   │     │ (sanitize, scan) │                   │
│  └──────────┘     └────────┬────────┘                   │
│                            │                            │
│                   ┌────────▼────────┐                   │
│                   │   ... YOUR      │                   │
│                   │   DESIGN ...    │                   │
│                   └────────┬────────┘                   │
│                            │                            │
│                   ┌────────▼────────┐                   │
│                   │ Output Filter   │                   │
│                   │ (scan comments) │                   │
│                   └────────┬────────┘                   │
│                            │                            │
│                   ┌────────▼────────┐                   │
│                   │  GitHub API     │                   │
│                   │ (post comments) │                   │
│                   └─────────────────┘                   │
│                                                         │
│  ┌─────────────────────────────────────┐                │
│  │ MONITORING: Logs, Alerts, Dashboard │                │
│  └─────────────────────────────────────┘                │
│                                                         │
│  ┌─────────────────────────────────────┐                │
│  │ AIR-GAPPED: Auth, Billing, Admin    │                │
│  └─────────────────────────────────────┘                │
└─────────────────────────────────────────────────────────┘

Fill in the middle section with your complete architecture, showing:

Assignment 4: Threat Analysis

For each of the 5 threat scenarios from Assignment 1, trace through your architecture and document:

FieldDescription
ThreatDescription of the attack
Attack VectorHow the attacker delivers the payload
Defense Layer 1First defense that engages (and does it stop the attack?)
Defense Layer 2Second defense if first fails
Defense Layer 3Third defense if second fails
Worst CaseWhat happens if ALL defenses fail?
Blast RadiusMaximum damage the attacker can cause

Complete this analysis for all 5 threat scenarios.

Self-Check Criteria

CriterionTarget
Architecture addresses at least 5 defense layersRequired
Diagram shows all components with data flow arrowsRequired
Human-in-the-loop checkpoints identified≥ 2 checkpoints
Air-gapped systems identified≥ 2 systems
RBAC/permission model defined for toolsRequired
Output filtering rules specifiedRequired
Threat analysis completed for all 5 scenariosRequired
Worst-case blast radius is limited (not catastrophic)Required

Reflection question: What is the most dangerous threat scenario for ReviewBot, and which architectural defense provides the most protection against it? If you could add only one more defense mechanism, what would it be?