Skip to content
ImagineWorld

Threat Modeling of Software

node_idnode-book_threat-modeling-best-practices_chapter-04-threat-modeling-of-software
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num4
chapter_titleThreat Modeling of Software
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

From mobile apps to medical devices, software powers modern technology. However, its rapid evolution makes it particularly susceptible to threats. Integrating threat modeling into the software development life cycle (SDLC) ensures that security is addressed from the start, which significantly reduces the cost and effort of fixing issues later. Threat modeling in the SDLC can identify threats during analysis and design, guiding architectural decisions and secure coding practices. As testing of the software progresses, threat models should drive the creation of misuse and abuse cases, while helping to ensure that implemented controls are effectively mitigating risks. Proactively incorporating threat modeling minimizes downstream risks such as data breaches, compliance violations, and reputational damage.

In this chapter, we’ll cover how threat modeling can participate in fast-paced Agile environments. The chapter will also delve into how, by embedding security into the SDLC, organizations will be able to align security efforts with business goals while maintaining flexibility to adapt to evolving threats. This chapter will highlight strategies for leveraging threat modeling across development stages, enabling development and security teams to manage their unique threat landscape effectively and with confidence.

In this chapter, we’ll cover the following topics:

  • Threat modeling in the SDLC
  • Usage of threat modeling in the different SDLC stages
  • Managing threats throughout the SDLC
  • Case study: New York City Cyber Command

Software is everywhere. It runs on web servers that serve applications over the internet, on the phones in our pockets, the smart televisions in our homes, the medical devices in a hospital, the automobiles we drive, and the hundreds of sensors that run in a single factory. There is no shortage of it. Threat modeling requires examining threats across the entire system, including hardware, network, and software. Among these, software is often the most brittle component. Hardware typically needs physical access, and the network often has a robust and well-developed defense in depth. Software, however, can be ephemeral, changing monthly, weekly, daily, or even hourly. Each change brings a changing threat model.

Threat modeling in the SDLC can be thought of as the practice of identifying, evaluating, and addressing threats during the design phase of software creation. This should ideally be completed before a single line of code has been written, enabling an organization to ship code that is secure from the start.

The role of threat modeling in software security

Section titled “The role of threat modeling in software security”

Identifying vulnerabilities early in the SDLC is more cost-effective than finding them later, such as when software is in a production environment. What is unique about software is the speed at which remediations and mitigations can be integrated into the development pipeline and brought to a production environment.

Many organizations that develop software operate in an Agile environment, which allows them, in theory, to gather feedback from production and respond rapidly with changes to resolve any issues that may arise. While this is not a book on Agile, it’s important to understand the basics of how software gets from ideation to production and to have a continuous feedback loop that ensures any issues or findings in production are brought back to the development team for resolution.

This starts with gathering and understanding the requirements that are derived from customers or the product owner. This goes into an architecture and design phase, which then gets implemented at the development phase as written and working code. The feature or product is then tested internally and externally (by the customer), where feedback is incorporated back into requirements, and the process continues. What is somewhat unique about Agile practices is that these iterations around the flywheel can be as short as a week or two, meaning that requirements can be generated and later deployed in production in a matter of days.

Figure 4.1: A basic view of the stages of the SDLC

Figure 4.1: A basic view of the stages of the SDLC

Consider an example where a product owner identifies a customer requirement: “Users need the ability to filter search results by price range.” During the architecture and design phase, the team diagrams how the filter component will interact with the search API and database. Developers implement the price filter during the development stage and deploy it to a testing environment, where QA tests the functionality internally. The feature is then deployed to production, where customers immediately begin using it. This cycle can be completed within days in most modern development teams and shows how quickly Agile teams iterate from identified need to working software.

That is a huge shift from some engineering cycles that can take weeks, months, or even longer to go from requirement to production. But that doesn’t mean that threat modeling is dead in software development environments. Far from it.

