Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions controllers/vulndb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package controllers
import (
"fmt"
"net/url"
"strconv"
"strings"
"time"

"github.com/l3montree-dev/devguard/database/models"
"github.com/l3montree-dev/devguard/dtos"
Expand Down Expand Up @@ -150,3 +152,57 @@ func (c VulnDBController) PURLInspect(ctx shared.Context) error {
MaliciousPackage: maliciousPackage,
})
}

// returns a list of cve ids sorted by the creation date as well as the total amount of entries
// query parameter offset: offset the fetched data by the provided amount
// query parameter limit: limit the amount of entries in the data
Comment thread
Hubtrick-Git marked this conversation as resolved.
func (c VulnDBController) ListIDsByCreationDate(ctx shared.Context) error {
type listIDsRow struct {
CVEID string `gorm:"column:cve"`
CreatedAt time.Time `gorm:"column:created_at"`
}
type responseDTO struct {
Count int `json:"total"`
CVEData []listIDsRow `json:"data"`
}
Comment thread
Hubtrick-Git marked this conversation as resolved.

// use an offset to query only a part of the data
offset := 0
offsetParam := ctx.QueryParam("offset")
if offsetParam != "" {
var err error
offset, err = strconv.Atoi(offsetParam)
if err != nil {
return echo.NewHTTPError(400, "invalid offset value").WithInternal(err)
}
Comment thread
Hubtrick-Git marked this conversation as resolved.
}

var err error
results := make([]listIDsRow, 0, 1<<18)
Comment thread
Hubtrick-Git marked this conversation as resolved.

// use optional limit parameter to limit the amount of fetched data
limit := 0
limitParam := ctx.QueryParam("limit")
if limitParam != "" {
limit, err = strconv.Atoi(limitParam)
if err != nil {
return echo.NewHTTPError(400, "invalid limit value").WithInternal(err)
}
Comment thread
Hubtrick-Git marked this conversation as resolved.
Comment thread
Hubtrick-Git marked this conversation as resolved.

sql := `SELECT cve,created_at FROM cves ORDER BY created_at DESC OFFSET ? LIMIT ?;`
err = c.cveRepository.GetDB(nil).Raw(sql, offset, limit).Find(&results).Error
} else {
sql := `SELECT cve,created_at FROM cves ORDER BY created_at DESC OFFSET ?;`
err = c.cveRepository.GetDB(nil).Raw(sql, offset).Find(&results).Error
Comment thread
Hubtrick-Git marked this conversation as resolved.
}
Comment thread
Hubtrick-Git marked this conversation as resolved.
if err != nil {
return echo.NewHTTPError(500, "could not get cve ids").WithInternal(err)
}

// build the response and return it
response := responseDTO{
Count: len(results),
CVEData: results,
Comment thread
Hubtrick-Git marked this conversation as resolved.
}
return ctx.JSON(200, response)
Comment thread
Hubtrick-Git marked this conversation as resolved.
}
Comment on lines +159 to +208
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage for the new endpoint. The codebase has comprehensive test coverage for other controller endpoints (see tests/scan_integration_test.go, tests/dependency_vuln_controller_test.go, etc.). Consider adding tests that verify: 1) the endpoint returns correct data with various offset/limit combinations, 2) proper error handling for invalid parameters, 3) correct sorting by creation date, and 4) handling of empty result sets.

Copilot uses AI. Check for mistakes.
1 change: 1 addition & 0 deletions router/vulndb_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func NewVulnDBRouter(apiV1Router APIV1Router, vulndbController *controllers.Vuln
cveRouter.GET("/", vulndbController.ListPaged)
cveRouter.GET("/:cveID/", vulndbController.Read)
cveRouter.GET("/purl-inspect/:purl", vulndbController.PURLInspect)
cveRouter.GET("/list-ids-by-creation-date/", vulndbController.ListIDsByCreationDate)
return VulnDBRouter{
Group: cveRouter,
}
Expand Down
Loading