Skip to content
Open
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
2 changes: 1 addition & 1 deletion pkg/fanal/secret/builtin-rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ var builtinRules = []Rule{
Category: CategoryMailchimp,
Title: "Mailchimp API key",
Severity: "MEDIUM",
Regex: MustCompile(`(?i)(?P<key>mailchimp[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"](?P<secret>[a-f0-9]{32}-us20)['\"]`),
Regex: MustCompile(`(?i)(?P<key>mailchimp[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"](?P<secret>[a-f0-9]{32}-us[0-9]{1,2})['\"]`),
SecretGroupName: "secret",
Keywords: []string{"mailchimp"},
},
Expand Down
29 changes: 29 additions & 0 deletions pkg/fanal/secret/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,35 @@ func TestSecretScanner(t *testing.T) {
}
}

// Mailchimp API keys end in "-us<N>", where N is the account's datacenter. The
Comment thread
nikpivkin marked this conversation as resolved.
Resolved
// keys are assembled at runtime so no complete key-shaped string is committed.
func TestSecretScannerMailchimpDatacenters(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Other rules are tested as cases in TestSecretScanner with a fixture in testdata/. This one could be a case there too, with testdata/mailchimp-api-key.txt. If push protection blocks the fixture, you can bypass it with the "It's used in tests" reason.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I tried moving it into TestSecretScanner with testdata/mailchimp-api-key.txt, but push protection kept rejecting the fixture even after allowing both keys with the "It's used in tests" reason. So I've kept it as a separate test that assembles the keys at runtime (the other two points are done in 4c97990). If you'd prefer the fixture form, feel free to move it over, or let me know and I'll try again.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The bypass works for fixtures. Please try once more. Open the unblock URLs from the error, choose "It's used in tests", then run the same git push again without changing the commit.

const hexPart = "3f9c2a7d1b8e4c6f0a5d9e2b7c1f4a8d"
content := strings.Join([]string{
`MAILCHIMP_API_KEY: "` + hexPart + "-us" + "6" + `"`,
Comment thread
nikpivkin marked this conversation as resolved.
Resolved
`MAILCHIMP_API_KEY: "` + hexPart + "-us" + "20" + `"`,
// A bare 32-hex list ID and a datacenter name on their own are not keys.
`MAILCHIMP_LIST_ID: "` + hexPart + `"`,
`MAILCHIMP_SERVER: "us6"`,
}, "\n")

c, err := secret.ParseConfig(filepath.Join("testdata", "config.yaml"))
require.NoError(t, err)

s := secret.NewScanner(c)
got := s.Scan(secret.ScanArgs{
FilePath: "mailchimp.env",
Content: strings.NewReader(content),
})

var lines []int
for _, f := range got.Findings {
assert.Equal(t, "mailchimp-api-key", f.RuleID)
lines = append(lines, f.StartLine)
}
assert.Equal(t, []int{1, 2}, lines, "keys for us6 and us20 are found; the list ID and server name are not")
}

func TestSecretScannerWithStreaming(t *testing.T) {
tests := []struct {
name string
Expand Down