Skip to content

CodeThreat/codethreat-appsec-azure-extension

Repository files navigation

CodeThreat Security Scan for Azure DevOps

Professional security scanning extension for Azure DevOps pipelines with comprehensive vulnerability detection and AI-powered analysis.

πŸ›‘οΈ Features

  • πŸ” SAST (Static Application Security Testing) - Source code vulnerability analysis
  • πŸ“¦ SCA (Software Composition Analysis) - Dependency vulnerability scanning
  • πŸ” Secrets Detection - Hardcoded credentials and API key detection
  • πŸ—οΈ Infrastructure as Code (IaC) - Infrastructure security scanning
  • πŸ€– AI-Powered Analysis - False positive elimination and intelligent insights
  • πŸ“Š Multiple Output Formats - SARIF, JSON, JUnit, CSV, XML
  • πŸ“‹ Custom Results Tab - Beautiful results visualization in Azure DevOps UI
  • πŸ” Network Diagnostics - Comprehensive debugging for corporate environments
  • 🏒 On-Premises Support - Works in air-gapped and corporate environments

πŸš€ Quick Start

1. Install Extension

Install the CodeThreat Security Scan extension from the Azure DevOps Marketplace.

2. Add to Pipeline

Add the CodeThreat Security Scan task to your azure-pipelines.yml:

trigger:
  - main

pool:
  vmImage: 'ubuntu-latest'  # Recommended: ubuntu-latest, windows-latest, macOS-latest

steps:
  - task: CodeThreatSecurityScan@1
    displayName: 'CodeThreat Security Scan'
    inputs:
      # Required
      apiKey: '$(CODETHREAT_API_KEY)'
      serverUrl: '$(CODETHREAT_SERVER_URL)'
      
      # Scan Configuration
      scanTypes: 'sast,sca,secrets'
      waitForCompletion: true
      timeout: 30
      
      # Build Protection
      failOnCritical: true
      failOnHigh: false
      
      # Output Configuration
      outputFormat: 'junit'
      outputFile: 'codethreat-results.xml'

  - task: PublishTestResults@2
    displayName: 'Publish Security Results'
    condition: always()
    inputs:
      testResultsFormat: 'JUnit'
      testResultsFiles: 'codethreat-results.xml'
      testRunTitle: 'CodeThreat Security Scan'

3. Configure Variables

In your Azure DevOps project, go to Library β†’ Variable groups and add:

Variable Name Value Secret
CODETHREAT_API_KEY your_api_key_here βœ… Yes
CODETHREAT_SERVER_URL https://app.codethreat.com No

πŸ“‹ Task Inputs

Required

Input Description Example
apiKey CodeThreat API key $(CODETHREAT_API_KEY)
serverUrl CodeThreat server URL https://app.codethreat.com

Optional

Input Description Default Options
organizationId Organization ID Auto-detected org-123
repositoryUrl Repository URL $(Build.Repository.Uri) Git URL
branch Branch to scan $(Build.SourceBranchName) Branch name
scanTypes Scan types sast,sca,secrets sast, sca, secrets, iac
waitForCompletion Wait for completion true true, false
timeout Timeout in minutes 30 1-120
pollInterval Poll interval in seconds 10 5-60
outputFormat Output format json json, sarif, junit, csv, xml
outputFile Output file path codethreat-results.json File path
failOnCritical Fail on critical true true, false
failOnHigh Fail on high severity false true, false
maxViolations Max violations 0 Number (0 = no limit)
skipImport Skip repository import false true, false
cliVersion CLI version latest Version number
verbose Verbose logging false true, false

πŸ“Š Task Outputs

The task sets the following pipeline variables:

Variable Description
CodeThreat.ScanId Scan identifier
CodeThreat.RepositoryId Repository identifier
CodeThreat.ViolationCount Total violations found
CodeThreat.CriticalCount Critical vulnerabilities
CodeThreat.HighCount High severity vulnerabilities
CodeThreat.SecurityScore Security score (0-100)
CodeThreat.ScanUrl Dashboard URL
CodeThreat.ResultsFile Results file path

Using Outputs