When threats are identified early in the SDLC, it allows the development team to code or redesign the remediations before the code goes into a production environment. Finding threats early allows you to address them early and thereby reduce remediation costs, with potential savings of up to 95% compared to fixing issues in production. The bottom line is that early detection transforms vulnerability management from a reactive and expensive challenge into a proactive, cost-effective strategy.

While threat modeling any system will reveal some common findings, such as unauthorized access and denial of service, there are a few that are specific to software. For instance, software is typically built in what’s called a continuous integration/continuous deployment (CI/CD) pipeline. This pipeline takes the code written by a developer, runs tests, integrates it with code written by other developers in the organization or even by third-party development teams, and packages it to eventually be deployed to a production environment.

While the CI/CD pipeline makes it extremely easy to deploy software at a rapid pace, this pipeline alone can expand the attack surface. We often use the phrase “security in the pipeline and of the pipeline” when referring to protecting the CI/CD pipeline, and it requires its own security controls to be in place. For example, security of the pipeline should mean protecting the Jenkins server or GitHub actions that can be compromised through unpatched vulnerabilities or malicious code injection that can deploy backdoors. I call this out to simply highlight the unique environment that software development operates in and why finding threats early can help devise better security controls overall.

While early discovery directly reduces the remediation expenses, it also mitigates potential downstream risks such as data breaches, reputational damage, and regulatory penalties while simultaneously optimizing development resources and maintaining agility. This benefit is not unique to software; however, software often has broader implications that can impact regulatory compliance.

Threat modeling of software in a perfect world

Section titled “Threat modeling of software in a perfect world”

I say perfect world, because software moves fast and doesn’t often allow for a heavy threat modeling process to interrupt that flow; that allows us to take a more lightweight approach to threat modeling techniques. Consider the security architecture diagram that we created in Chapter 2. It takes time to gather the required documentation, create the diagram, and generate a report on findings. In software development, by the time you have what you need, the diagrams are likely outdated. Waiting for the architecture work to be done is more akin to a waterfall approach (waiting for stages to complete before starting the next) and is an approach we would see outside of modern software development.

However, let’s assume that you can get your hands on completed architecture documentation and have the luxury of time. You will be able to follow the process from previous chapters of creating a security architecture diagram from the data flow diagram, the actors (both sanctioned and malicious), as well as, hopefully, a completed C4 model. All of these are components that are necessary for most development teams to get started.

While some applications and features are developed with little to no documentation, this is not considered a best practice. Most organizations strive for a higher level of maturity that requires more stringent oversight of their development processes and practices. In practice, you are likely to see less documentation in smaller shops or start-ups compared to larger enterprises, although there are always gaps and exceptions, regardless of the size of the organization.

Once you have reviewed the current architecture documentation, you’ll gather your questions and feedback to meet with the architecture team and review their documentation. This will likely generate more questions for you and them, but it will put you on the path of creating or refining the security architecture diagram. As a reminder, the security architecture diagram should contain the core components in the system, the flow of data, the actors (both bad and good), the trust boundaries, and the third-party connections.

The process of generating this diagram will depend on the complexity of the system being modeled and can range from a few hours to a few days. Your goal here is to develop the potential threats and understand what security controls exist in the organization and design, and which ones still need to be implemented. If you are in an organization that supports gating activity before all the documentation is completed, you will be able to provide feedback to the architecture and development team before any code is written. This works especially well when you are on the same deadlines and timeframes as the architecture team is on.

Best practice

If a tree falls in the forest and nobody is there to hear it, does it make a sound? Does identifying threats with no way of getting them to the right people make a difference? Nothing will kill your threat modeling activities quicker than having no means of letting the architecture or development team know. It’s important to identify where the development team gets their work items from and where they document their designs. You should be putting your documentation and findings there as well. How do they communicate? You need to be using the same channels. The threat modeling practice should not be secretive and should be open and accessible.

At this time, you’ve met with the architecture and development teams to vet their design while providing your feedback on the security architecture diagram with preliminary findings and both assumed and missing security controls. There is likely to be some back and forth regarding what security controls exist and perhaps assumptions about the design that were not correct. There may also just be additional discoveries based on time and the activity of reviewing the design.

