Threat modelling a featureProLesson 40 of 45, about 8 min
- 1
- 2
- 3
- 4
- 5
- 6
- 7
The app: Sentinel, a security console
SentinelHarbor / File sharingthreat model
Share a file by link: every request, and where it goes
Press a request that comes from outside Harbor to mark it as an entry point.
The threat model, and the code behind the feature
threat-model.md Sentinel writes it as you go
# Threat model: share a file by link
An owner makes a link to one file. Anyone with the link downloads it.
## Data flow
1. Owner’s browser → Harbor API POST /api/files/4120/share signed in
2. Harbor API → database save the share
3. Anyone with the link → Harbor API GET /s/4120?expires=…
4. Harbor API → files bucket read the file
## Entry points
None marked yet.
## Threats (0), highest risk first
None yet. Ask the six questions.
The agent’s first draft not shipped yet
1// app/api/files/[id]/share/route.ts: the owner asks for a link2export async function POST(req, { params }) {3 const user = await requireUser(req);4 const { id } = await params;5 const expires = Math.floor(Date.now() / 1000) + 7 * 86400;6 return Response.json({ url: `https://harbor.example/s/${id}?expires=${expires}` });7}8 9// app/s/[id]/route.ts: anyone with the link downloads the file10export async function GET(req, { params }) {11 const { id } = await params;12 const expires = Number(req.nextUrl.searchParams.get("expires"));13 if (Date.now() / 1000 > expires) return new Response("Link expired", { status: 410 });14 const file = await db.file.findUnique({ where: { id: Number(id) } });15 return streamFile(file);16}
The MagisterThis is Sentinel, Harbor’s security console. Before file sharing ships, Sam wants a threat model: owners make a link, anyone with the link downloads the file. Start with the data flow. Mark each request that comes from outside Harbor: those are your entry points.
Step 1 of 7Mark where outsiders come in
- Both requests from outside Harbor are marked
- Tap the entry point that needs no sign-in
You’re not signed in, so this lesson won’t be saved to your path. Sign in free to keep your XP.