Skip to content

🎯 GetSecurityAdvisoriesForPackages

Fetches security advisories for a given batch of packages (grouped by package name).

When to use

🎯 When you already know a project's direct dependency list and only care about vulnerabilities in those packages; 🚀 in a CI pipeline, batch-validate dependency security after composer install; 🔎 for ad-hoc investigation targeting a specific vendor.

Signature

go
func (c *ComposerClient) GetSecurityAdvisoriesForPackages(packageNames []string) (*domain.AdvisoriesResponse, error)

Parameters

ParameterTypeDescription
packageNames[]stringList of package names, e.g. []string{"symfony/http-foundation", "guzzlehttp/guzzle"}

Return value

ValueTypeDescription
Result*domain.AdvisoriesResponseAdvisories is a map[package name][]*Advisory, containing only the requested packages
ErrorerrorReturned on HTTP failure, non-200 status, or JSON parse failure

Corresponding endpoint: GET https://packagist.org/api/security-advisories/?packages[]={pkg}&packages[]={pkg}.

Example

go
package main

import (
	"fmt"
	"log"
	"time"

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

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

	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 affects versions %s\n", a.Title, a.AffectedVersions)
		}
	}
}

Advanced

Released under the MIT License