Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Threat modelling is the process of identifying and analysing potential security threats and vulnerabilities in a system, application, or network.

To mitigate potential security risks with a balanced budget, security threat modelling is critical.

Python is an interpreted general-purpose computer language. Using Python programs or creating Python software in a secure way requires insight into all potential security threats.

Scope

Every high-quality threat model starts with a clearly defined scope.

This helps establish a clean separation between Python-specific security threats (those tied to the language, its standard library, or common Python idioms) and general threats (those that could affect software regardless of implementation language).

In Scope:

When testing Python applications for security weaknesses, the scope of our threat model includes a software program written in Python.

The Python program may provide functionality in one or both of the following ways:

This scope intentionally excludes:

Out of scope:

Below the core high level Python Treat model:

python threat model

STRIDE Threat Model

The following table summarizes the classic STRIDE threat categories, with precise definitions using consistent British English phrasing suitable for security documentation.

ThreatThreat Definition
SpoofingPretending to be something or someone other than oneself
TamperingUnauthorised modification of data on disk, in network transit, in memory, or in other locations
RepudiationDenying responsibility for an action or event (whether the claim is true or false)
Information DisclosureUnauthorised access to or exposure of sensitive or confidential information
Denial of ServiceMaking a service unavailable by exhausting or depleting required resources
Elevation of PrivilegeGaining higher access rights or permissions than originally authorised

Common Python threats

Some common threats for a Python program are:

Spoofing

Spoofing occurs when an entity pretends to be something or someone else, undermining authentication controls. In the context of Python programs, the following are common spoofing threats:

Tampering

Tampering involves the unauthorised modification of data, code, or program behaviour. In the context of Python programs, the following tampering threats are particularly relevant:

Repudiation

Repudiation occurs when an actor can deny having performed an action (or when there is insufficient evidence to prove responsibility). In Python programs, repudiation threats often stem from the lack of reliable audit trails or from actions that deliberately obscure accountability:

Information Disclosure

Information disclosure (also known as a privacy breach or data leak) occurs when sensitive, confidential, or personally identifiable information is exposed to unauthorised parties. In the context of Python programs, the following are common vectors for information disclosure:

Denial of Service

A malicious Python program can cause denial-of-service (DoS) conditions in several ways:

Elevation of Privilege

A malicious Python program running with elevated privileges (more permissions than necessary) can cause severe damage in several ways:

Typical Threat Actors for Python

In a generic threat model for Python (including the language runtime, standard library, ecosystem, and applications written in Python), the following personas are commonly considered:

Create Your Own Python Threat Model for testing

Using our general Python threat model as a foundation makes it much easier to create a tailored threat model specific to your testing use case.

Follow these steps to develop one:

  1. Apply the STRIDE model
    Systematically identify potential threats by categorising them according to the STRIDE framework (developed by Microsoft):

    • Spoofing — impersonation of users, processes, or systems

    • Tampering — unauthorised modification of data or code

    • Repudiation — denial of actions or events

    • Information disclosure — unauthorised access to sensitive data

    • Denial of service — disruption of availability or performance

    • Elevation of privilege — gaining unauthorised higher-level access

    Map these threat categories to the components, data flows, trust boundaries, and actors in your Python-based system.

  2. Define the scope and context
    Clearly determine the boundaries of the Python software to which your threat model applies. Consider:

    • The specific application, library, script, or deployment (e.g., a web service, CLI tool, data pipeline, or embedded script).

    • The environment (development, production, cloud, on-premises, containerised, etc.).

    • Key assets (data, code, credentials, configuration).

    • External dependencies (third-party packages, CPython interpreter version, OS interactions).

    • Relevant actors (developers, end users, administrators, adversaries).
      Document assumptions, out-of-scope items, and any known constraints.

  3. Discuss, refine, and evaluate the threat model
    Collaborate with relevant stakeholders (developers, security team, operations) to:

    • Review identified threats for completeness and relevance.

    • Assess likelihood, impact, and risk severity (e.g., using qualitative scales like Low/Medium/High).

    • Prioritise threats and propose mitigations or controls (e.g., input validation, least privilege, dependency pinning, secure coding practices).

    • Validate assumptions and update the model as the system evolves.

    • Iterate periodically or after significant changes (new features, dependencies, deployments).

By following this structured approach, you can produce a practical, actionable threat model that aligns security efforts with your particular Python project.