Once everyone leaves the review with action items, the design is revised based on the findings, and the security architecture design gets integrated into a final threat model report that includes the design, the findings, the security controls, and tracking tickets for the work. This is the perfect world scenario and not one that you are likely to see in a modern software development practice, given the time constraints.

The reality of threat modeling of software

Section titled “The reality of threat modeling of software”

So, where does that leave us with generating a threat model for software in most other organizations? As mentioned previously, ideally, you will have the ability to get your hands on documentation early in the software development process, which is likely in the form of requirements or architectural analysis. Each organization may refer to this documentation differently and may have different owners of it, but knowing what is being worked on and putting yourself in the workflow for this information is vital. This will help you, the security architect, to familiarize yourself with what is being proposed: whether it’s a new application, a feature, or some other type of significant change.

You can access this information by ensuring that you are in the design meetings, are notified as documentation or decisions are being made. You may need to request access to the ticketing or feature tracking software that is being used by the development team to monitor for upcoming potential work. In these venues, you can use the simple Shostack Four-Question Framework that we covered before.

You may not always have the luxury of time or clear documentation, but being more integrated with your development counterparts and the overall development process in the organization will help you understand the work that is going on in space. This will lead to more quality interactions with your counterparts and a much better understanding of the architecture you are being asked to review. In other words, it’s better to be more familiar with the product development and architecture before you are asked to review it.

We’re now going to cover what threat modeling looks like in a practical software development environment.

Usage of threat modeling in different SDLC stages

Section titled “Usage of threat modeling in different SDLC stages”

The effectiveness of threat modeling depends heavily on when it occurs within the SDLC. For instance, conducting threat modeling during the analysis or design phases can eliminate most threats. While organizations can apply threat modeling at any SDLC stage, it is more optimal to do so before developers write code. Understanding each SDLC stage reveals where threat modeling integration delivers maximum security improvements with minimal development friction. Figure 4.2 depicts how most Agile software development stages look:

Figure 4.2: Stages of an Agile development life cycle

Figure 4.2: Stages of an Agile development life cycle

In the analysis phase, the product owners or product managers will take the incoming requirements and analyze the problem that needs to be solved and their potential solutions. This is also where most prioritization occurs for the solutions. In the design phase, the stakeholders will determine what the final product will look like and how it will perform. This may require the clarification of findings from the analysis phase.

The development phase is where code is brought into reality, at least at its early stages. There may be early feedback given to the stakeholders to show progress as well as ensure that the solution is moving in the right direction. During testing, the testing team will attempt to identify defects in the solution and locate areas where the solution is not functioning as intended.

Once the code is thoroughly tested and any defects are resolved, it is ready to be deployed to the environment. This leads to the continuous care and feeding of the solution through maintenance until it is decommissioned.

This is a general, high-level process of the SDLC followed in most organizations. In this Agile environment, this cycle repeats in short sprints to get the features out to customers quickly. In this process, threat modeling is most effective during the analysis and design phase. This aligns with the perfect world scenario discussed earlier. In this case, the documentation is collected, the security architect reviews the proposed design, and security requirements are generated to close any security gaps. These are then integrated with the other features and design requests and prioritized accordingly.

Just a bit of caution on priority. It can be a huge sticking point as the security requirements will likely be up against other features that are being requested by the product team. This is where the security architect and the broader security organization need to be able to translate security requirements and controls into business terms that raise them past common nuisance and into general acceptance.

For instance, rather than explaining “ Our authentication system lacks multi-factor authentication,” describe the scenario as “Cybercriminals will use credential stuffing to compromise customer accounts, make fraudulent purchases with stored payment methods, and lock legitimate customers out of their accounts. Customers who can’t access their accounts to complete purchases will abandon carts, creating X amount in lost revenue, and file chargebacks, damaging our payment processor standing. We would need X amount in development costs to prevent this scenario.”

Threat modeling during development and testing

Section titled “Threat modeling during development and testing”

