Documentation
¶
Overview ¶
Package vulnx provides a robust, idiomatic Go client for interacting with the ProjectDiscovery vulnx REST API. The client focuses on the "/v2/vulnerability" endpoints, exposing high-level helper methods that handle authentication, request construction, network-level retries, and JSON decoding so that callers can concentrate on business logic.
Quick Start ¶
The snippet below demonstrates a minimal, production-ready workflow. While authentication is optional, using an API key is strongly recommended to avoid rate limiting and ensure better performance:
ctx := context.Background()
client, err := vulnx.New(
vulnx.WithKeyFromEnv(), // or vulnx.WithPDCPKey("<YOUR_KEY>")
)
if err != nil {
log.Fatal(err)
}
out, err := client.SearchVulnerabilities(ctx, vulnx.SearchParams{
Query: vulnx.Ptr("id:CVE-2023-4799"),
Limit: vulnx.Ptr(10),
})
if err != nil {
log.Fatal(err)
}
fmt.Println(len(out.Vulnerabilities))
Rate Limiting ¶
Unauthenticated requests are subject to strict rate limits. If you encounter 429 (Too Many Requests) errors, configure an API key using WithPDCPKey() or WithKeyFromEnv() to get higher rate limits and better service reliability.
The client is safe for concurrent use by multiple goroutines.
For complete API semantics refer to https://api.projectdiscovery.io/docs.
Package vulnx provides types for the /v2/vulnerability API client.
Index ¶
- Constants
- Variables
- func Ptr[T any](v T) *T
- type AIMeta
- type Citation
- type Classification
- type Client
- func (c *Client) GetVulnerabilityByID(ctx context.Context, id string, params *GetByIDParams) (VulnerabilityResponse, error)
- func (c *Client) GetVulnerabilityFilters(ctx context.Context) ([]VulnerabilityFilter, error)
- func (c *Client) IsAuthenticated() bool
- func (c *Client) SearchVulnerabilities(ctx context.Context, params SearchParams) (SearchResponse, error)
- type ExposureStats
- type GetByIDParams
- type H1Stats
- type KevInfo
- type Option
- func WithBaseURL(url string) Option
- func WithClient(hc *retryablehttp.Client) Option
- func WithDebugRequest(cb func(*http.Request)) Option
- func WithDebugResponse(cb func(*http.Response)) Option
- func WithKeyFromEnv() Option
- func WithPDCPKey(apiKey string) Option
- func WithRetryableHTTPOptions(clientOpts retryablehttp.Options) Option
- type POC
- type ProductInfo
- type Schema
- type SearchEngineStats
- type SearchParams
- type SearchResponse
- type VulnExposure
- type Vulnerability
- type VulnerabilityFilter
- type VulnerabilityResponse
- type Weakness
Constants ¶
const ( // DefaultBaseURL is the default base URL for the API. DefaultBaseURL = "https://api.projectdiscovery.io" // UserAgent is the default user agent for the client. UserAgent = "vulnx-client/1.0" // BaseURLEnvVar is the environment variable name for overriding the base URL. BaseURLEnvVar = "VULNX_API_URL" )
Variables ¶
var ( ErrBadRequest = errkit.New("bad request: client sent an invalid request") ErrNotFound = errkit.New("not found: resource does not exist") ErrTooManyRequests = errkit.New("too many requests: rate limit exceeded - consider using an API key for higher limits") ErrInternalServerError = errkit.New("internal server error: something went wrong on the server") ErrUnknownAPIError = errkit.New("unknown api error") ErrRequestBuildFailure = errkit.New("failed to build request") ErrRequestFailed = errkit.New("request failed") ErrMarshalBody = errkit.New("failed to marshal request body") ErrCreateHTTPRequest = errkit.New("failed to create http request") ErrDecodeResponse = errkit.New("failed to decode response") )
Client errors
Functions ¶
Types ¶
type AIMeta ¶
type AIMeta struct {
IsPromptByHuman bool `json:"is_prompt_by_human,omitempty"`
IsTemplateByHuman bool `json:"is_template_by_human,omitempty"`
ModelUsed string `json:"model_used,omitempty"`
Prompt string `json:"prompt,omitempty"`
}
AIMeta represents AI metadata for a template.
type Citation ¶
type Citation struct {
AddedAt *time.Time `json:"added_at,omitempty"`
Source string `json:"source,omitempty"`
Tags []string `json:"tags,omitempty"`
URL string `json:"url,omitempty"`
}
Citation represents a citation for a vulnerability/template.
type Classification ¶
type Classification struct {
Cpe string `json:"cpe,omitempty"`
CveID []string `json:"cve_id,omitempty"`
CvssMetrics string `json:"cvss_metrics,omitempty"`
CvssScore float64 `json:"cvss_score,omitempty"`
CweID []string `json:"cwe_id,omitempty"`
EpssPercentile float64 `json:"epss_percentile,omitempty"`
EpssScore float64 `json:"epss_score,omitempty"`
}
Classification represents classification metadata for a template.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides high-level helpers around the vulnx API. It is safe for concurrent use. Zero values for *Client* fields are not meaningful—always use the *New* constructor.
func New ¶
New returns a new *Client* configured by the supplied *Option*s. Authentication is optional but strongly recommended - unauthenticated requests are subject to strict rate limits. Use *WithPDCPKey* or *WithKeyFromEnv* to configure an API key for better performance and higher rate limits.
The returned client is ready for immediate use:
c, err := vulnx.New(vulnx.WithPDCPKey("<YOUR_KEY>"))
if err != nil { /* handle */ }
// Or without authentication (subject to rate limits):
c, err := vulnx.New()
if err != nil { /* handle */ }
Custom HTTP behaviour (timeouts, retries, logging) can be injected via *WithClient* or *WithRetryableHTTPOptions*.
func (*Client) GetVulnerabilityByID ¶
func (c *Client) GetVulnerabilityByID(ctx context.Context, id string, params *GetByIDParams) (VulnerabilityResponse, error)
GetVulnerabilityByID fetches a single vulnerability document identified by its canonical ID (for example "CVE-2023-1234").
When *params* is non-nil the *Fields* slice can be used to limit the response payload to a subset of fields, reducing bandwidth.
func (*Client) GetVulnerabilityFilters ¶
func (c *Client) GetVulnerabilityFilters(ctx context.Context) ([]VulnerabilityFilter, error)
GetVulnerabilityFilters lists all filter definitions that can be applied to search queries. Filters are stable identifiers used for building rich UI facets or powering autocomplete experiences.
func (*Client) IsAuthenticated ¶
IsAuthenticated returns true if the client has an API key configured. This can be used to provide better UX messaging about rate limits.
func (*Client) SearchVulnerabilities ¶
func (c *Client) SearchVulnerabilities(ctx context.Context, params SearchParams) (SearchResponse, error)
SearchVulnerabilities performs a full-text search across all vulnerability documents and returns a paginated *SearchResponse*.
The behaviour of the search is controlled via *SearchParams*; see that type for field-level documentation.
SearchVulnerabilities may contact the network multiple times if retries are enabled on the underlying HTTP client. It is safe to call concurrently.
type ExposureStats ¶
type ExposureStats struct {
Fofa *SearchEngineStats `json:"fofa,omitempty"`
ID string `json:"id,omitempty"`
MaxHosts int `json:"max_hosts,omitempty"`
MinHosts int `json:"min_hosts,omitempty"`
Shodan *SearchEngineStats `json:"shodan,omitempty"`
}
ExposureStats represents search engine stats for a product.
type GetByIDParams ¶
type GetByIDParams struct {
Fields []string `json:"fields,omitempty"`
}
GetByIDParams defines optional query parameters for GetVulnerabilityByID.
type H1Stats ¶
type H1Stats struct {
DeltaRank int `json:"delta_rank,omitempty"`
DeltaReports int `json:"delta_reports,omitempty"`
Rank int `json:"rank,omitempty"`
Reports int `json:"reports,omitempty"`
}
H1Stats represents HackerOne stats for a vulnerability.
type KevInfo ¶
type KevInfo struct {
AddedDate *time.Time `json:"added_date,omitempty"`
DueDate *time.Time `json:"due_date,omitempty"`
KnownRansomwareCampaignUse bool `json:"known_ransomware_campaign_use,omitempty"`
Source string `json:"source,omitempty"`
}
KevInfo represents KEV (Known Exploited Vulnerabilities) info.
type Option ¶
type Option func(*Client)
Option represents a functional option that mutates a *Client* during construction. It follows the standard "functional options" pattern popularised by Google and is the preferred way to add optional parameters without an explosion of constructor variants.
A typical call site looks like this:
client, err := vulnx.New(
vulnx.WithPDCPKey("<YOUR_KEY>"),
vulnx.WithRetryableHTTPOptions(retryablehttp.Options{RetryMax: 5}),
)
if err != nil {
// handle error
}
func WithBaseURL ¶
WithBaseURL points the client at an alternative endpoint—useful for testing against staging or mock servers.
func WithClient ¶
func WithClient(hc *retryablehttp.Client) Option
WithClient overrides the default *retryablehttp.Client* used for all network operations. It enables advanced users to specify custom transports, proxy settings, or instrumentation hooks.
func WithDebugRequest ¶
WithDebugRequest sets a callback that is invoked with the *http.Request before it is sent.
func WithDebugResponse ¶
WithDebugResponse sets a callback that is invoked with the *http.Response after it is received (before decoding).
func WithKeyFromEnv ¶
func WithKeyFromEnv() Option
WithKeyFromEnv attempts to discover a PDCP API key from the local credential store (managed by `pdcp`) or the `PDCP_API_KEY` environment variable.
func WithPDCPKey ¶
WithPDCPKey sets the ProjectDiscovery Cloud Platform (PDCP) API key that will be sent in the `X-PDCP-Key` HTTP header.
func WithRetryableHTTPOptions ¶
func WithRetryableHTTPOptions(clientOpts retryablehttp.Options) Option
WithRetryableHTTPOptions constructs a fresh *retryablehttp.Client* with the supplied options and wires it into the *Client* instance.
type POC ¶
type POC struct {
AddedAt *time.Time `json:"added_at,omitempty"`
Source string `json:"source,omitempty"`
URL string `json:"url,omitempty"`
}
POC represents a proof of concept for a vulnerability.
type ProductInfo ¶
type ProductInfo struct {
Category string `json:"category,omitempty"`
Cpe []string `json:"cpe,omitempty"`
DeploymentModel string `json:"deployment_model,omitempty"`
Industry string `json:"industry,omitempty"`
IsPd bool `json:"is_pd,omitempty"`
Product string `json:"product,omitempty"`
ProjectRepos map[string]any `json:"project_repos,omitempty"`
Projects []string `json:"projects,omitempty"`
Summary string `json:"summary,omitempty"`
TechDomain string `json:"tech_domain,omitempty"`
Vendor string `json:"vendor,omitempty"`
}
ProductInfo represents affected product information.
type Schema ¶
type Schema struct {
Version string `json:"version,omitempty"`
}
Schema represents schema information for a template.
type SearchEngineStats ¶
type SearchEngineStats struct {
MaxHosts int `json:"max_hosts,omitempty"`
MinHosts int `json:"min_hosts,omitempty"`
Queries []string `json:"queries,omitempty"`
}
SearchEngineStats represents stats from a search engine.
type SearchParams ¶
type SearchParams struct {
Limit *int `json:"limit,omitempty"`
Offset *int `json:"offset,omitempty"`
SortAsc *string `json:"sort_asc,omitempty"`
SortDesc *string `json:"sort_desc,omitempty"`
Fields []string `json:"fields,omitempty"`
TermFacets []string `json:"term_facets,omitempty"`
RangeFacets []string `json:"range_facets,omitempty"`
Query *string `json:"q,omitempty"`
Highlight *bool `json:"highlight,omitempty"`
FacetSize *int `json:"facet_size,omitempty"`
}
SearchParams defines query parameters for vulnerability search.
type SearchResponse ¶
type SearchResponse struct {
Count int `json:"count"`
Facets map[string]any `json:"facets,omitempty"`
Results []Vulnerability `json:"results"`
Total int `json:"total"`
}
SearchResponse represents the response from /v2/vulnerability/search.
type VulnExposure ¶
type VulnExposure struct {
MaxHosts int `json:"max_hosts,omitempty"`
MinHosts int `json:"min_hosts,omitempty"`
Values []*ExposureStats `json:"values,omitempty"`
}
VulnExposure represents exposure stats for a vulnerability.
type Vulnerability ¶
type Vulnerability struct {
// CVEInfo fields
CVEID string `json:"cve_id,omitempty"`
AgeInDays int `json:"age_in_days,omitempty"`
Assignee string `json:"assignee,omitempty"`
CveCreatedAt *time.Time `json:"cve_created_at,omitempty"`
CveUpdatedAt *time.Time `json:"cve_updated_at,omitempty"`
CvssMetrics string `json:"cvss_metrics,omitempty"`
CvssScore float64 `json:"cvss_score,omitempty"`
EpssPercentile float64 `json:"epss_percentile,omitempty"`
EpssScore float64 `json:"epss_score,omitempty"`
IsAuth bool `json:"is_auth,omitempty"`
IsKev bool `json:"is_kev,omitempty"`
IsOss bool `json:"is_oss,omitempty"`
IsPatchAvailable bool `json:"is_patch_available,omitempty"`
IsPoc bool `json:"is_poc,omitempty"`
IsRemote bool `json:"is_remote,omitempty"`
IsTemplate bool `json:"is_template,omitempty"`
IsVkev bool `json:"is_vkev,omitempty"`
Kev []*KevInfo `json:"kev,omitempty"`
PocCount int `json:"poc_count,omitempty"`
PocFirstSeen *time.Time `json:"poc_first_seen,omitempty"`
Pocs []*POC `json:"pocs,omitempty"`
VulnStatus string `json:"vuln_status,omitempty"`
// VulnerabilityInfo extra fields
Citations []*Citation `json:"citations,omitempty"`
Cwe []string `json:"cwe,omitempty"`
Description string `json:"description,omitempty"`
Impact string `json:"impact,omitempty"`
Name string `json:"name,omitempty"`
Product string `json:"product,omitempty"`
Remediation string `json:"remediation,omitempty"`
RequirementType string `json:"requirement_type,omitempty"`
Requirements string `json:"requirements,omitempty"`
Severity string `json:"severity,omitempty"`
TemplateCoverage string `json:"template_coverage,omitempty"`
Vendor string `json:"vendor,omitempty"`
VulnerabilityImpact []string `json:"vulnerability_impact,omitempty"`
VulnerabilityType string `json:"vulnerability_type,omitempty"`
Weaknesses []*Weakness `json:"weaknesses,omitempty"`
// NucleiTemplate fields (flattened)
// TemplateSourceMeta
Category string `json:"category,omitempty"`
IntegrationID string `json:"integration_id,omitempty"`
IntegrationType string `json:"integration_type,omitempty"`
PullRequest string `json:"pull_request,omitempty"`
Ref string `json:"ref,omitempty"`
ReleaseTag string `json:"release_tag,omitempty"`
Score int `json:"score,omitempty"`
TemplateType string `json:"template_type,omitempty"`
// TemplateStatus
IsDraft bool `json:"is_draft,omitempty"`
IsEarly bool `json:"is_early,omitempty"`
IsGithub bool `json:"is_github,omitempty"`
IsNew bool `json:"is_new,omitempty"`
IsPdresearch bool `json:"is_pdresearch,omitempty"`
IsPdteam bool `json:"is_pdteam,omitempty"`
IsPdtemplate bool `json:"is_pdtemplate,omitempty"`
// TemplateFileMeta
Dir string `json:"dir,omitempty"`
Filename string `json:"filename,omitempty"`
URI string `json:"uri,omitempty"`
// TemplateContent
Author []string `json:"author,omitempty"`
Digest string `json:"digest,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Raw string `json:"raw,omitempty" yaml:"nuclei_template,omitempty"`
Tags []string `json:"tags,omitempty"`
Type string `json:"type,omitempty"`
// TemplateSharingMetadata
Organizations []string `json:"organizations,omitempty"`
OriginTemplateID string `json:"origin_template_id,omitempty"`
TTL string `json:"ttl,omitempty"`
TTLFrom *time.Time `json:"ttl_from,omitempty"`
Users []int `json:"users,omitempty"`
// NucleiTemplate extra fields
AIMeta *AIMeta `json:"ai_meta,omitempty"`
Classification *Classification `json:"classification,omitempty"`
ID string `json:"id,omitempty"`
UserID int `json:"user_id,omitempty"`
// Vulnerability extra fields
AffectedProducts []*ProductInfo `json:"affected_products,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
DocID string `json:"doc_id,omitempty"`
DocType string `json:"doc_type,omitempty"`
Exposure *VulnExposure `json:"exposure,omitempty"`
H1 *H1Stats `json:"h1,omitempty"`
NTPS int `json:"ntps,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
Vulnerability represents a vulnerability object returned by the API. This struct is a flat composition of all fields from the OpenAPI Vulnerability schema. All fields have omitempty. No struct embedding is used.
type VulnerabilityFilter ¶
type VulnerabilityFilter struct {
CanSort bool `json:"can_sort"`
DataType string `json:"data_type"`
Description string `json:"description"`
Examples []string `json:"examples"`
FacetPossible bool `json:"facet_possible"`
Field string `json:"field"`
SearchAnalyzer string `json:"search_analyzer"`
EnumValues []string `json:"enum_values"`
}
VulnerabilityFilter describes a filter field for vulnerabilities.
type VulnerabilityResponse ¶
type VulnerabilityResponse struct {
Data *Vulnerability `json:"data"`
}
VulnerabilityResponse represents the response from /v2/vulnerability/{id}.