- task: CodeThreatSecurityScan@1
  name: SecurityScan
  inputs:
    apiKey: '$(CODETHREAT_API_KEY)'
    serverUrl: '$(CODETHREAT_SERVER_URL)'

- script: |
    echo "Violations found: $(CodeThreat.ViolationCount)"
    echo "Security Score: $(CodeThreat.SecurityScore)/100"
    echo "View Results: $(CodeThreat.ScanUrl)"
  displayName: 'Display Results'

πŸ“‹ Custom Results Tab

After running the CodeThreat Security Scan task, a "CodeThreat Results" tab will automatically appear in your Azure DevOps pipeline results alongside the default Summary tab.

Features

The custom tab provides:

  • πŸ“Š Visual Summary Cards: Interactive cards showing violation counts by severity
  • 🎯 Security Score Visualization: Progress bar with color-coded score (0-100)
  • πŸ“‹ Detailed Scan Information: Complete scan metadata and configuration
  • πŸ” Violations Breakdown: Detailed table with severity distribution and descriptions
  • πŸ”¬ Scan Types Analysis: Status and description of each security test performed
  • πŸ”— Quick Actions: Direct links to CodeThreat dashboard and result downloads

Tab Content

The tab displays:

  1. Summary Cards: Critical, High, Medium, Low violation counts + Security Score + Scan Duration
  2. Security Score Progress: Visual progress bar with color coding (Red < 60 < Orange < Yellow < Green)
  3. Scan Details Table: Scan ID, Repository, Branch, Types, Duration, Results file
  4. Violations Analysis: Severity breakdown with percentages and descriptions
  5. Scan Types Status: SAST, SCA, Secrets, IaC completion status
  6. Quick Actions: Links to dashboard, download results, view raw data

Example Tab View

πŸ›‘οΈ CodeThreat Security Analysis Results
Comprehensive security scan results with AI-powered analysis

[Critical: 1] [High: 3] [Medium: 5] [Low: 2] [Score: 78/100] [Duration: 85s]

πŸ“Š Security Score Analysis
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 78%

πŸ“‹ Scan Information
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Scan ID         β”‚ cmf5fitgk003s2mig1efs7cjx                β”‚
β”‚ Repository      β”‚ MyApp Repository                         β”‚
β”‚ Branch          β”‚ main                                     β”‚
β”‚ Scan Types      β”‚ SAST, SCA, Secrets                       β”‚
β”‚ Duration        β”‚ 85 seconds                               β”‚
β”‚ Total Violationsβ”‚ 11                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ” Violations by Severity
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Severity β”‚ Count β”‚ Percentage β”‚ Description                                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Critical β”‚   1   β”‚     9%     β”‚ Immediate attention required                 β”‚
β”‚ High     β”‚   3   β”‚    27%     β”‚ Should be fixed soon                         β”‚
β”‚ Medium   β”‚   5   β”‚    46%     β”‚ Should be addressed                          β”‚
β”‚ Low      β”‚   2   β”‚    18%     β”‚ Consider fixing                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

[🌐 View in CodeThreat Dashboard] [πŸ“„ Download Results] [πŸ” View Raw Results]

🎯 Usage Examples

Basic Security Scan

- task: CodeThreatSecurityScan@1
  inputs:
    apiKey: '$(CODETHREAT_API_KEY)'
    serverUrl: '$(CODETHREAT_SERVER_URL)'
    scanTypes: 'sast,sca,secrets'

Advanced Configuration

- task: CodeThreatSecurityScan@1
  inputs:
    # Authentication
    apiKey: '$(CODETHREAT_API_KEY)'
    serverUrl: '$(CODETHREAT_SERVER_URL)'
    organizationId: '$(CODETHREAT_ORG_ID)'
    
    # Scan Configuration
    scanTypes: 'sast,sca,secrets,iac'
    waitForCompletion: true
    timeout: 45
    pollInterval: 15
    
    # Build Protection
    failOnCritical: true
    failOnHigh: true
    maxViolations: 10
    
    # Output Configuration
    outputFormat: 'sarif'
    outputFile: 'security-results.sarif'
    verbose: true

Multi-Environment Pipeline

