Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Drawing a system as a data flow diagram

After this lesson: I can draw a system as a data flow diagram with its trust boundaries.

60 min lesson5 commandsJupyterLab data science lab: pandas, Matplotlib and scikit-learn in the browser

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Where would you break in?

Your college canteen launches an app. Students order lunch, pay by card and collect it at noon. The kitchen sees each order on a screen.

Before anyone tests the app, someone has to ask where it could be attacked. You cannot answer that until you can see the whole system on one page.

By the end of this lesson

Note

I can draw a system as a data flow diagram with its trust boundaries.

Key words

WordWhat it means
Threat modela written record of what could go wrong and what you will do
Data flow diagrama picture of how data moves through a system
External entitya person or system outside your control
Processcode that takes data in and does something with it
Data storea place where data rests, such as a database
Trust boundarya line where the level of trust changes

The cells students fill in are left blank in this preview.

Starter

Have a go

Starter

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Four questions make a threat model

A threat model answers four questions. What are we working on? What can go wrong? What are we going to do about it? Did we do a good job?

This lesson answers the first one. Lessons 2 and 3 find what can go wrong. Lessons 4 and 5 decide what to do. Lesson 6 keeps the answers up to date.

The five parts of a data flow diagram

PartDrawn asIn the canteen app
External entityA boxStudent, Card payments, Admin
ProcessA circle or rounded boxWeb app, Kitchen screen
Data storeTwo parallel linesOrders database
Data flowAn arrow with a labelsave order, payment result
Trust boundaryA dashed lineBetween the internet and the college

The cells students fill in are left blank in this preview.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

The canteen app as a data flow diagram

flowchart LR
  S["Student"] -->|sign in and order| W(("Web app"))
  W -->|order status| S
  W -->|save order| D[("Orders database")]
  D -->|orders to cook| K(("Kitchen screen"))
  W -->|payment request| C["Card payments"]
  C -->|payment result| W
  A["Admin"] -->|edit menu| D

Trust boundaries show where attacks start

A trust boundary is where data moves between places you trust differently. The internet and the college network are two zones. So are the card company and the staff office.

Any flow that crosses a boundary needs a question: who sent this, and can I believe it? Most threats you find later sit on those crossings.

Try it: which flows cross a boundary?

Code: python
# Each element: name, kind, zone. Each flow: label, from, to.
zone = {"Student": "internet", "Web app": "college", "Orders database": "college"}
flows = [
    ["sign in", "Student", "Web app"],
    ["save order", "Web app", "Orders database"],
]
for f in flows:
    if zone[f[1]] != zone[f[2]]:
        print(f[0], "crosses a trust boundary")
    else:
        print(f[0], "stays inside", zone[f[1]])
# Add a flow ["payment", "Web app", "Card payments"] and a zone for Card payments.

Make a free account to save your work and track your progress.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

The model is data you can check

In the lab the canteen app is written as two lists. Each element has a name, a kind and a zone. Each flow has a label, a start and an end.

The script counts each kind, marks every crossing and checks one rule. Data must pass through a process. A flow from a person straight into a data store means some code is missing from the drawing.

Write the diagram script, part 1

Command
docker exec jupyter sh -c "mkdir -p steps && printf '%s\n' 'import sys' 'elements = [' '    [\"Student\", \"external entity\", \"internet\"],' '    [\"Web app\", \"process\", \"college\"],' '    [\"Orders database\", \"data store\", \"college\"],' '    [\"Kitchen screen\", \"process\", \"college\"],' '    [\"Card payments\", \"external entity\", \"payments\"],' '    [\"Admin\", \"external entity\", \"staff\"],' ']' 'flows = [' '    [\"sign in and order\", \"Student\", \"Web app\"],' '    [\"order status\", \"Web app\", \"Student\"],' '    [\"save order\", \"Web app\", \"Orders database\"],' '    [\"orders to cook\", \"Orders database\", \"Kitchen screen\"],' '    [\"payment request\", \"Web app\", \"Card payments\"],' '    [\"payment result\", \"Card payments\", \"Web app\"],' '    [\"edit menu\", \"Admin\", \"Orders database\"],' ']' 'if \"fixed\" in sys.argv:' '    elements.append([\"Admin page\", \"process\", \"college\"])' > steps/dfd.py"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write the diagram script, part 2

Command
docker exec jupyter sh -c "printf '%s\n' '    flows[6] = [\"edit menu\", \"Admin\", \"Admin page\"]' '    flows.append([\"menu changes\", \"Admin page\", \"Orders database\"])' 'kind = {}' 'zone = {}' 'for e in elements:' '    kind[e[0]] = e[1]' '    zone[e[0]] = e[2]' 'for k in [\"external entity\", \"process\", \"data store\"]:' '    n = 0' '    for e in elements:' '        if e[1] == k:' '            n = n + 1' '    print(k, n)' 'print(\"data flows\", len(flows))' 'crossing = 0' 'for f in flows:' '    note = \"\"' '    if not zone[f[1]] == zone[f[2]]:' '        note = \"   CROSSES \" + zone[f[1]] + \" | \" + zone[f[2]]' '        crossing = crossing + 1' '    print(f[0] + \":\", f[1], \"to\", f[2] + note)' 'print(\"crossing a trust boundary:\", crossing)' 'bad = 0' 'for f in flows:' '    if not kind[f[1]] == \"process\" and not kind[f[2]] == \"process\":' '        print(\"CHECK:\", f[0], \"joins\", f[1], \"to\", f[2], \"with no process between\")' >> steps/dfd.py"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write the diagram script, part 3

Command
docker exec jupyter sh -c "printf '%s\n' '        bad = bad + 1' 'if bad == 0:' '    print(\"every flow passes through a process\")' >> steps/dfd.py"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Check the canteen diagram

Command
docker exec jupyter python3 steps/dfd.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

What dfd.py printed

LineMeaning
external entity 3, process 2, data store 1Six elements
data flows 7Seven arrows
crossing a trust boundary: 5Five flows to question first
CHECK: edit menu joins Admin to Orders databaseA flow with no process between

The cells students fill in are left blank in this preview.

A common mistake

Warning

Many people think a data flow diagram should show every class and function. It shows where data goes and where trust changes. Draw a process for each part that handles data, and stop when the boundaries are clear.

Add the missing Admin page

Command
docker exec jupyter python3 steps/dfd.py fixed

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Assignment: check a diagram

Write the checks the lab script made, for any diagram.

An element is [name, kind, zone] and a flow is [label, from, to]. zone_of(elements, name) returns the zone of the named element. crossing(elements, flows) returns the labels of flows whose ends are in different zones, in order. no_process(elements, flows) returns the labels of flows where neither end is a process.

Code: python
def zone_of(elements, name):
    # elements is a list of [name, kind, zone]. Return the zone of the named one.
    return ""


def crossing(elements, flows):
    # flows is a list of [label, from, to]. Return the labels whose two ends are in different zones.
    return []


def no_process(elements, flows):
    # Return the labels of flows where neither end is a "process".
    return []

Make a free account to save your work and track your progress.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.