Skip to content

Commit 0a60e46

Browse files
authored
change: return invalid credentials errors on custom nginx error codes for incorrect client cert (#96)
This improves the user feedback in some cases when supplying invalid client certificates. However this covers only a subset of possible server behaviors on invalid client certificates, but those are the only cases which can be clearly attributed to invalid/missing client certs. Some common server responses from CSAF Provider on invalid or missing client certificate: - http status 400 (bad request): https://docs.apigee.com/api-platform/troubleshoot/runtime/400-ssl-certificate-error - custom NGINX http error codes 495 or 496: https://nginx.org/en/docs/http/ngx_http_ssl_module.html#errors *(now covered)* - termination of connection (transport level error): https://cloud.google.com/load-balancing/docs/mtls ## Why Better error feedback. ## References VTI-659
1 parent a200fb1 commit 0a60e46

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

cmd/csaf_downloader/downloader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"golang.org/x/time/rate"
3636

3737
"github.com/gocsaf/csaf/v3/csaf"
38+
"github.com/gocsaf/csaf/v3/internal/httpext"
3839
"github.com/gocsaf/csaf/v3/internal/misc"
3940
"github.com/gocsaf/csaf/v3/pkg/errs"
4041
csafErrs "github.com/gocsaf/csaf/v3/pkg/errs"
@@ -487,7 +488,7 @@ func (dc *downloadContext) downloadAdvisory(
487488

488489
if resp.StatusCode != http.StatusOK {
489490
switch {
490-
case resp.StatusCode == http.StatusUnauthorized:
491+
case resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == httpext.StatusNGINXInvalidClientCert || resp.StatusCode == httpext.StatusNGINXNoClientCert:
491492
errorCh <- csafErrs.ErrInvalidCredentials{Message: fmt.Sprintf("invalid credentials to retrieve CSAF document %s at URL %s: %s", filename, file.URL(), resp.Status)}
492493
case resp.StatusCode == http.StatusForbidden:
493494
// if we have access to the feed containing the document, we also must have access to itself, otherwise this indicates a problem with the provider

csaf/advisories.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"strings"
2020
"time"
2121

22+
"github.com/gocsaf/csaf/v3/internal/httpext"
2223
"github.com/gocsaf/csaf/v3/internal/misc"
2324
"github.com/gocsaf/csaf/v3/pkg/errs"
2425
"github.com/gocsaf/csaf/v3/util"
@@ -232,7 +233,7 @@ func (afp *AdvisoryFileProcessor) loadChanges(
232233

233234
if resp.StatusCode != http.StatusOK {
234235
switch { // we don't expect 401 and 403, as directory based feeds are supposed to be public, but just to be on the safe side
235-
case resp.StatusCode == http.StatusUnauthorized:
236+
case resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == httpext.StatusNGINXInvalidClientCert || resp.StatusCode == httpext.StatusNGINXNoClientCert:
236237
return nil, errs.ErrInvalidCredentials{Message: fmt.Sprintf("invalid credentials for accessing %s: %s", changesURL, resp.Status)}
237238
case resp.StatusCode == http.StatusForbidden:
238239
return []AdvisoryFile{}, nil // user has insufficient permissions to access feed, no error

internal/httpext/status_codes.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SPDX-FileCopyrightText: 2025 Greenbone AG <https://greenbone.net>
2+
//
3+
// SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
package httpext
6+
7+
const (
8+
// non standard status code used by NGINX: https://nginx.org/en/docs/http/ngx_http_ssl_module.html#errors
9+
StatusNGINXInvalidClientCert = 495
10+
StatusNGINXNoClientCert = 496
11+
)

0 commit comments

Comments
 (0)