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

Free lesson

Ranking threats and deciding what to do

After this lesson: I can rank threats by risk and choose a response for each one.

60 min lesson4 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

Fifty threats, one week

STRIDE gave the canteen team 52 questions. Answering them left a dozen real threats. The team has one week before the app goes live.

They cannot fix everything, so they need an order and a decision for each threat. A ranking that anyone can check beats the loudest voice in the room.

By the end of this lesson

Note

I can rank threats by risk and choose a response for each one.

Key words

WordWhat it meansExample
Likelihoodhow probable it is that a threat happens1 to 5
Impacthow much harm it does if it happens1 to 5
Risk scorelikelihood times impact
Mitigateadd a control that makes a threat less likely or less harmful
Residual riskthe risk left after a control is in place

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

Likelihood times impact gives a score

Give each threat a likelihood and an impact from 1 to 5. Their product is the risk score, from 1 to 25. The canteen team agreed three bands. A score of 10 or more is fixed now, 5 to 9 gets a planned fix, and 1 to 4 is accepted and watched.

An older scheme, DREAD, scored five things. Teams gave the same threat very different scores, so it fell out of use.

Scoring three canteen threats

ThreatLikelihoodImpactScoreBand
Change the order number to see other orders4312Fix now
Guess a weak password339Plan a fix
Edit the menu and deny it224Accept and watch

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

Try it: score and band three threats

Code: python
threats = [["Guess a weak password", 3, 3], ["Flood the order page", 2, 3], ["Steal a backup", 1, 5]]
for t in threats:
    score = t[1] * t[2]
    if score >= 10:
        decision = "fix now"
    elif score >= 5:
        decision = "plan a fix"
    else:
        decision = "accept and watch"
    print(score, t[0], "->", decision)
# Multi-factor sign-in lowers the likelihood of a guessed password to 2. Try it.

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

Four ways to respond to a threat

You can mitigate a threat with a control. You can accept it and watch for it. You can transfer it, as the canteen does by letting the card company handle card numbers. You can avoid it by not building the feature.

A control lowers the likelihood or the impact. What is left is the residual risk, and someone with authority signs it off.

A common mistake

Warning

Many people think a threat is gone once it has a control. A control lowers the score, it rarely makes it zero. After the ownership check the order number threat still scores 3. Record the residual risk, so it is accepted on purpose.

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

Write the ranking script, part 1

Command
docker exec jupyter sh -c "mkdir -p steps && printf '%s\n' 'import sys' 'threats = [' '    [\"Change the order number to see other orders\", 4, 3],' '    [\"Guess a weak password\", 3, 3],' '    [\"Flood the order page\", 2, 3],' '    [\"Edit the menu and deny it\", 2, 2],' '    [\"Read card details on the way\", 1, 5],' '    [\"Steal a database backup\", 1, 5],' '    [\"Change orders on the kitchen screen\", 1, 4],' ']' 'controls = {' '    \"Change the order number to see other orders\": 1,' '    \"Guess a weak password\": 2,' '}' 'if \"after\" in sys.argv:' '    for t in threats:' '        if t[0] in controls:' '            t[1] = controls[t[0]]' 'rows = []' 'for t in threats:' '    rows.append([t[1] * t[2], t[1], t[2], t[0]])' 'rows.sort(key=lambda r: -r[0])' 'total = 0' 'for r in rows:' '    if r[0] >= 10:' '        decision = \"fix now\"' '    elif r[0] >= 5:' '        decision = \"plan a fix\"' '    else:' '        decision = \"accept and watch\"' > steps/rank.py"

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

Write the ranking script, part 2

Command
docker exec jupyter sh -c "printf '%s\n' '    total = total + r[0]' '    print(str(r[0]).rjust(2), \"=\", r[1], \"x\", r[2], \" \", r[3].ljust(44), decision)' 'print(\"total risk\", total)' >> steps/rank.py"

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

Rank the seven threats

Command
docker exec jupyter python3 steps/rank.py

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

Rank them again after two controls

Command
docker exec jupyter python3 steps/rank.py after

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

What rank.py printed

RunTop threatFix nowTotal risk
BeforeChange the order number, 121 threat45
After the ownership check and multi-factorGuess a weak password and Flood the order page, 6 eachNone33

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

Assignment: rank the threats

Write the ranking the lab script made, without sorted.

score(likelihood, impact) returns their product. priority(points) returns 1 for 10 or more, 2 for 5 to 9 and 3 below that. rank(threats) takes a list of [name, likelihood, impact] and returns the names, highest score first. Threats with the same score keep their order, and the list you were given is not changed.

Code: python
def score(likelihood, impact):
    # Both are 1 to 5. The score is their product.
    return 0


def priority(points):
    # 1 for a score of 10 or more, 2 for 5 to 9, 3 for anything lower.
    return 0


def rank(threats):
    # threats is a list of [name, likelihood, impact]. Return the names, highest score first.
    # Two threats with the same score keep their order in the list. Do not use sorted.
    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.