Skip to content
Tutorials Center
My learning

Topics

Lesson 28 of 31 ยท Projects

Project: Vulnerability Risk Register

Build a vulnerability risk register in Python: compute CVSS v3.1 base scores, prioritize with context, track remediation deadlines and export a report.

A vulnerability scan on a medium-sized network can return hundreds of findings. Nobody can fix them all this week, so the real skill is deciding what to fix first and then making sure the fix actually happens. Teams keep a risk register for that: a living list of findings with a score, an owner, a deadline and a status. A register turns a pile of scanner output into a plan that managers can follow and auditors can check.

In this project you build a small risk register in Python. It computes real CVSS v3.1 base scores from vector strings, adjusts priority using context (how important the asset is, whether it faces the internet, whether exploitation has been seen), tracks remediation deadlines and statuses, and exports the result as text, CSV and JSON. All findings are invented and no system is scanned. Review Vulnerability Assessment Workflow if CVE and CVSS are new to you.

Real versus stand-in. Real registers live in a ticketing system, a GRC tool or a vulnerability management platform, and scores come from scanner results and vendor advisories. The CVSS formulas below are the real v3.1 base-score equations, so the scores match what published tools compute for the same vector. The findings, asset weights and due-date rules are invented examples; your organization's policy decides the real values.

The register at a glance

From finding to fix

Score CVSS base score from a vector.
Prioritize Adjust for asset and exposure.
Track Owner, due date, status.
Export Share the plan with others.

A score says how bad a flaw can be. Priority says what to do first.

1 / 2

Stage 1: compute CVSS base scores

A CVSS vector is a compact string such as AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H. Each pair is one metric: attack vector (AV), attack complexity (AC), privileges required (PR), user interaction (UI), scope (S), and the impact on confidentiality, integrity and availability (C, I, A). The base score combines an impact part (how much damage) and an exploitability part (how easy to trigger) using fixed weights, then rounds up to one decimal place.

The code below implements the v3.1 base equations and checks itself against three well-known results: the classic remote-takeover vector scores 9.8, the same vector with a changed scope scores 10.0, and a typical reflected cross-site scripting flaw scores 6.1.

Python Stage 1: a CVSS v3.1 base score calculator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The weights are fixed numbers from the CVSS specification, which is why different tools agree on the same vector. The roundup function exists because ordinary floating-point rounding can land a hair below a boundary and give a score one tenth too low. Also notice the ** 15 in the changed-scope impact: it is part of the official equation and quickly suppresses the correction for very high impact.

Stage 2: prioritize with context

The base score describes the flaw in isolation. It knows nothing about your environment. Two findings with the same score can deserve very different urgency: a medium flaw on the public login server may matter more than a high flaw on a machine that is switched off and unreachable. So registers add context multipliers, a practice similar in spirit to the CVSS environmental and temporal metrics but simpler to apply.

The simple model below multiplies the base score by three factors: how critical the asset is, whether it is internet-facing, and whether exploitation is known to be happening. It also assigns a due date from the final priority band. These factors and deadlines are a policy decision; treat the numbers as an example.

Python Stage 2: priority and due dates

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Compare the base score with the final priority. F-06 has the second-highest base score (8.8), but its priority drops to 7.0 because it sits on a low-value machine that is not exposed, so F-04 (base 7.8, but on an important build server) overtakes it. F-02, a modest 6.1, stays near the middle because it is reachable by anyone. This is the whole argument for context: without it, a team patches by number and still leaves the dangerous gaps open. Keep the reasoning visible in the register so a reviewer can disagree with a specific factor rather than with a mysterious final number.

Stage 3: track status and deadlines

A register is only useful if it is maintained. Each finding moves through a small set of states: open, in_progress, fixed, accepted. Not every move is legal: a finding cannot jump from open to fixed without somebody noting a retest, and accepting a risk, which means a conscious decision to live with it, needs an owner and an expiry date so it is reviewed again instead of forgotten.

We model that with a dataclass and one method that enforces the allowed transitions. Putting the rule in code gives you a register that cannot silently get into an invalid state.

Python Stage 3: statuses, owners and overdue items

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Two guard rails do the real work. ALLOWED is a tiny state machine, so the register refuses nonsense moves such as jumping straight from open to fixed, which would hide the retest. And move("accepted") demands an owner and an expiry date, which makes risk acceptance a visible, time-limited decision rather than a way to quietly make a problem disappear.

Stage 4: export a report

The register has two audiences. Engineers want a task list. Managers want counts and trends. We produce both from the same records: a short text summary, a CSV that opens in a spreadsheet, and JSON for other tools. Python's csv and json modules write into io.StringIO here instead of a file, because the browser sandbox has no real file system to save to; on your own computer you would pass an open file instead.

Python Stage 4: summary, CSV and JSON export

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A few habits make the export trustworthy. The summary computes everything from the records, never from typed-in numbers. CSV output includes derived columns such as overdue, so the spreadsheet user does not have to recompute them. And the JSON payload stays small and machine-friendly, which makes it easy to feed a dashboard or a ticket system later. When a figure in the report is ever in doubt, you can trace it back to the rows that produced it.

Ideas to extend the project

  • Add the CVSS temporal and environmental metrics instead of the simple multipliers, and compare the results.
  • Add a last_reviewed date and flag findings that nobody has touched for 30 days.
  • Record each status change in an audit log with a timestamp and the person who made it.
  • Read findings from a scanner's JSON export, see Vulnerability Scanners and Their Reports, instead of the hard-coded list.
  • Write the report for a non-technical reader, following Writing a Professional Security Report.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why can a finding with a lower base score be fixed before one with a higher base score?

    The base score describes the flaw in isolation. Priority combines it with your environment, so a medium flaw on a public, critical system can outrank a high flaw on an isolated machine.
  2. 2. What is the purpose of the roundup function in the CVSS calculation?

    CVSS v3.1 defines Roundup so that every implementation gets the same one-decimal result, even where binary floating point would be a hair low.
  3. 3. Why does accepting a risk in the register require an owner and an expiry date?

    Acceptance is a business decision. A named owner and an end date keep it visible and time-limited.
  4. 4. Why is the allowed-transition table useful?

    A small state machine encodes your process in code, so the register cannot drift into states that hide unfinished work.

Summary

  • A risk register is a maintained list of findings with a score, priority, owner, due date and status.
  • CVSS v3.1 turns a vector string into a base score with fixed weights and a defined round-up rule.
  • Base score is not priority: adjust for asset value, exposure and known exploitation, and keep the reasoning visible.
  • Deadlines follow from the priority band; overdue findings need escalation.
  • Enforce valid status changes in code, and make risk acceptance time-limited and owned.
  • Export the same records as a readable summary, CSV and JSON so each audience gets what it needs.

Continue with Practice Exercises with Solutions.