stages:
  - stage: SecurityScan
    displayName: 'Security Analysis'
    jobs:
      - job: CodeThreatScan
        displayName: 'CodeThreat Security Scan'
        steps:
          - task: CodeThreatSecurityScan@1
            displayName: 'Run Security Scan'
            inputs:
              apiKey: '$(CODETHREAT_API_KEY)'
              serverUrl: '$(CODETHREAT_SERVER_URL)'
              scanTypes: 'sast,sca,secrets'
              failOnCritical: true
              outputFormat: 'junit'
              outputFile: 'security-results.xml'
          
          - task: PublishTestResults@2
            displayName: 'Publish Security Results'
            condition: always()
            inputs:
              testResultsFormat: 'JUnit'
              testResultsFiles: 'security-results.xml'
              testRunTitle: 'Security Analysis'

  - stage: Deploy
    displayName: 'Deploy Application'
    dependsOn: SecurityScan
    condition: succeeded()
    jobs:
      - deployment: Deploy
        displayName: 'Deploy to Production'
        environment: 'production'
        strategy:
          runOnce:
            deploy:
              steps:
                - script: echo "Deploying secure application..."

Conditional Scanning

# Only scan on main branch pushes
- task: CodeThreatSecurityScan@1
  condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
  inputs:
    apiKey: '$(CODETHREAT_API_KEY)'
    serverUrl: '$(CODETHREAT_SERVER_URL)'
    scanTypes: 'sast,sca,secrets,iac'
    failOnCritical: true
    failOnHigh: true

🏒 On-Premises Usage

Air-Gapped Environments

The extension supports on-premises and air-gapped environments:

- task: CodeThreatSecurityScan@1
  inputs:
    apiKey: '$(CODETHREAT_API_KEY)'
    serverUrl: 'https://codethreat.yourcompany.com'  # Your private server
    cliVersion: '1.0.3'  # Specific version for stability

Custom CLI Installation

For environments with restricted internet access, you can pre-install the CLI:

# Pre-install CLI in pipeline
- script: |
    npm install -g @codethreat/appsec-cli@1.0.3
  displayName: 'Install CodeThreat CLI'

- task: CodeThreatSecurityScan@1
  inputs:
    apiKey: '$(CODETHREAT_API_KEY)'
    serverUrl: '$(CODETHREAT_SERVER_URL)'

πŸ”§ Troubleshooting

Common Issues

"API key is required"

  • Ensure CODETHREAT_API_KEY is set in your variable group
  • Verify the variable is marked as secret
  • Check variable group is linked to your pipeline

"Authentication failed"

  • Verify API key is valid and not expired
  • Check server URL is correct and accessible
  • Ensure organization has appropriate permissions

"CLI installation failed"

  • Check if Node.js is available in the build agent
  • Verify internet access for npm installation
  • For on-premises: ensure binary download URL is accessible

"Scan timeout"

  • Increase timeout value for large repositories
  • Consider running scans asynchronously (waitForCompletion: false)
  • Check repository size and scan types

Azure DevOps Warnings

"Node version (16) is end-of-life"

  • βœ… Fixed in v1.1.0+: Extension now uses Node.js 20
  • Update to latest extension version from marketplace

"windows-2019 runner image is being deprecated"

  • Solution: Update your pipeline YAML to use latest runner images
  • Use vmImage: 'windows-latest' instead of windows-2019
  • Use vmImage: 'ubuntu-latest' instead of ubuntu-18.04
# βœ… Recommended (no warnings)
pool:
  vmImage: 'ubuntu-latest'    # Latest Ubuntu LTS
  # or
  vmImage: 'windows-latest'   # Latest Windows Server
  # or  
  vmImage: 'macOS-latest'     # Latest macOS

# ❌ Deprecated (causes warnings)  
pool:
  vmImage: 'windows-2019'     # Deprecated
  vmImage: 'ubuntu-18.04'     # Deprecated
  vmImage: 'macOS-10.15'      # Deprecated

Debug Mode

Enable verbose logging:

- task: CodeThreatSecurityScan@1
  inputs:
    apiKey: '$(CODETHREAT_API_KEY)'
    serverUrl: '$(CODETHREAT_SERVER_URL)'
    verbose: true

Or enable system debug:

  • Set System.Debug pipeline variable to true

πŸ“š Documentation

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ†˜ Support

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors