Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

VulDB API – Java Examples

Language: Java License: GPL-3.0 VulDB API

Java example code for accessing the VulDB API and integrating vulnerability intelligence into applications, security tools and automated workflows.

VulDB is a vulnerability management and cyber threat intelligence platform providing information about publicly disclosed vulnerabilities, affected products, risk assessments, exploitation and countermeasures.

This repository demonstrates how to authenticate, retrieve vulnerability records and process the API response using the Java standard library. It is intended as a lightweight starting point for custom integrations rather than a complete API client or SDK.

Table of Contents

Features

  • Retrieve recently published vulnerability entries.
  • Look up a vulnerability by its VulDB entry ID.
  • Search for a CVE identifier.
  • Authenticate using a personal API key in an HTTP header.
  • Send HTTPS POST requests and print the raw response to the console.
  • Handle HTTP failures and Java exceptions.
  • Use the Java standard library without external dependencies or a build framework.

Repository Structure

File Description
VulDBApiDemo.java Standalone Java example for querying the VulDB API.
README.md Repository documentation and usage instructions.
LICENSE GNU General Public License v3.0.
.gitattributes Git file attribute configuration.

Requirements

  • Java Development Kit (JDK) 8 or newer is recommended; java and javac must be available on your system.
  • A VulDB account with a valid personal API key and sufficient API credits.
  • Internet access to vuldb.com via HTTPS (TCP port 443).
  • Git (optional, for cloning the repository).

The example uses HttpsURLConnection and standard Java I/O classes. Maven, Gradle and third-party HTTP or JSON libraries are not required to run the demonstration.

Getting Started

1. Clone the Repository

git clone https://github.com/vuldb/vuldb-api-java-examples.git
cd vuldb-api-java-examples

Alternatively, download the repository as a ZIP archive from GitHub.

2. Obtain and Configure Your API Key

Sign in to VulDB and retrieve your personal API key from the API history page.

Open VulDBApiDemo.java and replace the placeholder with your API key for local testing:

String personalApiKey = "YOUR_API-KEY_HERE";

Warning

Never commit a real API key to version control or share it in logs, screenshots or issue reports. For automated integrations, load credentials from an environment variable or a secret management system instead.

For example, replace the declaration above with:

String personalApiKey = System.getenv("VULDB_API_KEY");
if (personalApiKey == null || personalApiKey.trim().isEmpty()) {
    throw new IllegalStateException("VULDB_API_KEY is not configured");
}

Set the environment variable in your runtime environment before starting the application.

3. Correct the Detail Parameter

Important

The current example appends the value of details without its parameter name when constructing the POST body. As a result, it produces a string such as recent=5&0 instead of recent=5&details=0. To make the configured detail level effective, replace the request-body construction block with the following:

String requestBody;
if (id == null && cve == null) {
    requestBody = "recent=" + recent + "&details=" + details;
} else if (cve != null) {
    requestBody = "search=" + cve + "&details=" + details;
} else {
    requestBody = "id=" + id + "&details=" + details;
}

It is also recommended to explicitly declare the form content type before opening the output stream:

conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

4. Compile and Run

javac VulDBApiDemo.java
java VulDBApiDemo

The program sends a request and writes the response to standard output. By default, it requests five recent entries. No command-line arguments are implemented; change the variables in the source file and recompile to select a different query.

Configuration

The following variables are defined in VulDBApiDemo.java:

Variable Default Description
personalApiKey "YOUR_API-KEY_HERE" Personal API authentication key.
userAgent "VulDB API Advanced Java Demo Agent" HTTP user-agent identifying the client.
recent "5" Number of recent entries to retrieve.
details "0" 0 for basic information, 1 for extended information. Requires the correction above.
id null VulDB entry ID, supplied as a string.
cve null CVE identifier to look up.

The query type is selected in the source code. A non-null cve takes precedence over id; if both are null, the recent-entry query is used. Configure only one lookup mode at a time.

Usage Examples

Change the following four variables in the Java source file for the desired query, then recompile and run the program. The request bodies below assume the detail-parameter correction has been applied.

Retrieve Recent Vulnerabilities

String recent = "5";
String details = "0";
String id = null;
String cve = null;

POST body:

recent=5&details=0

Retrieve a Vulnerability by VulDB ID

String recent = "5";
String details = "0";
String id = "67685";
String cve = null;

POST body:

id=67685&details=0

Example entry: VulDB 67685.

Search for a CVE Identifier

String recent = "5";
String details = "0";
String id = null;
String cve = "CVE-2014-6271";

POST body:

search=CVE-2014-6271&details=0

Retrieve Extended Vulnerability Details

String recent = "5";
String details = "1";
String id = "67685";
String cve = null;

POST body:

id=67685&details=1

Extended data availability depends on the account and subscription. Detailed queries may consume more API credits.

Save the API Response to a File

java VulDBApiDemo > response.json

This redirects standard output to a file. Verify the response before treating it as JSON, since the example also prints HTTP failure messages to standard output.

API Request and Response

Request Overview

Property Value
Endpoint used by the example https://vuldb.com/api
Endpoint listed in the API documentation https://vuldb.com/?api
HTTP method POST
Authentication header X-VulDB-ApiKey
Client identification User-Agent
Recommended content type application/x-www-form-urlencoded
Default response format JSON

The Java program opens an HTTPS connection, configures request headers, writes the form body in UTF-8, checks the HTTP status and prints the response body when the HTTP status is 200.

Response Structure

A successful JSON response contains the following sections:

Section Description
response Metadata, including API version, status, item count and credit usage.
request Information about the query processed by the API.
result Matching vulnerability records.

The example prints the response without parsing it. To integrate the returned data into another Java application, add a JSON parser such as Jackson or Gson and process the result array. These libraries are not included in the repository.

Note

An HTTP 200 response does not necessarily indicate a successful API operation. Production clients should additionally inspect response.status and any error, warning or notification fields.

Troubleshooting

API status / symptom Suggested action
204 No matching entries; verify the query.
400 Check request parameter names and values.
401 Verify the API key and account access.
402 Review subscription entitlements.
403 Check remaining API credits and access restrictions.
405 Verify that the request type is supported.
HTTP 429 Reduce request frequency and respect the temporary restriction.
IOException Verify network connectivity, proxy settings and TLS trust configuration.
javac not found Install a JDK and configure the system PATH.
Extended details missing Check the request-body correction and account entitlements.

API status codes are distinct from HTTP status codes. Review the API documentation for the complete status reference.

Use the API history page to investigate requests and responses. If a request is not listed, check local connectivity, authentication and request construction; not every rejected request is recorded.

Integration Best Practices

For production deployments, extend the demonstration to meet your operational requirements:

  • Store API credentials securely outside the Java source code.
  • Set connection and read timeouts, and close resources reliably.
  • Preserve HTTPS certificate validation.
  • URL-encode individual form parameter values when accepting arbitrary input.
  • Parse JSON and validate both HTTP and API status codes.
  • Handle empty responses and unexpected or missing fields.
  • Monitor response.consumption and response.remaining to track API credit usage.
  • Respect the documented request frequency guidance (at most 30 requests per minute is recommended); use controlled retries and backoff for temporary failures.
  • Consider adding version=3 to the request body when a stable major API version is required.
  • Avoid unnecessary repeated queries and review the applicable data usage terms before storing or redistributing results.

These are recommendations for extending the example; they are not all implemented by the current source code.

Resources

Resource Link
VulDB vuldb.com
API Documentation vuldb.com/kb/api
API Key and Request History vuldb.com/?my.apihistory
Account Registration vuldb.com/?signup
Official GitHub Organization github.com/vuldb
Additional API Client Examples Python, PHP, PowerShell, Go

Contributing

Bug reports, suggestions and improvements to the example are welcome. Use the GitHub issue tracker or submit a pull request. Remove credentials and other sensitive information from all submissions.

License

The example source code is distributed under the GNU General Public License v3.0 (GPL-3.0). See the LICENSE file for the full license text.

Vulnerability intelligence retrieved through the API is subject to the applicable VulDB Terms of Use. The source code license does not grant independent rights to redistribute API data.

Support

For questions about the VulDB API, API credits, licensing or commercial integrations, contact support@vuldb.com.

For issues specific to the Java demonstration, use the GitHub issue tracker.