Skip to content
Changes

Reference

duo · Nov 25, 2026

What this change means

Source files changed in ways the catalog does not model (for example logic inside Verify). Read the diff to judge the effect.

pkg/detectors/duo/duo.go+74−61View file
@@ -6,6 +6,8 @@ import (
66 "crypto/sha1"
77 "encoding/base64"
88 "encoding/hex"
9added: "encoding/json"
10added: "errors"
911 "fmt"
1012 "io"
1113 "net/http"
@@ -40,6 +42,22 @@ var (
4042 apiHost = regexp.MustCompile(`\b([a-z0-9-]{6,}\.duosecurity\.com)\b`)
4143)
4244
45added: const (
46added: adminAPIPath = "/admin/v1/info/summary" // https://duo.com/docs/adminapi#account-info
47added: authAPIPath = "/auth/v2/check" // https://duo.com/docs/authapi#check
48added:
49added: adminApplication = "Admin API"
50added: authApplication = "Auth API"
51added:
52added: duoCodeInvalidSignature = 40103
53added: duoCodeAccessForbidden = 40301
54added: )
55added:
56added: type duoReply struct {
57added: status int
58added: code int
59added: }
60added:
4361// Keywords are used for efficiently pre-filtering chunks.
4462// Use identifiers in the secret preferably, or the provider name.
4563func (s Scanner) Keywords() []string {
@@ -53,7 +71,7 @@ func (s Scanner) getClient() *http.Client {
5371 return defaultClient
5472}
5573
56removed: // FromData will find and optionally verify DeepSeek secrets in a given set of bytes.
74added: // FromData will find and optionally verify Duo secrets in a given set of bytes.
5775func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
5876 dataStr := string(data)
@@ -77,31 +95,19 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
7795 Raw: []byte(apiKey),
7896 RawV2: []byte(fmt.Sprintf("%s:%s:%s", host, apiKey, apiSecret)),
7997 ExtraData: map[string]string{
80removed: "application": "Admin API",
98added: "application": adminApplication,
8199 },
82100 SecretParts: map[string]string{
83101 "host": host,
84102 "ikey": apiKey,
85103 "skey": apiSecret,
86removed: "application": "Admin API",
104added: "application": adminApplication,
87105 },
88106 }
89107 if verify {
90removed: verified, verificationErr := VerifyAdminToken(ctx, s.getClient(), host, apiKey, apiSecret)
91removed: // we will try auth api verification if admin api verification fails without error,
92removed: // which is in the case of it returning 401 unauthorized due to invalid credentials.
93removed: if !verified && verificationErr == nil {
94removed: var authStatusCode int
95removed: verified, authStatusCode, verificationErr = VerifyAuthToken(ctx, s.getClient(), host, apiKey, apiSecret)
96removed: // The Auth API responds 403 (not 401) when ikey/skey are
97removed: // structurally valid Admin API keys, active or not. That still
98removed: // counts as verified, but the keys remain Admin API keys, so
99removed: // only relabel to Auth API when the check actually succeeded (200).
100removed: if authStatusCode != http.StatusForbidden {
101removed: s1.ExtraData["application"] = "Auth API"
102removed: s1.SecretParts["application"] = "Auth API"
103removed: }
104removed: }
108added: verified, application, verificationErr := verifyMatch(ctx, s.getClient(), host, apiKey, apiSecret)
109added: s1.ExtraData["application"] = application
110added: s1.SecretParts["application"] = application
105111 s1.SetVerificationError(verificationErr, host, apiKey, apiSecret)
106112 s1.Verified = verified
107113 }
@@ -112,49 +118,56 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
112118 return results, nil
113119}
114120
115removed: // returns verified=true if credentials are valid and belong to auth api, false if creds are invalid, and error if creds belong to auth api or for anything else (e.g., network error).
116removed: // The HTTP status code is also returned so callers can distinguish a genuine 200 from a
117removed: // 403, which the Auth API returns for structurally valid Admin API keys (active or not).
118removed: func VerifyAuthToken(
121added: // verifyMatch checks the credentials against the Admin API, then the Auth API, and
122added: // returns whether they are valid and which application they belong to.
123added: //
124added: // Only a 200 from either API proves the credentials valid, and only error code 40103
125added: // (invalid signature) from either API proves them invalid: that API recognized the
126added: // integration key and rejected the secret key. Other responses are reported as a verification error.
127added: func verifyMatch(
119128 ctx context.Context,
120129 client *http.Client,
121130 host, ikey, skey string,
122removed: ) (bool, int, error) {
123removed: // Docs: https://duo.com/docs/authapi#check
124removed: return verifyDuoRequest(
125removed: ctx,
126removed: client,
127removed: host,
128removed: ikey,
129removed: skey,
130removed: "/auth/v2/check",
131removed: )
132removed: }
131added: ) (bool, string, error) {
132added: admin, adminErr := duoRequest(ctx, client, host, ikey, skey, adminAPIPath)
133added: if adminErr == nil && admin.status == http.StatusOK {
134added: return true, adminApplication, nil
135added: }
133136
134removed: // returns 401 unauthorized if credentials are invalid, 200 OK if valid, and error for anything else
135removed: func VerifyAdminToken(
136removed: ctx context.Context,
137removed: client *http.Client,
138removed: host, ikey, skey string,
139removed: ) (bool, error) {
140removed: // Docs: https://duo.com/docs/adminapi#account-info
141removed: verified, _, err := verifyDuoRequest(
142removed: ctx,
143removed: client,
144removed: host,
145removed: ikey,
146removed: skey,
147removed: "/admin/v1/info/summary",
137added: auth, authErr := duoRequest(ctx, client, host, ikey, skey, authAPIPath)
138added: if authErr == nil && auth.status == http.StatusOK {
139added: return true, authApplication, nil
140added: }
141added:
142added: if (adminErr == nil && admin.code == duoCodeInvalidSignature) ||
143added: (authErr == nil && auth.code == duoCodeInvalidSignature) {
144added: return false, adminApplication, nil
145added: }
146added: if adminErr != nil {
147added: return false, adminApplication, adminErr
148added: }
149added: if authErr != nil {
150added: return false, adminApplication, authErr
151added: }
152added:
153added: msg := fmt.Sprintf(
154added: "indeterminate Duo verification: admin API returned HTTP %d (code %d), auth API returned HTTP %d (code %d)",
155added: admin.status, admin.code, auth.status, auth.code,
148156 )
149removed: return verified, err
157added: if admin.code == duoCodeAccessForbidden {
158added: msg += `; an Admin API integration needs the "Grant read information" permission to be verified`
159added: }
160added: return false, adminApplication, errors.New(msg)
150161}
151162
152removed: func verifyDuoRequest(
163added: // duoRequest sends a signed GET request to the given Duo API path and returns the HTTP
164added: // status and Duo error code without interpreting them.
165added: func duoRequest(
153166 ctx context.Context,
154167 client *http.Client,
155168 host, ikey, skey string,
156169 path string,
157removed: ) (bool, int, error) {
170added: ) (duoReply, error) {
158171
159172 timestamp := time.Now().UTC().Format(http.TimeFormat)
@@ -185,7 +198,7 @@ func verifyDuoRequest(
185198 nil,
186199 )
187200 if err != nil {
188removed: return false, 0, err
201added: return duoReply{}, err
189202 }
190203
191204 req.Header.Set("Authorization", "Basic "+auth)
@@ -193,23 +206,23 @@ func verifyDuoRequest(
193206
194207 res, err := client.Do(req)
195208 if err != nil {
196removed: return false, 0, err
209added: return duoReply{}, err
197210 }
198211 defer func() {
199212 _, _ = io.Copy(io.Discard, res.Body)
200213 _ = res.Body.Close()
201214 }()
202215
203removed: switch res.StatusCode {
204removed: case http.StatusOK:
205removed: return true, res.StatusCode, nil
206removed: case http.StatusUnauthorized:
207removed: return false, res.StatusCode, nil
208removed: case http.StatusForbidden: // Auth API returns 403 if credentials are admin keys be it active or inactive
209removed: return true, res.StatusCode, nil
210removed: default:
211removed: return false, res.StatusCode, fmt.Errorf("unexpected HTTP status %d", res.StatusCode)
216added: reply := duoReply{status: res.StatusCode}
217added: if res.StatusCode != http.StatusOK {
218added: var body struct {
219added: Code int `json:"code"`
220added: }
221added: if json.NewDecoder(io.LimitReader(res.Body, 64<<10)).Decode(&body) == nil {
222added: reply.code = body.Code
223added: }
212224 }
225added: return reply, nil
213226}
214227
215228func (s Scanner) Type() detector_typepb.DetectorType {