[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EK30QM1XFWRHR0MV2CG0CJ":3,"skill-same:01M6EK30QM1XFWRHR0MV2CG0CJ":93},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":38,"linkOnly":39,"markdownContent":40,"markdownBody":41,"frontMatter":42,"refName":64,"commitSha":65,"skillDirectory":66,"forksCount":67,"repositoryHtmlUrl":68,"repositoryHomepageUrl":69,"ownerHtmlUrl":70,"ownerBlogUrl":6,"ownerDescription":71,"updatedAt":72,"install":73,"resources":86},"01M6EK30QM1XFWRHR0MV2CG0CJ","pytm",null,"Python-based threat modeling using pytm library for programmatic STRIDE analysis, data flow diagram generation, and automated security threat identification. Use when: (1) Creating threat models programmatically using Python code, (2) Generating data flow diagrams (DFDs) with automatic STRIDE threat identification, (3) Integrating threat modeling into CI\u002FCD pipelines and shift-left security practices, (4) Analyzing system architecture for security threats across trust boundaries, (5) Producing threat reports with STRIDE categories and mitigation recommendations, (6) Maintaining threat models as code for version control and automation.","ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fagentsecops\u002Fpytm\u002FSKILL.md",[],[5,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"risk-analysis","identification","threatmodel","chart","as","trust","version","use","system","python","ATT&CK","threat-modeling","NIST","ci","library","architecture","threat modeling","security","github","2026-11-10 10:12:30",false,"---\nname: pytm\ndescription: >\n  Python-based threat modeling using pytm library for programmatic STRIDE analysis,\n  data flow diagram generation, and automated security threat identification. Use when:\n  (1) Creating threat models programmatically using Python code, (2) Generating data flow\n  diagrams (DFDs) with automatic STRIDE threat identification, (3) Integrating threat\n  modeling into CI\u002FCD pipelines and shift-left security practices, (4) Analyzing system\n  architecture for security threats across trust boundaries, (5) Producing threat reports\n  with STRIDE categories and mitigation recommendations, (6) Maintaining threat models\n  as code for version control and automation.\nversion: 0.1.0\nmaintainer: SirAppSec\ncategory: threatmodel\ntags: [threat-modeling, stride, dfd, security-architecture, pytm, appsec, risk-analysis]\nframeworks: [STRIDE, OWASP, MITRE-ATT&CK, NIST]\ndependencies:\n  python: \">=3.7\"\n  packages: [pytm, graphviz]\nreferences:\n  - https:\u002F\u002Fgithub.com\u002Fizar\u002Fpytm\n  - https:\u002F\u002Fowasp.org\u002Fwww-community\u002FThreat_Modeling\n  - https:\u002F\u002Fwww.microsoft.com\u002Fen-us\u002Fsecurity\u002Fblog\u002F2007\u002F09\u002F11\u002Fstride-chart\u002F\n  - https:\u002F\u002Fattack.mitre.org\u002F\n---\n\n# Threat Modeling with pytm\n\n## Overview\n\npytm is a Python library for programmatic threat modeling based on the STRIDE methodology. It enables\nsecurity engineers to define system architecture as code, automatically generate data flow diagrams (DFDs),\nidentify security threats across trust boundaries, and produce comprehensive threat reports. This\napproach integrates threat modeling into CI\u002FCD pipelines, enabling shift-left security and continuous\nthreat analysis.\n\n## Quick Start\n\nCreate a basic threat model:\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\nfrom pytm import TM, Server, Dataflow, Boundary, Actor\n\n# Initialize threat model\ntm = TM(\"Web Application Threat Model\")\ntm.description = \"E-commerce web application\"\n\n# Define trust boundaries\ninternet = Boundary(\"Internet\")\ndmz = Boundary(\"DMZ\")\ninternal = Boundary(\"Internal Network\")\n\n# Define actors and components\nuser = Actor(\"Customer\")\nuser.inBoundary = internet\n\nweb = Server(\"Web Server\")\nweb.inBoundary = dmz\n\ndb = Server(\"Database\")\ndb.inBoundary = internal\n\n# Define data flows\nuser_to_web = Dataflow(user, web, \"HTTPS Request\")\nuser_to_web.protocol = \"HTTPS\"\nuser_to_web.data = \"credentials, payment info\"\nuser_to_web.isEncrypted = True\n\nweb_to_db = Dataflow(web, db, \"Database Query\")\nweb_to_db.protocol = \"SQL\u002FTLS\"\nweb_to_db.data = \"user data, transactions\"\n\n# Generate threat report and diagram\ntm.process()\n```\n\nInstall pytm:\n```bash\npip install pytm\n# Also requires graphviz for diagram generation\nbrew install graphviz  # macOS\n# or: apt-get install graphviz  # Linux\n```\n\n## Core Workflows\n\n### Workflow 1: Create New Threat Model\n\nProgress:\n[ ] 1. Define system scope and trust boundaries\n[ ] 2. Identify all actors (users, administrators, external systems)\n[ ] 3. Map system components (servers, databases, APIs, services)\n[ ] 4. Define data flows between components with security attributes\n[ ] 5. Run `tm.process()` to generate threats and DFD\n[ ] 6. Review STRIDE threats and add mitigations\n[ ] 7. Generate threat report with `scripts\u002Fgenerate_report.py`\n\nWork through each step systematically. Check off completed items.\n\n### Workflow 2: STRIDE Threat Analysis\n\npytm automatically identifies threats based on STRIDE categories:\n\n- **Spoofing**: Identity impersonation attacks\n- **Tampering**: Unauthorized modification of data\n- **Repudiation**: Denial of actions without traceability\n- **Information Disclosure**: Unauthorized access to sensitive data\n- **Denial of Service**: Availability attacks\n- **Elevation of Privilege**: Unauthorized access escalation\n\nFor each identified threat:\n1. Review threat description and affected component\n2. Assess likelihood and impact (use `references\u002Frisk_matrix.md`)\n3. Determine if existing controls mitigate the threat\n4. Add mitigation using `threat.mitigation = \"description\"`\n5. Document residual risk and acceptance criteria\n\n### Workflow 3: Architecture as Code\n\nDefine system architecture programmatically:\n\n```python\nfrom pytm import TM, Server, Datastore, Dataflow, Boundary, Actor, Lambda\n\ntm = TM(\"Microservices Architecture\")\n\n# Cloud boundaries\ninternet = Boundary(\"Internet\")\ncloud_vpc = Boundary(\"Cloud VPC\")\n\n# API Gateway\napi_gateway = Server(\"API Gateway\")\napi_gateway.inBoundary = cloud_vpc\napi_gateway.implementsAuthentication = True\napi_gateway.implementsAuthorization = True\n\n# Microservices\nauth_service = Lambda(\"Auth Service\")\nauth_service.inBoundary = cloud_vpc\n\norder_service = Lambda(\"Order Service\")\norder_service.inBoundary = cloud_vpc\n\n# Data stores\nuser_db = Datastore(\"User Database\")\nuser_db.inBoundary = cloud_vpc\nuser_db.isEncryptedAtRest = True\n\n# Data flows with security properties\nclient_to_api = Dataflow(Actor(\"Client\"), api_gateway, \"API Request\")\nclient_to_api.protocol = \"HTTPS\"\nclient_to_api.isEncrypted = True\nclient_to_api.data = \"user credentials, orders\"\n\napi_to_auth = Dataflow(api_gateway, auth_service, \"Auth Check\")\napi_to_auth.protocol = \"gRPC\u002FTLS\"\n\nauth_to_db = Dataflow(auth_service, user_db, \"User Lookup\")\nauth_to_db.protocol = \"TLS\"\n\ntm.process()\n```\n\n### Workflow 4: CI\u002FCD Integration\n\nAutomate threat modeling in continuous integration:\n\n```yaml\n# .github\u002Fworkflows\u002Fthreat-model.yml\nname: Threat Model Analysis\non: [push, pull_request]\n\njobs:\n  threat-model:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v3\n\n      - name: Set up Python\n        uses: actions\u002Fsetup-python@v4\n        with:\n          python-version: '3.10'\n\n      - name: Install dependencies\n        run: |\n          pip install pytm\n          sudo apt-get install -y graphviz\n\n      - name: Generate threat model\n        run: python threat_model.py\n\n      - name: Upload DFD diagram\n        uses: actions\u002Fupload-artifact@v3\n        with:\n          name: threat-model-dfd\n          path: '*.png'\n\n      - name: Check for unmitigated threats\n        run: python scripts\u002Fcheck_mitigations.py threat_model.py\n```\n\n### Workflow 5: Threat Report Generation\n\nGenerate comprehensive threat documentation:\n\n```bash\n# Run threat model with report generation\npython threat_model.py\n\n# Generate markdown report\n.\u002Fscripts\u002Fgenerate_report.py --model threat_model.py --output threat_report.md\n\n# Generate JSON for tool integration\n.\u002Fscripts\u002Fgenerate_report.py --model threat_model.py --format json --output threats.json\n```\n\nReport includes:\n- System architecture overview\n- Trust boundary analysis\n- Complete STRIDE threat enumeration\n- Existing and recommended mitigations\n- Risk prioritization matrix\n\n## Security Considerations\n\n### Sensitive Data Handling\n\n- **Threat models as code**: Store in version control but review for sensitive architecture details\n- **Credentials and secrets**: Never hardcode in threat models - use placeholders\n- **Data classification**: Clearly label data flows with sensitivity levels (PII, PCI, PHI)\n- **Report distribution**: Control access to threat reports revealing security architecture\n\n### Access Control\n\n- **Threat model repository**: Restrict write access to security team and architects\n- **CI\u002FCD integration**: Protect threat modeling pipeline from tampering\n- **Diagram artifacts**: Control distribution of DFDs showing system architecture\n- **Mitigation tracking**: Integrate with secure issue tracking systems\n\n### Audit Logging\n\nLog the following for security governance:\n- Threat model creation and modification history\n- Identified threats and severity assessments\n- Mitigation implementation and validation\n- Risk acceptance decisions with approval\n- Threat model review and update cycles\n\n### Compliance Requirements\n\n- **NIST 800-30**: Risk assessment methodology alignment\n- **ISO 27001**: A.14.1.2 - Securing application services on public networks\n- **OWASP SAMM**: Threat Assessment practice maturity\n- **PCI-DSS 6.3.1**: Security threat identification in development\n- **SOC2 CC9.1**: Risk assessment process for system changes\n\n## Bundled Resources\n\n### Scripts (`scripts\u002F`)\n\n- `generate_report.py` - Generate markdown\u002FJSON threat reports with STRIDE categorization\n- `check_mitigations.py` - Validate all identified threats have documented mitigations\n- `threat_classifier.py` - Classify threats by severity using DREAD or custom risk matrix\n- `template_generator.py` - Generate threat model templates for common architectures\n\n### References (`references\u002F`)\n\n- `stride_methodology.md` - Complete STRIDE methodology guide with threat examples\n- `risk_matrix.md` - Risk assessment framework with likelihood and impact scoring\n- `component_library.md` - Reusable pytm components for common patterns (APIs, databases, cloud services)\n- `mitigation_strategies.md` - Common mitigation patterns mapped to STRIDE categories and OWASP controls\n\n### Assets (`assets\u002F`)\n\n- `templates\u002Fweb_application.py` - Web application threat model template\n- `templates\u002Fmicroservices.py` - Microservices architecture template\n- `templates\u002Fmobile_app.py` - Mobile application threat model template\n- `templates\u002Fiot_system.py` - IoT system threat model template\n- `dfd_styles.json` - Custom graphviz styling for professional diagrams\n\n## Common Patterns\n\n### Pattern 1: Web Application Three-Tier Architecture\n\n```python\nfrom pytm import TM, Server, Datastore, Dataflow, Boundary, Actor\n\ntm = TM(\"Three-Tier Web Application\")\n\n# Boundaries\ninternet = Boundary(\"Internet\")\ndmz = Boundary(\"DMZ\")\ninternal = Boundary(\"Internal Network\")\n\n# Components\nuser = Actor(\"End User\")\nuser.inBoundary = internet\n\nlb = Server(\"Load Balancer\")\nlb.inBoundary = dmz\nlb.implementsNonce = True\n\nweb = Server(\"Web Server\")\nweb.inBoundary = dmz\nweb.implementsAuthentication = True\nweb.implementsAuthenticationOut = False\n\napp = Server(\"Application Server\")\napp.inBoundary = internal\napp.implementsAuthorization = True\n\ndb = Datastore(\"Database\")\ndb.inBoundary = internal\ndb.isSQL = True\ndb.isEncryptedAtRest = True\n\n# Data flows\nDataflow(user, lb, \"HTTPS\").isEncrypted = True\nDataflow(lb, web, \"HTTPS\").isEncrypted = True\nDataflow(web, app, \"HTTP\").data = \"session token, requests\"\nDataflow(app, db, \"SQL\u002FTLS\").data = \"user data, transactions\"\n\ntm.process()\n```\n\n### Pattern 2: Cloud Native Microservices\n\n```python\nfrom pytm import TM, Lambda, Datastore, Dataflow, Boundary, Actor\n\ntm = TM(\"Cloud Microservices\")\n\ncloud = Boundary(\"Cloud Provider VPC\")\nuser = Actor(\"Mobile App\")\n\n# Serverless functions\napi_gateway = Lambda(\"API Gateway\")\napi_gateway.inBoundary = cloud\napi_gateway.implementsAPI = True\n\nauth_fn = Lambda(\"Auth Function\")\nauth_fn.inBoundary = cloud\n\n# Managed services\ncache = Datastore(\"Redis Cache\")\ncache.inBoundary = cloud\ncache.isEncrypted = True\n\ndb = Datastore(\"DynamoDB\")\ndb.inBoundary = cloud\ndb.isEncryptedAtRest = True\n\n# Data flows\nDataflow(user, api_gateway, \"API Call\").protocol = \"HTTPS\"\nDataflow(api_gateway, auth_fn, \"Auth\").protocol = \"internal\"\nDataflow(auth_fn, cache, \"Session\").isEncrypted = True\nDataflow(api_gateway, db, \"Query\").isEncrypted = True\n\ntm.process()\n```\n\n### Pattern 3: Adding Custom Threats\n\nDefine organization-specific threats:\n\n```python\nfrom pytm import TM, Threat\n\ntm = TM(\"Custom Threat Model\")\n\n# Add custom threat to component\nweb_server = Server(\"Web Server\")\n\ncustom_threat = Threat(\n    target=web_server,\n    id=\"CUSTOM-001\",\n    description=\"API rate limiting bypass using distributed requests\",\n    condition=\"web_server.implementsRateLimiting is False\",\n    mitigation=\"Implement distributed rate limiting with Redis\",\n    references=\"OWASP API Security Top 10 - API4 Unrestricted Resource Consumption\"\n)\n\nweb_server.threats.append(custom_threat)\n```\n\n### Pattern 4: Trust Boundary Analysis\n\nFocus on cross-boundary threats:\n\n```python\n# Identify all trust boundary crossings\nfor flow in tm.dataflows:\n    if flow.source.inBoundary != flow.sink.inBoundary:\n        print(f\"Cross-boundary flow: {flow.name}\")\n        print(f\"  From: {flow.source.inBoundary.name}\")\n        print(f\"  To: {flow.sink.inBoundary.name}\")\n        print(f\"  Encrypted: {flow.isEncrypted}\")\n        print(f\"  Authentication: {flow.implementsAuthentication}\")\n```\n\nTrust boundary crossings require extra scrutiny:\n- Authentication and authorization mechanisms\n- Encryption in transit\n- Input validation and sanitization\n- Logging and monitoring\n\n## Integration Points\n\n### SDLC Integration\n\n- **Design Phase**: Create initial threat model during architecture review\n- **Development**: Reference threat model for security requirements\n- **Code Review**: Validate mitigations are implemented correctly\n- **Testing**: Generate security test cases from identified threats\n- **Deployment**: Validate security controls match threat model assumptions\n- **Operations**: Update threat model for infrastructure changes\n\n### Security Tools Ecosystem\n\n- **Issue Tracking**: Export threats as Jira\u002FGitHub issues for mitigation tracking\n- **Documentation**: Generate threat models for security documentation\n- **SIEM**: Map threats to detection rules and monitoring alerts\n- **Pentesting**: Provide threat model to pentesters for targeted assessment\n- **Code Analysis**: Link SAST\u002FDAST findings to threat model threats\n\n### Cloud and DevOps\n\n- **Infrastructure as Code**: Threat model Terraform\u002FCloudFormation templates\n- **Container Security**: Model container orchestration and service mesh\n- **API Design**: Threat model API gateway and microservices communication\n- **Secrets Management**: Model key management and secrets distribution\n\n## Troubleshooting\n\n### Issue: Missing Threats in Output\n\n**Symptoms**: Expected STRIDE threats not appearing in generated report\n\n**Solution**:\n1. Verify component properties are set correctly (e.g., `isSQL=True` for databases)\n2. Check data flow security attributes (`isEncrypted`, `protocol`)\n3. Ensure components are assigned to boundaries\n4. Review trust boundary crossings\n5. Consult `references\u002Fstride_methodology.md` for threat conditions\n\n### Issue: Diagram Generation Failure\n\n**Symptoms**: DFD not generated or graphviz errors\n\n**Solution**:\n```bash\n# Verify graphviz installation\ndot -V\n\n# Install graphviz if missing\nbrew install graphviz  # macOS\nsudo apt-get install graphviz  # Linux\n\n# Test pytm with simple model\npython -c \"from pytm import TM; tm = TM('test'); tm.process()\"\n```\n\n### Issue: Too Many False Positive Threats\n\n**Symptoms**: Identified threats don't apply to your architecture\n\n**Solution**:\n1. Set accurate component properties to suppress irrelevant threats\n2. Use threat conditions to filter: `threat.condition = \"...\"`\n3. Document why threats don't apply: `threat.mitigation = \"N\u002FA - using managed service\"`\n4. Create custom threat library with `references\u002Fcomponent_library.md`\n\n### Issue: Threat Model Maintenance Drift\n\n**Symptoms**: Threat model doesn't reflect current architecture\n\n**Solution**:\n1. Store threat models in version control alongside architecture diagrams\n2. Trigger threat model regeneration in CI on architecture changes\n3. Schedule quarterly threat model reviews\n4. Link threat model updates to architecture review board approvals\n5. Use `scripts\u002Fcheck_mitigations.py` to validate completeness\n\n## Advanced Configuration\n\n### Custom Threat Definitions\n\nCreate organization-specific threat library:\n\n```python\n# custom_threats.py\nfrom pytm import Threat\n\ndef add_custom_threats(tm):\n    \"\"\"Add organization-specific threats to threat model\"\"\"\n\n    # Cloud-specific threats\n    cloud_misconfiguration = Threat(\n        id=\"CLOUD-001\",\n        description=\"Misconfigured cloud storage bucket exposes sensitive data\",\n        condition=\"datastore.inBoundary.name == 'Cloud' and not datastore.isEncrypted\",\n        mitigation=\"Enable encryption at rest and bucket policies\"\n    )\n\n    # API-specific threats\n    api_abuse = Threat(\n        id=\"API-001\",\n        description=\"API endpoint abuse through lack of rate limiting\",\n        condition=\"server.implementsAPI and not server.implementsRateLimiting\",\n        mitigation=\"Implement rate limiting and API key rotation\"\n    )\n\n    return [cloud_misconfiguration, api_abuse]\n```\n\n### Risk Scoring Integration\n\nAdd DREAD scoring to threats:\n\n```python\nclass ScoredThreat(Threat):\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.damage = 0        # 0-10\n        self.reproducibility = 0\n        self.exploitability = 0\n        self.affected_users = 0\n        self.discoverability = 0\n\n    def dread_score(self):\n        return (self.damage + self.reproducibility + self.exploitability +\n                self.affected_users + self.discoverability) \u002F 5\n\n# Usage\nthreat = ScoredThreat(\n    target=component,\n    description=\"SQL Injection\",\n    damage=9,\n    reproducibility=8,\n    exploitability=7,\n    affected_users=10,\n    discoverability=6\n)\nprint(f\"DREAD Score: {threat.dread_score()}\u002F10\")\n```\n\n### Diagram Customization\n\nCustomize DFD output with graphviz attributes:\n\n```python\n# Set custom colors for trust boundaries\ninternet.color = \"red\"\ndmz.color = \"orange\"\ninternal.color = \"green\"\n\n# Customize diagram output\ntm.graph_options = {\n    \"rankdir\": \"LR\",  # Left to right layout\n    \"bgcolor\": \"white\",\n    \"fontname\": \"Arial\",\n    \"fontsize\": \"12\"\n}\n```\n\n## References\n\n- [pytm GitHub Repository](https:\u002F\u002Fgithub.com\u002Fizar\u002Fpytm)\n- [OWASP Threat Modeling](https:\u002F\u002Fowasp.org\u002Fwww-community\u002FThreat_Modeling)\n- [Microsoft STRIDE Methodology](https:\u002F\u002Fwww.microsoft.com\u002Fen-us\u002Fsecurity\u002Fblog\u002F2007\u002F09\u002F11\u002Fstride-chart\u002F)\n- [MITRE ATT&CK Framework](https:\u002F\u002Fattack.mitre.org\u002F)\n- [Threat Modeling Manifesto](https:\u002F\u002Fwww.threatmodelingmanifesto.org\u002F)\n- [NIST 800-30: Risk Assessment](https:\u002F\u002Fcsrc.nist.gov\u002Fpublications\u002Fdetail\u002Fsp\u002F800-30\u002Frev-1\u002Ffinal)\n","# Threat Modeling with pytm\n\n## Overview\n\npytm is a Python library for programmatic threat modeling based on the STRIDE methodology. It enables\nsecurity engineers to define system architecture as code, automatically generate data flow diagrams (DFDs),\nidentify security threats across trust boundaries, and produce comprehensive threat reports. This\napproach integrates threat modeling into CI\u002FCD pipelines, enabling shift-left security and continuous\nthreat analysis.\n\n## Quick Start\n\nCreate a basic threat model:\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\nfrom pytm import TM, Server, Dataflow, Boundary, Actor\n\n# Initialize threat model\ntm = TM(\"Web Application Threat Model\")\ntm.description = \"E-commerce web application\"\n\n# Define trust boundaries\ninternet = Boundary(\"Internet\")\ndmz = Boundary(\"DMZ\")\ninternal = Boundary(\"Internal Network\")\n\n# Define actors and components\nuser = Actor(\"Customer\")\nuser.inBoundary = internet\n\nweb = Server(\"Web Server\")\nweb.inBoundary = dmz\n\ndb = Server(\"Database\")\ndb.inBoundary = internal\n\n# Define data flows\nuser_to_web = Dataflow(user, web, \"HTTPS Request\")\nuser_to_web.protocol = \"HTTPS\"\nuser_to_web.data = \"credentials, payment info\"\nuser_to_web.isEncrypted = True\n\nweb_to_db = Dataflow(web, db, \"Database Query\")\nweb_to_db.protocol = \"SQL\u002FTLS\"\nweb_to_db.data = \"user data, transactions\"\n\n# Generate threat report and diagram\ntm.process()\n```\n\nInstall pytm:\n```bash\npip install pytm\n# Also requires graphviz for diagram generation\nbrew install graphviz  # macOS\n# or: apt-get install graphviz  # Linux\n```\n\n## Core Workflows\n\n### Workflow 1: Create New Threat Model\n\nProgress:\n[ ] 1. Define system scope and trust boundaries\n[ ] 2. Identify all actors (users, administrators, external systems)\n[ ] 3. Map system components (servers, databases, APIs, services)\n[ ] 4. Define data flows between components with security attributes\n[ ] 5. Run `tm.process()` to generate threats and DFD\n[ ] 6. Review STRIDE threats and add mitigations\n[ ] 7. Generate threat report with `scripts\u002Fgenerate_report.py`\n\nWork through each step systematically. Check off completed items.\n\n### Workflow 2: STRIDE Threat Analysis\n\npytm automatically identifies threats based on STRIDE categories:\n\n- **Spoofing**: Identity impersonation attacks\n- **Tampering**: Unauthorized modification of data\n- **Repudiation**: Denial of actions without traceability\n- **Information Disclosure**: Unauthorized access to sensitive data\n- **Denial of Service**: Availability attacks\n- **Elevation of Privilege**: Unauthorized access escalation\n\nFor each identified threat:\n1. Review threat description and affected component\n2. Assess likelihood and impact (use `references\u002Frisk_matrix.md`)\n3. Determine if existing controls mitigate the threat\n4. Add mitigation using `threat.mitigation = \"description\"`\n5. Document residual risk and acceptance criteria\n\n### Workflow 3: Architecture as Code\n\nDefine system architecture programmatically:\n\n```python\nfrom pytm import TM, Server, Datastore, Dataflow, Boundary, Actor, Lambda\n\ntm = TM(\"Microservices Architecture\")\n\n# Cloud boundaries\ninternet = Boundary(\"Internet\")\ncloud_vpc = Boundary(\"Cloud VPC\")\n\n# API Gateway\napi_gateway = Server(\"API Gateway\")\napi_gateway.inBoundary = cloud_vpc\napi_gateway.implementsAuthentication = True\napi_gateway.implementsAuthorization = True\n\n# Microservices\nauth_service = Lambda(\"Auth Service\")\nauth_service.inBoundary = cloud_vpc\n\norder_service = Lambda(\"Order Service\")\norder_service.inBoundary = cloud_vpc\n\n# Data stores\nuser_db = Datastore(\"User Database\")\nuser_db.inBoundary = cloud_vpc\nuser_db.isEncryptedAtRest = True\n\n# Data flows with security properties\nclient_to_api = Dataflow(Actor(\"Client\"), api_gateway, \"API Request\")\nclient_to_api.protocol = \"HTTPS\"\nclient_to_api.isEncrypted = True\nclient_to_api.data = \"user credentials, orders\"\n\napi_to_auth = Dataflow(api_gateway, auth_service, \"Auth Check\")\napi_to_auth.protocol = \"gRPC\u002FTLS\"\n\nauth_to_db = Dataflow(auth_service, user_db, \"User Lookup\")\nauth_to_db.protocol = \"TLS\"\n\ntm.process()\n```\n\n### Workflow 4: CI\u002FCD Integration\n\nAutomate threat modeling in continuous integration:\n\n```yaml\n# .github\u002Fworkflows\u002Fthreat-model.yml\nname: Threat Model Analysis\non: [push, pull_request]\n\njobs:\n  threat-model:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v3\n\n      - name: Set up Python\n        uses: actions\u002Fsetup-python@v4\n        with:\n          python-version: '3.10'\n\n      - name: Install dependencies\n        run: |\n          pip install pytm\n          sudo apt-get install -y graphviz\n\n      - name: Generate threat model\n        run: python threat_model.py\n\n      - name: Upload DFD diagram\n        uses: actions\u002Fupload-artifact@v3\n        with:\n          name: threat-model-dfd\n          path: '*.png'\n\n      - name: Check for unmitigated threats\n        run: python scripts\u002Fcheck_mitigations.py threat_model.py\n```\n\n### Workflow 5: Threat Report Generation\n\nGenerate comprehensive threat documentation:\n\n```bash\n# Run threat model with report generation\npython threat_model.py\n\n# Generate markdown report\n.\u002Fscripts\u002Fgenerate_report.py --model threat_model.py --output threat_report.md\n\n# Generate JSON for tool integration\n.\u002Fscripts\u002Fgenerate_report.py --model threat_model.py --format json --output threats.json\n```\n\nReport includes:\n- System architecture overview\n- Trust boundary analysis\n- Complete STRIDE threat enumeration\n- Existing and recommended mitigations\n- Risk prioritization matrix\n\n## Security Considerations\n\n### Sensitive Data Handling\n\n- **Threat models as code**: Store in version control but review for sensitive architecture details\n- **Credentials and secrets**: Never hardcode in threat models - use placeholders\n- **Data classification**: Clearly label data flows with sensitivity levels (PII, PCI, PHI)\n- **Report distribution**: Control access to threat reports revealing security architecture\n\n### Access Control\n\n- **Threat model repository**: Restrict write access to security team and architects\n- **CI\u002FCD integration**: Protect threat modeling pipeline from tampering\n- **Diagram artifacts**: Control distribution of DFDs showing system architecture\n- **Mitigation tracking**: Integrate with secure issue tracking systems\n\n### Audit Logging\n\nLog the following for security governance:\n- Threat model creation and modification history\n- Identified threats and severity assessments\n- Mitigation implementation and validation\n- Risk acceptance decisions with approval\n- Threat model review and update cycles\n\n### Compliance Requirements\n\n- **NIST 800-30**: Risk assessment methodology alignment\n- **ISO 27001**: A.14.1.2 - Securing application services on public networks\n- **OWASP SAMM**: Threat Assessment practice maturity\n- **PCI-DSS 6.3.1**: Security threat identification in development\n- **SOC2 CC9.1**: Risk assessment process for system changes\n\n## Bundled Resources\n\n### Scripts (`scripts\u002F`)\n\n- `generate_report.py` - Generate markdown\u002FJSON threat reports with STRIDE categorization\n- `check_mitigations.py` - Validate all identified threats have documented mitigations\n- `threat_classifier.py` - Classify threats by severity using DREAD or custom risk matrix\n- `template_generator.py` - Generate threat model templates for common architectures\n\n### References (`references\u002F`)\n\n- `stride_methodology.md` - Complete STRIDE methodology guide with threat examples\n- `risk_matrix.md` - Risk assessment framework with likelihood and impact scoring\n- `component_library.md` - Reusable pytm components for common patterns (APIs, databases, cloud services)\n- `mitigation_strategies.md` - Common mitigation patterns mapped to STRIDE categories and OWASP controls\n\n### Assets (`assets\u002F`)\n\n- `templates\u002Fweb_application.py` - Web application threat model template\n- `templates\u002Fmicroservices.py` - Microservices architecture template\n- `templates\u002Fmobile_app.py` - Mobile application threat model template\n- `templates\u002Fiot_system.py` - IoT system threat model template\n- `dfd_styles.json` - Custom graphviz styling for professional diagrams\n\n## Common Patterns\n\n### Pattern 1: Web Application Three-Tier Architecture\n\n```python\nfrom pytm import TM, Server, Datastore, Dataflow, Boundary, Actor\n\ntm = TM(\"Three-Tier Web Application\")\n\n# Boundaries\ninternet = Boundary(\"Internet\")\ndmz = Boundary(\"DMZ\")\ninternal = Boundary(\"Internal Network\")\n\n# Components\nuser = Actor(\"End User\")\nuser.inBoundary = internet\n\nlb = Server(\"Load Balancer\")\nlb.inBoundary = dmz\nlb.implementsNonce = True\n\nweb = Server(\"Web Server\")\nweb.inBoundary = dmz\nweb.implementsAuthentication = True\nweb.implementsAuthenticationOut = False\n\napp = Server(\"Application Server\")\napp.inBoundary = internal\napp.implementsAuthorization = True\n\ndb = Datastore(\"Database\")\ndb.inBoundary = internal\ndb.isSQL = True\ndb.isEncryptedAtRest = True\n\n# Data flows\nDataflow(user, lb, \"HTTPS\").isEncrypted = True\nDataflow(lb, web, \"HTTPS\").isEncrypted = True\nDataflow(web, app, \"HTTP\").data = \"session token, requests\"\nDataflow(app, db, \"SQL\u002FTLS\").data = \"user data, transactions\"\n\ntm.process()\n```\n\n### Pattern 2: Cloud Native Microservices\n\n```python\nfrom pytm import TM, Lambda, Datastore, Dataflow, Boundary, Actor\n\ntm = TM(\"Cloud Microservices\")\n\ncloud = Boundary(\"Cloud Provider VPC\")\nuser = Actor(\"Mobile App\")\n\n# Serverless functions\napi_gateway = Lambda(\"API Gateway\")\napi_gateway.inBoundary = cloud\napi_gateway.implementsAPI = True\n\nauth_fn = Lambda(\"Auth Function\")\nauth_fn.inBoundary = cloud\n\n# Managed services\ncache = Datastore(\"Redis Cache\")\ncache.inBoundary = cloud\ncache.isEncrypted = True\n\ndb = Datastore(\"DynamoDB\")\ndb.inBoundary = cloud\ndb.isEncryptedAtRest = True\n\n# Data flows\nDataflow(user, api_gateway, \"API Call\").protocol = \"HTTPS\"\nDataflow(api_gateway, auth_fn, \"Auth\").protocol = \"internal\"\nDataflow(auth_fn, cache, \"Session\").isEncrypted = True\nDataflow(api_gateway, db, \"Query\").isEncrypted = True\n\ntm.process()\n```\n\n### Pattern 3: Adding Custom Threats\n\nDefine organization-specific threats:\n\n```python\nfrom pytm import TM, Threat\n\ntm = TM(\"Custom Threat Model\")\n\n# Add custom threat to component\nweb_server = Server(\"Web Server\")\n\ncustom_threat = Threat(\n    target=web_server,\n    id=\"CUSTOM-001\",\n    description=\"API rate limiting bypass using distributed requests\",\n    condition=\"web_server.implementsRateLimiting is False\",\n    mitigation=\"Implement distributed rate limiting with Redis\",\n    references=\"OWASP API Security Top 10 - API4 Unrestricted Resource Consumption\"\n)\n\nweb_server.threats.append(custom_threat)\n```\n\n### Pattern 4: Trust Boundary Analysis\n\nFocus on cross-boundary threats:\n\n```python\n# Identify all trust boundary crossings\nfor flow in tm.dataflows:\n    if flow.source.inBoundary != flow.sink.inBoundary:\n        print(f\"Cross-boundary flow: {flow.name}\")\n        print(f\"  From: {flow.source.inBoundary.name}\")\n        print(f\"  To: {flow.sink.inBoundary.name}\")\n        print(f\"  Encrypted: {flow.isEncrypted}\")\n        print(f\"  Authentication: {flow.implementsAuthentication}\")\n```\n\nTrust boundary crossings require extra scrutiny:\n- Authentication and authorization mechanisms\n- Encryption in transit\n- Input validation and sanitization\n- Logging and monitoring\n\n## Integration Points\n\n### SDLC Integration\n\n- **Design Phase**: Create initial threat model during architecture review\n- **Development**: Reference threat model for security requirements\n- **Code Review**: Validate mitigations are implemented correctly\n- **Testing**: Generate security test cases from identified threats\n- **Deployment**: Validate security controls match threat model assumptions\n- **Operations**: Update threat model for infrastructure changes\n\n### Security Tools Ecosystem\n\n- **Issue Tracking**: Export threats as Jira\u002FGitHub issues for mitigation tracking\n- **Documentation**: Generate threat models for security documentation\n- **SIEM**: Map threats to detection rules and monitoring alerts\n- **Pentesting**: Provide threat model to pentesters for targeted assessment\n- **Code Analysis**: Link SAST\u002FDAST findings to threat model threats\n\n### Cloud and DevOps\n\n- **Infrastructure as Code**: Threat model Terraform\u002FCloudFormation templates\n- **Container Security**: Model container orchestration and service mesh\n- **API Design**: Threat model API gateway and microservices communication\n- **Secrets Management**: Model key management and secrets distribution\n\n## Troubleshooting\n\n### Issue: Missing Threats in Output\n\n**Symptoms**: Expected STRIDE threats not appearing in generated report\n\n**Solution**:\n1. Verify component properties are set correctly (e.g., `isSQL=True` for databases)\n2. Check data flow security attributes (`isEncrypted`, `protocol`)\n3. Ensure components are assigned to boundaries\n4. Review trust boundary crossings\n5. Consult `references\u002Fstride_methodology.md` for threat conditions\n\n### Issue: Diagram Generation Failure\n\n**Symptoms**: DFD not generated or graphviz errors\n\n**Solution**:\n```bash\n# Verify graphviz installation\ndot -V\n\n# Install graphviz if missing\nbrew install graphviz  # macOS\nsudo apt-get install graphviz  # Linux\n\n# Test pytm with simple model\npython -c \"from pytm import TM; tm = TM('test'); tm.process()\"\n```\n\n### Issue: Too Many False Positive Threats\n\n**Symptoms**: Identified threats don't apply to your architecture\n\n**Solution**:\n1. Set accurate component properties to suppress irrelevant threats\n2. Use threat conditions to filter: `threat.condition = \"...\"`\n3. Document why threats don't apply: `threat.mitigation = \"N\u002FA - using managed service\"`\n4. Create custom threat library with `references\u002Fcomponent_library.md`\n\n### Issue: Threat Model Maintenance Drift\n\n**Symptoms**: Threat model doesn't reflect current architecture\n\n**Solution**:\n1. Store threat models in version control alongside architecture diagrams\n2. Trigger threat model regeneration in CI on architecture changes\n3. Schedule quarterly threat model reviews\n4. Link threat model updates to architecture review board approvals\n5. Use `scripts\u002Fcheck_mitigations.py` to validate completeness\n\n## Advanced Configuration\n\n### Custom Threat Definitions\n\nCreate organization-specific threat library:\n\n```python\n# custom_threats.py\nfrom pytm import Threat\n\ndef add_custom_threats(tm):\n    \"\"\"Add organization-specific threats to threat model\"\"\"\n\n    # Cloud-specific threats\n    cloud_misconfiguration = Threat(\n        id=\"CLOUD-001\",\n        description=\"Misconfigured cloud storage bucket exposes sensitive data\",\n        condition=\"datastore.inBoundary.name == 'Cloud' and not datastore.isEncrypted\",\n        mitigation=\"Enable encryption at rest and bucket policies\"\n    )\n\n    # API-specific threats\n    api_abuse = Threat(\n        id=\"API-001\",\n        description=\"API endpoint abuse through lack of rate limiting\",\n        condition=\"server.implementsAPI and not server.implementsRateLimiting\",\n        mitigation=\"Implement rate limiting and API key rotation\"\n    )\n\n    return [cloud_misconfiguration, api_abuse]\n```\n\n### Risk Scoring Integration\n\nAdd DREAD scoring to threats:\n\n```python\nclass ScoredThreat(Threat):\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.damage = 0        # 0-10\n        self.reproducibility = 0\n        self.exploitability = 0\n        self.affected_users = 0\n        self.discoverability = 0\n\n    def dread_score(self):\n        return (self.damage + self.reproducibility + self.exploitability +\n                self.affected_users + self.discoverability) \u002F 5\n\n# Usage\nthreat = ScoredThreat(\n    target=component,\n    description=\"SQL Injection\",\n    damage=9,\n    reproducibility=8,\n    exploitability=7,\n    affected_users=10,\n    discoverability=6\n)\nprint(f\"DREAD Score: {threat.dread_score()}\u002F10\")\n```\n\n### Diagram Customization\n\nCustomize DFD output with graphviz attributes:\n\n```python\n# Set custom colors for trust boundaries\ninternet.color = \"red\"\ndmz.color = \"orange\"\ninternal.color = \"green\"\n\n# Customize diagram output\ntm.graph_options = {\n    \"rankdir\": \"LR\",  # Left to right layout\n    \"bgcolor\": \"white\",\n    \"fontname\": \"Arial\",\n    \"fontsize\": \"12\"\n}\n```\n\n## References\n\n- [pytm GitHub Repository](https:\u002F\u002Fgithub.com\u002Fizar\u002Fpytm)\n- [OWASP Threat Modeling](https:\u002F\u002Fowasp.org\u002Fwww-community\u002FThreat_Modeling)\n- [Microsoft STRIDE Methodology](https:\u002F\u002Fwww.microsoft.com\u002Fen-us\u002Fsecurity\u002Fblog\u002F2007\u002F09\u002F11\u002Fstride-chart\u002F)\n- [MITRE ATT&CK Framework](https:\u002F\u002Fattack.mitre.org\u002F)\n- [Threat Modeling Manifesto](https:\u002F\u002Fwww.threatmodelingmanifesto.org\u002F)\n- [NIST 800-30: Risk Assessment](https:\u002F\u002Fcsrc.nist.gov\u002Fpublications\u002Fdetail\u002Fsp\u002F800-30\u002Frev-1\u002Ffinal)\n",{"name":5,"tags":43,"version":48,"category":21,"frameworks":49,"maintainer":53,"references":54,"description":59,"dependencies":60},[30,44,45,46,5,47,19],"stride","dfd","security-architecture","appsec","0.1.0",[50,51,52,31],"STRIDE","OWASP","MITRE-ATT&CK","SirAppSec",[55,56,57,58],"https:\u002F\u002Fgithub.com\u002Fizar\u002Fpytm","https:\u002F\u002Fowasp.org\u002Fwww-community\u002FThreat_Modeling","https:\u002F\u002Fwww.microsoft.com\u002Fen-us\u002Fsecurity\u002Fblog\u002F2007\u002F09\u002F11\u002Fstride-chart\u002F","https:\u002F\u002Fattack.mitre.org\u002F","Python-based threat modeling using pytm library for programmatic STRIDE analysis, data flow diagram generation, and automated security threat identification. Use when: (1) Creating threat models programmatically using Python code, (2) Generating data flow diagrams (DFDs) with automatic STRIDE threat identification, (3) Integrating threat modeling into CI\u002FCD pipelines and shift-left security practices, (4) Analyzing system architecture for security threats across trust boundaries, (5) Producing threat reports with STRIDE categories and mitigation recommendations, (6) Maintaining threat models as code for version control and automation.\n",{"python":61,"packages":62},">=3.7",[5,63],"graphviz","main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002Faiskillstore\u002Fmarketplace\u002Fagentsecops\u002Fpytm",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":8,"skillName":5,"commands":74,"prompt":84,"zipAvailable":85},[75,78,81],{"tool":76,"command":77},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill pytm",{"tool":79,"command":80},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill pytm",{"tool":82,"command":83},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill pytm","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fagentsecops\u002Fpytm\u002FSKILL.md",true,[87],{"path":88,"resourceType":89,"resourceTypeDesc":90,"sizeBytes":91,"sourceHtmlUrl":92},"skill-report.json","REFERENCE","参考文档",17922,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fagentsecops\u002Fpytm\u002Fskill-report.json",[94,103,112,121,127,133],{"skillNo":95,"name":96,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":97,"categories":98,"keywords":99,"publishedAt":38},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[100,101,102],"model","model hierarchy","model hierarchy skill",{"skillNo":104,"name":105,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":106,"categories":107,"keywords":108,"publishedAt":38},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[109,110,111],"MCP","zoom","zoom mcp",{"skillNo":113,"name":114,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":38},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[118,119,120,110],"sdk","zoom apps sdk","apps",{"skillNo":122,"name":123,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":124,"categories":125,"keywords":126,"publishedAt":38},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[123],{"skillNo":128,"name":129,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":130,"categories":131,"keywords":132,"publishedAt":38},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[129],{"skillNo":134,"name":135,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":136,"categories":137,"keywords":138,"publishedAt":38},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[135]]