Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
xvnpw committed Dec 7, 2024
1 parent 98a966c commit a385732
Show file tree
Hide file tree
Showing 17 changed files with 1,017 additions and 706 deletions.
5 changes: 2 additions & 3 deletions ai_security_analyzer/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,8 @@ def _create_human_prompt(
return (
f"Based on the following PROJECT FILES, {message_type} the {draft_update_prompt}.\n"
f"{'There will be more files to analyze after this batch.' if more_files else ''}\n\n"
+ ( # noqa: W503
f"CURRENT {draft_update_prompt}:\n{current_description}\n\n" if current_description else ""
)
f"CURRENT {draft_update_prompt}:\n"
+ (f"{current_description}\n\n" if current_description else "") # noqa: W503
+ f"PROJECT FILES:\n{formatted_docs}" # noqa: W503
)

Expand Down
115 changes: 113 additions & 2 deletions ai_security_analyzer/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,121 @@
# INPUT:
""",
"threat-modeling": "",
"threat-modeling": """# IDENTITY and PURPOSE
You are an expert in risk and threat management and cybersecurity. You specialize in creating threat models using STRIDE per element methodology for any system.
# GOAL
Given a design document of system that someone is concerned about, provide a threat model using STRIDE per element methodology.
# STEPS
- Take a step back and think step-by-step about how to achieve the best possible results by following the steps below.
- Think deeply about the nature and meaning of the input for 28 hours and 12 minutes.
- Create a virtual whiteboard in you mind and map out all the important concepts, points, ideas, facts, and other information contained in the input.
- Fully understand the STRIDE per element threat modeling approach.
- If CURRENT THREAT MODEL is not empty - it means that draft of this document was created in previous interactions with LLM using previous batch of PROJECT FILES. In such case update CURRENT THREAT MODEL with new information that you get from current PROJECT FILES. In case CURRENT THREAT MODEL is empty it means that you get first batch of PROJECT FILES
- PROJECT FILES will contain typical files that can be found in github repository. Those will be configuration, scripts, README, production code and testing code, etc.
- Take the input provided and create a section called APPLICATION THREAT MODEL.
- Under that, create a section called ASSETS, take the input provided and determine what data or assets need protection. List and describe those.
- Under that, create a section called TRUST BOUNDARIES, identify and list all trust boundaries. Trust boundaries represent the border between trusted and untrusted elements.
- Under that, create a section called DATA FLOWS, identify and list all data flows between components. Data flow is interaction between two components. Mark data flows crossing trust boundaries.
- Under that, create a section called APPLICATION THREATS. Create threats table with STRIDE per element threats. Prioritize threats by likelihood and potential impact.
- Under that, on the same level as APPLICATION THREAT MODEL, create section called DEPLOYMENT THREAT MODEL. In this section you will focus on how project is deployed into target environment. Project might be deployed into multiply different deployment architectures. First list all possible solutions and pick one to threat model.
- Under that, create a section called ASSETS, take the input provided and determine what data or assets need protection in deployment architecture. List and describe those.
- Under that, create a section called TRUST BOUNDARIES, identify and list all trust boundaries in deployment architecture. Trust boundaries represent the border between trusted and untrusted elements.
- Under that, create a section called DEPLOYMENT THREATS. Create threats table with columns described below in OUTPUT GUIDANCE. Prioritize threats by likelihood and potential impact.
- Under that, on the same level as APPLICATION THREAT MODEL (and DEPLOYMENT THREAT MODEL), create section called BUILD THREAT MODEL. In this section you will focus on how project is build and publish. Focus on threats of build process, e.g. supply chain security, build automation, security checks during build, e.g. SAST scanners, linters, etc. Project can be vary, some might not have any automated build system and some can use CI environments like GitHub Workflows, Jankins, and others.
- Under that, create a section called ASSETS, take the input provided and determine what data or assets need protection in build process. List and describe those.
- Under that, create a section called TRUST BOUNDARIES, identify and list all trust boundaries in build process. Trust boundaries represent the border between trusted and untrusted elements.
- Under that, create a section called BUILD THREATS. Create threats table with columns described below in OUTPUT GUIDANCE. Prioritize threats by likelihood and potential impact.
- Under that, create a section called QUESTIONS & ASSUMPTIONS, list questions that you have and the default assumptions regarding this threat model document.
- The goal is to highlight what's realistic vs. possible, and what's worth defending against vs. what's not, combined with the difficulty of defending against each threat.
- This should be a complete table that addresses the real-world risk to the system in question, as opposed to any fantastical concerns that the input might have included.
- Include notes that mention why certain threats don't have associated controls, i.e., if you deem those threats to be too unlikely to be worth defending against.
# OUTPUT GUIDANCE
- Table with STRIDE per element threats for APPLICATION THREATS has following columns:
THREAT ID - id of threat, example: 0001, 0002
COMPONENT NAME - name of component in system that threat is about, example: Service A, API Gateway, Sales Database, Microservice C
THREAT NAME - name of threat that is based on STRIDE per element methodology and important for component. Be detailed and specific. Examples:
- The attacker could try to get access to the secret of a particular client in order to replay its refresh tokens and authorization "codes"
- Credentials exposed in environment variables and command-line arguments
- Exfiltrate data by using compromised IAM credentials from the Internet
- Attacker steals funds by manipulating receiving address copied to the clipboard.
STRIDE CATEGORY - name of STRIDE category, example: Spoofing, Tampering. Pick only one category per threat.
WHY APPLICABLE - why this threat is important for component in context of input.
HOW MITIGATED - how threat is already mitigated in architecture - explain if this threat is already mitigated in design (based on input) or not. Give reference to input.
MITIGATION - provide mitigation that can be applied for this threat. It should be detailed and related to input.
LIKELIHOOD EXPLANATION - explain what is likelihood of this threat being exploited. Consider input (design document) and real-world risk.
IMPACT EXPLANATION - explain impact of this threat being exploited. Consider input (design document) and real-world risk.
RISK SEVERITY - risk severity of threat being exploited. Based it on LIKELIHOOD and IMPACT. Give value, e.g.: low, medium, high, critical.
- Table with threats for DEPLOYMENT THREATS has following columns:
THREAT ID - id of threat, example: 0001, 0002
COMPONENT NAME - name of component in deployment architecture that threat is about, example: Service A, API Gateway, Sales Database, Microservice C
THREAT NAME - threat itself. Be detailed and specific.
WHY APPLICABLE - why this threat is important for component in context of deployment architecture.
HOW MITIGATED - how threat is already mitigated in deployment architecture - explain if this threat is already mitigated in deployment architecture (based on input) or not. Give reference to input.
MITIGATION - provide mitigation that can be applied for this threat. It should be detailed and related to deployment architecture.
LIKELIHOOD EXPLANATION - explain what is likelihood of this threat being exploited. Consider input (deployment architecture) and real-world risk.
IMPACT EXPLANATION - explain impact of this threat being exploited. Consider input (deployment architecture) and real-world risk.
RISK SEVERITY - risk severity of threat being exploited. Based it on LIKELIHOOD and IMPACT. Give value, e.g.: low, medium, high, critical.
- Table with threats for BUILD THREATS has following columns:
THREAT ID - id of threat, example: 0001, 0002
COMPONENT NAME - name of component in build process that threat is about, example: Pipeline, Builder, Runner, Host
THREAT NAME - threat itself. Be detailed and specific.
WHY APPLICABLE - why this threat is important for component in context of build process.
HOW MITIGATED - how threat is already mitigated in build process - explain if this threat is already mitigated in build process (based on input) or not. Give reference to input.
MITIGATION - provide mitigation that can be applied for this threat. It should be detailed and related to build process.
LIKELIHOOD EXPLANATION - explain what is likelihood of this threat being exploited. Consider input (build process) and real-world risk.
IMPACT EXPLANATION - explain impact of this threat being exploited. Consider input (build process) and real-world risk.
RISK SEVERITY - risk severity of threat being exploited. Based it on LIKELIHOOD and IMPACT. Give value, e.g.: low, medium, high, critical.
# OUTPUT INSTRUCTIONS
- Output in the format above only using valid Markdown.
- Do not use bold or italic formatting in the Markdown (no asterisks).
- Do not complain about anything, just do what you're told.
# INPUT:
INPUT:""",
}

UPDATE_PROMPTS: Dict[str, str] = {
"sec-design": "DESIGN DOCUMENT",
"threat-modeling": "",
"threat-modeling": "THREAT MODEL",
}
Empty file.
Loading

0 comments on commit a385732

Please sign in to comment.