During the development phase, the threat model should serve as a reference for implementing security controls identified by the security architect in partnership with the development teams. Ideally, these controls are integrated directly into the architecture diagram and description, giving the developers a single source of truth rather than separate architecture and security diagrams. In other words, the threats identified during threat modeling should be incorporated directly into the development team’s architecture artifacts. At the final stage of developing the security, the product team should prioritize these security controls and allocate necessary time and resources to get them completed.

For example, consider a scenario where, during the threat modeling exercise, the security architect identifies missing controls in the proposed file upload function. In this case, the security architect would recommend input validation to ensure that malicious files are rejected through file size limits to prevent denial-of-service attacks, require the use of a MIME type allow list to block potentially dangerous file types, and perform deep content inspection to verify that actual file contents match the declared type. Additionally, the security architect would also recommend that secure file handling be reinforced through measures such as generating random IDs for filenames to prevent path traversal attacks, applying secure file permissions to restrict unauthorized access, and sanitizing file extensions to mitigate command injection risks.

Access controls further protect the service by verifying user permissions before allowing uploads, restricting file uploads to a designated directory, and adhering to the principle of least privilege when setting file permissions. An audit trail adds another layer of defense by enabling detailed logging of all upload attempts, tracking file metadata, and recording security events for both successes and failures. Lastly, error handling ensures that system details are not leaked through error responses, failures are comprehensively logged, and security-related exceptions are handled appropriately with a robust hierarchy.

While these controls can work together to mitigate a range of threats identified during threat modeling, they should be baked into the design to provide a unified architecture.

By analyzing the identified threats, their potential impacts, and the security controls needed to address them, developers can make informed decisions on implementing the required controls. They might request additional information on the required controls from the security architect to provide clarity. Once the controls are coded and implemented, the developers get the security architect to be a part of the code review process. While this is not common in many organizations, it will go a long way in solidifying the relationship between the security architect and the development team.

If you’ve never participated in a code review, consider yourself lucky. This is a review of your written code that takes place in the presence of your peers and other team members (often senior developers and architects). It’s like buying an ugly car that you absolutely adore and having your friends tell you that it’s ugly.

During these code reviews, the security controls that have been developed should be reviewed in the context of the overall threat model to ensure that the controls have been employed appropriately. The threat model should be referenced and the implementation confirmed through questioning the developer, reviewing the code, and reviewing the running application.

Moving to the testing phase, the theoretical threats should become practical scenarios, opening the opportunity to be tested and validated either by a test engineer or by a penetration testing or red team.

Best practices

Do you want to know whether the threat scenario that you identified in the threat model is valid or not? Create a test case that can be executed to confirm or challenge your scenarios with regard to the threat model. By creating test cases that directly map to identified threats, teams can verify the effectiveness of their security controls and confirm the validity of the threat model.

Automation plays a vital role here. By incorporating security tests into the CI pipeline, teams can quickly detect when changes introduce new vulnerabilities or weaken existing protections. This automated approach provides consistent validation while reducing the manual effort required for security testing.

Misuse and abuse cases that are driven by the threat model can be particularly handy during testing. They simulate how attackers might attempt to exploit the system and should include both expected attack patterns and edge cases that might lead to unexpected vulnerabilities. It’s important to write these cases in a way that can be executed by someone without security knowledge, or at the very least, you should assume that the person executing the test case is not a security engineer.

Building in the threat model assumptions and outputs into the development and testing phase ensures that the threat model continues to add value beyond the design phase. This also allows the security architect to work closely with the development and testing teams, which cannot be overstated. When assumptions made during the threat modeling exercise are tested, it’s important to incorporate that feedback into the existing threat model to ensure that it is aligned with reality. This effort is made easier when the security architect can see how their guidance has been applied in development.

Threat modeling during the deployment and maintenance phase

Section titled “Threat modeling during the deployment and maintenance phase”

In the deployment phase, the threat model should serve as a blueprint for implementing security measures such as monitoring systems and risk-based vulnerability management. Rather than applying a one-size-fits-all approach, security teams can use a threat model to prioritize monitoring and remediation efforts on high-risk or “hot spot” areas identified earlier in the threat modeling process.

In the deployed environment, the organization should utilize monitoring techniques such as sensors, log aggregators, and security tools that align with specific threats identified in the threat model, supported by automated systems for continuous threat detection and response. For instance, if the threat model highlights API endpoints as critical assets due to the data they expose or transactions they allow, the security team might deploy specialized API security monitoring solutions and implement more frequent scanning intervals for these components. Or, if the model identifies sensitive data storage as a key concern, monitoring efforts focus heavily on database access and potential exfiltration indicators.

One of the most critical components of the maintenance activities in an organization is the vulnerability management strategy. When guided by the threat model, this activity becomes more refined and efficient. Instead of treating all vulnerabilities with equal urgency, teams can correlate identified vulnerabilities with threat scenarios mapped during the modeling phase. This allows for intelligent prioritization based on a comprehensive threat model.

For example, a buffer overflow vulnerability in a public-facing component can be reviewed against the completed threat model, where the impacted workflow was deemed as high-value with access to critical data. In this case, the vulnerability should be escalated as a priority issue that requires an immediate fix.

There is an entire discipline in security around vulnerability management, which goes way beyond using the threat model to identify the attack surface. You need to know what the actual risk is (impact and likelihood) of the potential threat.

If a change in the design occurs during development due to limitations, assumptions, or even a change in product direction, the architecture documentation is (or should be) updated to reflect the new reality. Why would threat modeling be any different? While we’ll touch on more automated and codified methods of updating the threat model in future chapters, the importance of keeping an evergreen threat model can’t be overstated.

This living threat model serves as a map during certain phases, such as the operational phase, where production monitoring data plays a critical role in either validating or challenging the assumptions made in the threat model. Incident response findings often uncover new attack vectors that must be documented and addressed. As performance optimizations are made, they can introduce new security considerations that need to be factored into the ongoing threat modeling process. Decisions around scaling the system can shift the threat landscape, requiring a reevaluation of potential risks. Finally, any changes to the infrastructure must undergo a thorough security review to ensure that they don’t inadvertently introduce new vulnerabilities or negate current security controls. Integrating these insights ensures that the threat model remains a living document, adapting to the evolving environment.

As already mentioned, during a security incident, the threat model should provide insight into the high-risk and critical workflows throughout the system. However, once the dust settles on the incident, the after-action report should be fed back into the threat model to ensure that gaps in controls or assumptions that were being made by the threat model match reality.

There are multiple ways to get information that will help refine and evolve your threat model throughout the process. The integration of services such as real-time threat intelligence has fundamentally changed how we approach security architecture. Announcements of third-party vulnerabilities should prompt immediate reviews of the model to assess the impact of the vulnerability on security and architecture. Changes to APIs from external services would necessitate a reassessment of threats and potential risks. In other words, are you sending different or new data to an API that increases the overall risk to the system and organization? Most vendors that you work with will have security bulletins or feeds that can influence architecture assumptions as well. Ensure that you are signed up for these bulletins and evaluate their relevance in your process.

Supply chain security has been a huge topic in the past few years, and not just in cybersecurity. Your threat model should change as your software supply chain evolves. This can be done through a basic security evaluation while partnering with the third-party risk management team in your organization (if you have one). Lastly, changes to regulatory requirements must be reflected in the controls to ensure ongoing compliance. Many companies are facing a perturbed regulatory environment as rules around data collection and use change.

These are just a few examples of where and how to evolve your threat model, but the bottom line is that any time your system, your threat landscape, or your risk appetite changes, your threat model should also change with it.

We’ve discussed how to manage risks in an organization previously. However, managing the threats that come from a threat model doesn’t require any special process. To me, the best method for managing threats found is no different from managing defects found during development or testing, which is by opening a ticket.

