Skip to content

Commit 5720d80

Browse files
Potential fix for code scanning alert no. 4: Database query built from user-controlled sources
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent c882c17 commit 5720d80

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

internal/presentation/handler/list_handler.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ func NewListHandler(lister abstraction.Lister) *ListHandler {
2525
// HandleList handles GET /list/:pubKey requests.
2626
func (h *ListHandler) HandleList(c echo.Context) error {
2727
pubKey := c.Param(presentation.PK)
28-
if pubKey == "" {
29-
c.Response().Header().Set(presentation.ReasonTag, "missing pubKey")
28+
if pubKey == "" || !isValidPubKey(pubKey) {
29+
c.Response().Header().Set(presentation.ReasonTag, "invalid or missing pubKey")
3030

3131
return c.NoContent(http.StatusBadRequest)
3232
}
@@ -71,3 +71,9 @@ func parseTimeQueryParam(c echo.Context, paramName string) (*time.Time, error) {
7171

7272
return &t, nil
7373
}
74+
75+
// isValidPubKey validates the pubKey to ensure it is alphanumeric and meets expected length constraints.
76+
func isValidPubKey(pubKey string) bool {
77+
const pubKeyPattern = `^[a-zA-Z0-9]{1,64}$` // Example: Adjust length as needed
78+
return regexp.MustCompile(pubKeyPattern).MatchString(pubKey)
79+
}

0 commit comments

Comments
 (0)