Skip to content

Add vulnerable example to test annotations - #1

Merged
imjasonh merged 1 commit into
mainfrom
add-vulnerable-example
Jun 7, 2025
Merged

Add vulnerable example to test annotations#1
imjasonh merged 1 commit into
mainfrom
add-vulnerable-example

Conversation

@imjasonh

@imjasonh imjasonh commented Jun 7, 2025

Copy link
Copy Markdown
Owner

Summary

This PR adds a vulnerable example to demonstrate the govulncheck action's capabilities and includes several enhancements to improve vulnerability reporting and user experience.

🎯 Key Features Added

  1. Vulnerable Example

    • Added example/ directory with code that intentionally uses a vulnerable version of golang.org/x/net
    • Demonstrates real vulnerability detection in action
    • Shows how annotations appear on both go.mod and source code
  2. Enhanced Annotations

    • Rich context including vulnerability summaries, CVE numbers, and fix recommendations
    • Direct links to Go vulnerability database (pkg.go.dev/vuln)
    • Proper file path handling for subdirectories
    • Shows the actual vulnerable function being called (e.g., "html.Parse" not "main")
  3. Suggested Fixes

    • When vulnerable code is actually called, creates notice annotations
    • Shows current vs suggested dependency versions
    • Lists which specific vulnerabilities have active call sites
  4. Workflow Summary

    • Comprehensive report using GitHub Actions summary API
    • Formatted tables showing vulnerabilities by module
    • Vulnerable code locations organized by file
    • Clear upgrade recommendations

📸 What It Looks Like

When the action runs on the example, it will:

  • ⚠️ Create warning annotations on vulnerable modules in go.mod
  • 🚨 Create warning annotations on code that calls vulnerable functions
  • 🔧 Suggest specific version updates when vulnerabilities are actively used
  • 📊 Generate a detailed workflow summary with all findings

🧪 Test Plan

The PR includes a workflow that runs on the vulnerable example. You can see:

  • Annotations appear on the correct lines in go.mod and main.go
  • Vulnerability details include links and CVE numbers
  • Suggested fixes show the exact version to update to
  • Workflow summary displays a comprehensive report

🐛 Bug Fixes Included

  • Fixed JSON parsing to handle both JSON lines and multi-line JSON formats
  • Fixed annotation file paths when running in subdirectories
  • Improved extraction of vulnerable function names from trace data
  • Enhanced OSV detail parsing and storage

🤖 Generated with Claude Code

This commit adds a comprehensive example demonstrating the govulncheck action's capabilities, along with several enhancements to improve the user experience.

## Changes

### Example Setup
- Added example/main.go that uses golang.org/x/net v0.0.0-20220906165146-f3363e06e74c (vulnerable version)
- Example intentionally calls html.Parse to trigger vulnerability detection
- Demonstrates how the action creates annotations on vulnerable code

### Enhanced Annotations
- Fixed file path handling when running in subdirectories (e.g., './example')
- Added rich context to annotations including:
  - Vulnerability summaries and CVE numbers
  - Direct links to Go vulnerability database (pkg.go.dev/vuln)
  - Fixed version information
  - Clear indication of which function is vulnerable (e.g., "html.Parse" not "main")
- Sorted vulnerabilities by OSV ID for consistent display

### Suggested Fixes
- When vulnerable code is actually called, creates notice annotations on go.mod
- Shows current vs suggested dependency versions
- Lists which specific vulnerabilities have active call sites
- Provides actionable upgrade recommendations

### Workflow Summary
- Added comprehensive workflow summary using GitHub Actions summary API
- Displays vulnerabilities in formatted tables by module
- Shows vulnerable code locations organized by file
- Includes links to Go vulnerability database entries
- Provides clear recommendations for fixing vulnerabilities

### Bug Fixes
- Fixed JSON parsing to handle both JSON lines and multi-line JSON formats
- Fixed annotation file paths to be relative to repository root
- Improved vulnerability function name extraction from trace data
- Enhanced OSV detail parsing and storage

## Testing
The example workflow demonstrates all features by intentionally using a vulnerable dependency. When run, it will:
1. Detect vulnerabilities in golang.org/x/net
2. Create warning annotations on go.mod and main.go
3. Suggest specific version updates
4. Generate a detailed workflow summary

This provides a complete demonstration of the action's vulnerability detection and reporting capabilities.
@imjasonh
imjasonh force-pushed the add-vulnerable-example branch from a0bdd29 to 3a117d2 Compare June 7, 2025 04:58
@imjasonh
imjasonh merged commit f1b84c8 into main Jun 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant