Skip to content

feat: add security advisories support#74

Merged
leoafarias merged 1 commit into
mainfrom
security-advisories
Nov 5, 2025
Merged

feat: add security advisories support#74
leoafarias merged 1 commit into
mainfrom
security-advisories

Conversation

@leoafarias

Copy link
Copy Markdown
Owner

Summary

Implements the /api/packages/<package>/advisories endpoint from the Hosted Pub Repository Specification Version 2. This endpoint is live and working on pub.dev, providing security advisories in OSV format for packages.

Changes

  • Add packageAdvisories endpoint to Endpoint class
  • Create PackageAdvisories, SecurityAdvisory, and Affected models following OSV schema 1.6.0
  • Add packageAdvisories() method to PubClient that gracefully handles unsupported endpoints (returns null on 404)
  • Include pubDisplayUrl convenience getter for accessing advisory URLs from database_specific field
  • Add comprehensive tests including integration tests with real API data

Implementation Details

Models

The implementation follows the OSV (Open Source Vulnerability) schema 1.6.0:

  • PackageAdvisories: Contains list of advisories and optional advisoriesUpdated timestamp
  • SecurityAdvisory: Full OSV fields including id, summary, details, affected versions, and database_specific
  • Affected: Tracks affected versions

Error Handling

The client gracefully handles three scenarios:

  1. Packages with advisories (e.g., http, dio)
  2. Packages without advisories (e.g., flutter - empty array)
  3. Servers that don't support the endpoint (404 → returns null)

Testing

  • ✅ Endpoint URL generation test
  • ✅ Integration test with http package (1 advisory)
  • ✅ Integration test with dio package (2 advisories)
  • ✅ Integration test with flutter package (no advisories)
  • ✅ All 48 tests passing

Usage Example

final client = PubClient();
final advisories = await client.packageAdvisories('http');

if (advisories != null) {
  print('Last updated: ${advisories.advisoriesUpdated}');
  
  for (final advisory in advisories.advisories) {
    print('${advisory.id}: ${advisory.summary}');
    print('URL: ${advisory.pubDisplayUrl}');
  }
}

Closes #67

Implement /api/packages/<package>/advisories endpoint support
following the Hosted Pub Repository Specification Version 2.

Changes:
- Add packageAdvisories endpoint to Endpoint class
- Create PackageAdvisories, SecurityAdvisory, and Affected models
  following OSV schema 1.6.0
- Add packageAdvisories() method to PubClient that returns null
  for servers that don't support the endpoint
- Include pubDisplayUrl convenience getter for accessing advisory URLs
- Add comprehensive tests including integration tests with real API data

The implementation gracefully handles:
- Packages with advisories (http, dio)
- Packages without advisories (flutter)
- Servers that don't support the endpoint (404 → null)

Closes #67
@leoafarias
leoafarias merged commit 98a5b57 into main Nov 5, 2025
1 check passed
@leoafarias
leoafarias deleted the security-advisories branch November 5, 2025 00:54
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.

Add security advisories support

1 participant