Skip to content
Changes

Reference

kong · Oct 6, 2026

What this change means

Atlas added kong to its detector catalog in this update.

pkg/detectors/kong/kong.go+109−0View file
@@ -0,0 +1,109 @@
1added: package kong
2added:
3added: import (
4added: "context"
5added: "fmt"
6added: "io"
7added: "net/http"
8added:
9added: regexp "github.com/wasilibs/go-re2"
10added:
11added: "github.com/trufflesecurity/trufflehog/v3/pkg/common"
12added: "github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
13added: "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb"
14added: )
15added:
16added: type Scanner struct {
17added: client *http.Client
18added: }
19added:
20added: // Ensure the Scanner satisfies the interface at compile time.
21added: var _ detectors.Detector = (*Scanner)(nil)
22added:
23added: const verifyURL = "https://global.api.konghq.com/v3/organizations/me"
24added:
25added: var (
26added: defaultClient = common.SaneHttpClient()
27added: keyPat = regexp.MustCompile(`\b((?:kpat_|spat_)[a-zA-Z0-9]{49})\b`)
28added: )
29added:
30added: // Keywords are used for efficiently pre-filtering chunks.
31added: // Use identifiers in the secret preferably, or the provider name.
32added: func (s Scanner) Keywords() []string {
33added: return []string{"kpat_", "spat_"}
34added: }
35added:
36added: // FromData will find and optionally verify Kong secrets in a given set of bytes.
37added: func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
38added: dataStr := string(data)
39added:
40added: uniqueMatches := make(map[string]struct{})
41added: for _, match := range keyPat.FindAllStringSubmatch(dataStr, -1) {
42added: uniqueMatches[match[1]] = struct{}{}
43added: }
44added:
45added: for match := range uniqueMatches {
46added: s1 := detectors.Result{
47added: DetectorType: detector_typepb.DetectorType_KongKonnect,
48added: Raw: []byte(match),
49added: SecretParts: map[string]string{"key": match},
50added: }
51added:
52added: if verify {
53added: client := s.client
54added: if client == nil {
55added: client = defaultClient
56added: }
57added:
58added: isVerified, extraData, verificationErr := verifyMatch(ctx, client, match)
59added: s1.Verified = isVerified
60added: s1.ExtraData = extraData
61added: s1.SetVerificationError(verificationErr, match)
62added: }
63added:
64added: results = append(results, s1)
65added: }
66added:
67added: return
68added: }
69added:
70added: func verifyMatch(ctx context.Context, client *http.Client, token string) (bool, map[string]string, error) {
71added: req, err := http.NewRequestWithContext(ctx, http.MethodGet, verifyURL, nil)
72added: if err != nil {
73added: return false, nil, err
74added: }
75added:
76added: req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
77added:
78added: res, err := client.Do(req)
79added: if err != nil {
80added: return false, nil, err
81added: }
82added: defer func() {
83added: _, _ = io.Copy(io.Discard, res.Body)
84added: _ = res.Body.Close()
85added: }()
86added:
87added: extraData := map[string]string{
88added: "rotation_guide": "https://developer.konghq.com/konnect-api/#konnect-api-authentication",
89added: }
90added:
91added: switch res.StatusCode {
92added: case http.StatusOK:
93added: // If the endpoint returns useful information, we can return it as a map.
94added: return true, extraData, nil
95added: case http.StatusUnauthorized:
96added: // The secret is determinately not verified (nothing to do)
97added: return false, nil, nil
98added: default:
99added: return false, nil, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode)
100added: }
101added: }
102added:
103added: func (s Scanner) Type() detector_typepb.DetectorType {
104added: return detector_typepb.DetectorType_KongKonnect
105added: }
106added:
107added: func (s Scanner) Description() string {
108added: return "Kong Konnect is a API and AI management platform, and Konnect tokens (like personal or system access tokens) are used to securely authenticate developers, scripts, and CI/CD pipelines to manage and automate gateway configurations programmatically"
109added: }