Almost all organizations operate some type of tracking system that can track defects from identification to resolution. As stated, security findings should be treated no differently and should follow the same process. This helps keep a clear documentation of the security issue, as well as how and when it was resolved. Like any other defect, having this information greatly supports future efforts when a similar issue arises. Some common tracking tools are Jira, Asana, GitHub, and GitLab.

We spend a lot of time treating security like it’s special when handling findings from reports, tests, or threat models. In reality, these are defects, or gaps in the design, no different from finding a slow response time on a part of the application or excessive memory usage. If these are found during testing or in production, an end user or the internal resource who located the issue is likely to raise a question about the issue. This will likely turn into a defect ticket in the tracking system used by the development team. Why would this be any different from a cross-site scripting vulnerability found in a test?

The lines are blurry when it comes to the difference between a software defect and a security vulnerability. While all software vulnerabilities can be considered defects, not all software defects are vulnerabilities. A software defect becomes a security vulnerability when it can be exploited by a malicious actor to compromise the confidentiality, integrity, or availability of the system.

So, where does that leave us with managing threats in the SDLC? The takeaway is that, whether they are security issues or not, there needs to be a systematic approach with a well-established process for handling identified issues.

Ideally, the organization will have the tools and processes to take defects from identification to resolution in place. While the findings can come from many sources throughout the life cycle, they ultimately need to funnel into a consistent process and set of tools that ensure a satisfactory conclusion. In the case of our threat models, this means that the threats identified should be opened in the defect tracking system. This provides visibility into the threats impacting that specific application and allows for the cataloging of information for future use.

Take, for example, the finding I described previously related to a threat identified in the file upload feature of an application. During the threat modeling process, a security control gap is identified in the file upload service. To track this, the security architect or development team will open a high-priority security vulnerability ticket to track the necessary architectural controls that need to be implemented. The ticket could be titled Security Control Gaps: File Upload Service Requires Additional Protections, and should be tagged with the appropriate tags to ease reporting and tracking.

In the details of the ticket itself, the documentation should outline several critical security requirements, beginning with robust input validation controls, including file size limits, MIME type allowlists, and deep content inspection for file type verification.

Ideally, the organization will already have patterns developed for secure file upload. These patterns should provide a clear picture of how the feature should be implemented in the architecture and include the different security controls required. If this is the case, the person opening the ticket in the tracking system should include internal links to the secure patterns

The ticket details should specify secure file handling measures, such as emphasizing the generation of random file IDs, implementation of secure file permissions, protection against path traversal attacks, and additional controls. But including this information goes beyond just the purpose of capturing technical details. The tracking process involves regular status updates during team meetings, with the development team incorporating these requirements into their planning.

The ticket remains open, pending implementation, requiring both QA verification and final security architect sign-off to ensure that all controls are properly implemented and tested. This type of approach ensures that security requirements are properly tracked, implemented, and verified before the vulnerability can be considered remediated.

The reason this is important is that having a separate process for security issues, whether they come from scans, penetration testing, or threat modeling, is a sure way to be overlooked or deprioritized. Security must integrate with development where it already operates, which means using the same processes and tools.

Let’s put these concepts into practice with an example threat model of a software application.

Here, we’ll take an example of an application that is called PicShare. It is a fictional cloud-based photo-sharing social media platform designed to mimic the core functionality of apps such as Instagram or Flickr. Users can register, create profiles, upload images, tag friends, comment on posts, and share content publicly or privately. The app supports image metadata, hashtags, and location tagging, and integrates with cloud storage services such as Amazon S3 or Firebase for scalable media hosting.

PicShare is built with a modern tech stack using a Django backend, a React frontend, and RESTful APIs for mobile and web clients. It uses OAuth 2.0 for authentication and supports third-party login via Google or Facebook. The app also includes basic moderation tools, user blocking, and content reporting features.

In PicShare, users interact by uploading photos from their devices, adding captions, and tagging other users. The platform allows browsing through feeds, liking and commenting on posts, and following other users to curate personalized content. Advanced users can create albums, apply filters, and share content externally via generated links.

