Skip to content

🔒 Security Advisory Models

Structures in pkg/domain that describe Packagist security advisories. They correspond to Packagist's https://packagist.org/api/security-advisories/ API endpoints and are deserialized by ComposerClient.GetSecurityAdvisories / GetSecurityAdvisoriesForPackages / GetSecurityAdvisoriesSince.

Type Overview

TypeRole
AdvisoriesResponseTop-level response, advisory mapping grouped by package name
AdvisorySingle security advisory details
SourceAdvisory source (GitHub, NVD, etc.)

🛡️ AdvisoriesResponse

Top-level structure for security advisory responses. Advisories is a map where keys are package names and values are lists of advisories for that package.

go
type AdvisoriesResponse struct {
    Advisories map[string][]*Advisory `json:"advisories"`
}
FieldTypeDescription
Advisoriesmap[string][]*AdvisorySecurity advisory mapping, key is package name (e.g., symfony/http-foundation), value is the list of security advisories for that package

Typical JSON form

json
{
  "advisories": {
    "symfony/http-foundation": [
      {"advisoryId": "PKSA-38s9-s9dj", "packageName": "symfony/http-foundation", ...}
    ]
  }
}

🐞 Advisory

Single security advisory, containing vulnerability identifier, affected scope, source, and timing.

go
type Advisory struct {
    AdvisoryID         string    `json:"advisoryId"`
    PackageName        string    `json:"packageName"`
    RemoteID           string    `json:"remoteId"`
    Title              string    `json:"title"`
    Link               string    `json:"link"`
    Cve                string    `json:"cve"`
    AffectedVersions   string    `json:"affectedVersions"`
    Source             string    `json:"source"`
    ReportedAt         string    `json:"reportedAt"`
    ComposerRepository string    `json:"composerRepository"`
    Sources            []*Source `json:"sources"`
}
FieldTypeDescriptionExample
AdvisoryIDstringPackagist advisory unique identifierPKSA-38s9-s9dj
PackageNamestringAffected Composer package namesymfony/http-foundation
RemoteIDstringID in remote systemCVE-2022-24894
TitlestringAdvisory titleHTTP Request Smuggling in Symfony HttpFoundation
LinkstringAdvisory detail linkhttps://github.com/advisories/GHSA-rc93-5vf2-xh7q
CvestringCVE numberCVE-2022-24894
AffectedVersionsstringAffected version range (Composer version constraint syntax)>=5.4.0,<5.4.19|>=6.0.0,<6.0.4
SourcestringSource platformGitHub
ReportedAtstringReport time (ISO 8601 string)2022-03-10T12:00:00Z
ComposerRepositorystringRelated Composer repositorypackagist
Sources[]*SourceMultiple source information listSee next section

AffectedVersions uses pipe to separate multiple constraints

AffectedVersions is a Composer version constraint string where multiple segments are separated by | (e.g., >=5.4.0,<5.4.19|>=6.0.0,<6.0.4). When checking whether a specific version is affected, use Composer's version constraint parser instead of simple string comparison.


🌐 Source

Advisory source information, possibly from different security databases.

go
type Source struct {
    Name     string `json:"name"`
    RemoteID string `json:"remoteId"`
}
FieldTypeDescriptionExample
NamestringSource nameGitHub, NVD
RemoteIDstringRemote ID in source platformGHSA-rc93-5vf2-xh7q

🚀 Example: Fetch and Iterate Security Advisories

go
package main

import (
    "fmt"
    "log"
    "time"

    "github.com/scagogogo/composer-skills/pkg/client"
)

func main() {
    c := client.NewComposerClient(60 * time.Second)

    // Fetch security advisories for specified packages
    resp, err := c.GetSecurityAdvisoriesForPackages([]string{"symfony/http-foundation", "guzzlehttp/guzzle"})
    if err != nil {
        log.Fatal(err)
    }

    for pkg, advisories := range resp.Advisories {
        fmt.Printf("=== %s (%d advisories) ===\n", pkg, len(advisories))
        for _, a := range advisories {
            fmt.Printf("  [%s] %s\n", a.Cve, a.Title)
            fmt.Printf("    Affected versions: %s\n", a.AffectedVersions)
            fmt.Printf("    Reported at:       %s\n", a.ReportedAt)
            fmt.Printf("    Link:              %s\n", a.Link)
        }
    }
}

Incremental fetch by time

For security monitoring, use GetSecurityAdvisoriesSince(updatedSince time.Time) to fetch only advisories updated after a specific time point, suitable for scheduled polling scenarios.

Released under the MIT License