Drawing on what we’ve learned in previous chapters, we can begin to build the security architecture diagram as follows:

Figure 4.3: Beginning of the security architecture diagram depicting the main components and actors

Figure 4.3: Beginning of the security architecture diagram depicting the main components and actors

Based on this diagram and our understanding of the use cases, we can start to identify the threat scenarios and threat agents. In our case, code has not been written on this yet, and we have an opportunity to build our security controls as early as possible. We can start by working with the product team to understand the user stories and requirements that will bring PicShare functionality to users. Here are the four requirements that we start with:

  • PicShare must allow users to sign in using third-party providers such as Google and Facebook through OAuth 2.0, ensuring secure and streamlined access
  • Users must be able to upload photos from their devices, and the system must extract and store metadata such as location, device type, and timestamp
  • Users must be able to share photos publicly or privately, with options to generate external sharing links and control visibility settings
  • The platform must provide users with the ability to report inappropriate content, block other users, and allow moderators to review flagged posts

These requirements and our diagram are our starting point for our threat modeling exercise. We should be able to take them and begin to discover what the potential threats are by starting with asking what can go wrong.

In our first threat scenario, we can consider unauthorized access to private photos where an attacker bypasses access controls and views or downloads private photos shared only with specific users:

  • Threat actor (TA01): Malicious actor
  • Threat scenario (TS01): Using insecure direct object references (IDOR)

In the next scenario, a user uploads a file disguised as an image that contains malware or malicious scripts, anticipating that it will be executed by other users or by PicShare’s internal systems. The threat actors may be seeking to exploit weak validation for fun or minor disruption:

  • Threat actor (TA02): Script kiddie or opportunistic hacker
  • Threat scenario (TS02): Uploading .exe, .js, or .php files with spoofed MIME types or using image metadata (EXIF) to inject malicious payloads

In the next scenario, we can consider an account takeover via OAuth token theft. In this case, an attacker steals a user’s OAuth token and gains full access to their account:

  • Threat actor (TA03): Cybercriminal motivated by identity theft, impersonation, or monetization
  • Threat scenario (TS03): Phishing attacks targeting login flows or by storing tokens insecurely in local storage or exposing them in URLs

In the last scenario, we’ll consider automated spam and fake accounts that flood the platform with fake profiles, spam posts, and malicious links:

  • Threat actor (TA04): Botnet operators or spammers who are looking for advertising, phishing, or platform disruption
  • Threat scenario (TS04): Lack of CAPTCHA or rate limiting on registration

Now that we have the potential threat scenarios defined, we can update our diagram to include the scenarios and actors so that we can present it to our development team before they begin writing code. To keep the diagram clean and easy to view, we’ll use the nomenclature of TAXX and TSXX to designate the threat actors and threat scenarios, respectively.

Figure 4.4: PicShare security architecture diagram with included threat scenarios and threat agents

Figure 4.4: PicShare security architecture diagram with included threat scenarios and threat agents

With the completed diagram and threat scenarios identified, the threat modeling team can go back to the stakeholders, such as the product owners and development team, to determine the practicality of the found threats and begin to develop the controls that will remediate the found threats. After a working session with the stakeholders, all four scenarios are found to be viable, and the following remediation plan for each of the threats is devised:

  • Control (C01): Addressing the potential IDOR threat, the team determines that they need to implement strict access control checks on every photo request and use signed, time-limited URLs for cloud storage access
  • Control (C02): To address the potential upload of invalid or malicious types, the team determines that they need to code in validation of file types and MIME headers on the server side, as well as implement a scan after files are uploaded to look for malware and restrict uploads to safe image formats such as .jpg and .png
  • Control (C03): To address the potential for tokens to be stolen or misused, the team determines that they need to store tokens securely (e.g., HTTP-only cookies), use HTTPS for all communications, and implement token expiration and refresh mechanisms
  • Control (C04): To combat fake accounts being created and used, the team determines that it should include CAPTCHA for registration and posting endpoints, enforce rate limiting, and use behavioral analysis to detect bot-like activity

Our security architecture diagram should look something like this:

Figure 4.5: PicShare security architecture diagram with included security controls

Figure 4.5: PicShare security architecture diagram with included security controls

These controls should then be developed into requirements that can be tracked and developed throughout the life cycle, as any functional requirement would be. Here are some example requirements that are agreed upon by the stakeholders:

  • All photo access requests must validate the requesting user’s authorization against the photo’s visibility settings
  • Log and monitor all access to private media for audit and anomaly detection
  • Accept only certain image file types (e.g., .jpg, .png, and .gif) and reject all others
  • Validate MIME type and file extension on the server side before processing uploads
  • Integrate antivirus or malware scanning for all uploaded files
  • Store access tokens in secure, HTTP-only cookies rather than local storage
  • Implement token expiration and refresh mechanisms with short-lived access tokens
  • Require CAPTCHA and rate limiting during account registration and posting

With these requirements, the development team should be on its way to creating a more secure application. Additionally, the controls should be visible in the final architecture artifacts developed by the development team and available for reference in the future.

The New York City Cyber Command’s (NYC3’s) adoption of threat modeling represents a shift in municipal cybersecurity practices. Prior to implementing formalized threat modeling, NYC3 operated primarily through vendor technologies and industry guidelines, lacking a holistic approach to identifying and addressing digital threats. This reactive stance left potential vulnerabilities in the city’s vast digital infrastructure, prompting the organization to seek a more comprehensive security strategy.

The implementation of threat modeling brought about remarkable improvements in NYC3’s security posture. Within the first evaluation period, the organization successfully thwarted 541 unique intrusion attempts, demonstrating the effectiveness of its enhanced threat detection capabilities. Additionally, the new approach prevented the compromise of five privileged user accounts. Left unattended, these accounts could have led to catastrophic security breaches given the elevated access rights they possessed. The threat modeling process also identified three public-facing server vulnerabilities that were soon remediated, showing the proactive benefits of systematic threat modeling.

One byproduct of the threat modeling adoption was its impact on organizational culture and staff capability. The implementation saw an exceptional adoption rate, with 20 out of 25 team members independently incorporating threat modeling into their daily operations within just 30 days of training. This organic integration speaks to both the practical utility of the threat modeling and its ability to enhance confidence in handling cybersecurity challenges. Through collaborative efforts with city, state, and federal entities, NYC3 has established itself as a national model for municipal cyber defense, showcasing how systematic threat modeling can transform an organization’s security posture from reactive to proactive.

The success of NYC3’s threat modeling initiative highlights how effective defense requires more than just technological solutions. By combining systematic threat assessment with enhanced staff capabilities and inter-agency collaboration, NYC3 has created a security framework that protects New York City’s digital assets while setting a standard for other municipalities to follow.

This chapter examined the role of threat modeling in the SDLC, emphasizing its importance as a proactive security practice. It began by establishing the foundational value of threat modeling in software security, highlighting how early integration into the development process can significantly reduce vulnerabilities and improve system resilience.

We then covered how threat modeling can be applied across different stages of the SDLC, including development, testing, deployment, and maintenance. Each phase presents unique opportunities and challenges for identifying and mitigating threats, and the chapter stressed the importance of evolving threat models as systems change over time. This approach ensures that security remains aligned with the software’s functionality and risk profile.

To reinforce these concepts, the chapter introduced a detailed example using PicShare, a fictional photo-sharing application. This example demonstrated how to identify assets, define threat actors, and construct realistic threat scenarios using the “What can go wrong?” method. It also provided actionable security controls and development requirements, illustrating how threat modeling can directly inform secure design and implementation.

Finally, the chapter emphasized the need for a systematic approach to managing threats throughout the SDLC. By integrating threat modeling into routine development activities and aligning it with architectural decisions, teams can build more secure software while maintaining agility and innovation.

Next, we’ll look at how we model threats in the cloud and infrastructure where our software runs.

Get This Book’s PDF Version and Exclusive Extras