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
4 changes: 2 additions & 2 deletions pkg/detectors/notion/notion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ var (
client = common.SaneHttpClient()

// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
keyPat = regexp.MustCompile(`\b(secret_[A-Za-z0-9]{43})\b`)
keyPat = regexp.MustCompile(`\b((?:secret_[A-Za-z0-9]{43})|ntn_[0-9]{11}[A-Za-z0-9]{32}[A-Za-z0-9]{3})\b`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Great 😃 Could you move the new pattern to a separate V2 detector instead of merging it into the existing one? Since the API for verification is the same, we can extract the verification logic into a shared method and use it in both versions.

)

// Keywords are used for efficiently pre-filtering chunks.
// Use identifiers in the secret preferably, or the provider name.
func (s Scanner) Keywords() []string {
return []string{"notion"}
return []string{"notion", "ntn_"}
}

// FromData will find and optionally verify Notion secrets in a given set of bytes.
Expand Down
22 changes: 17 additions & 5 deletions pkg/detectors/notion/notion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
)

var (
validPattern = "secret_oPp4m4V04lEWqgLGyhCN7b8H9JLANmyE1AYl2aG3aTN"
invalidPattern = "secret_oPp4m4V04lEWqgLGyh?N7b8H9JLANmyE1AYl2aG3aTN"
keyword = "notion"
validPattern = "secret_oPp4m4V04lEWqgLGyhCN7b8H9JLANmyE1AYl2aG3aTN"
invalidPattern = "secret_oPp4m4V04lEWqgLGyh?N7b8H9JLANmyE1AYl2aG3aTN"
validPatternV2 = "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"
invalidPatternV2 = "ntn_123456789012345678901234567890123456789012345678901234567890"
keyword = "notion"
)

func TestNotion_Pattern(t *testing.T) {
Expand All @@ -26,15 +28,25 @@ func TestNotion_Pattern(t *testing.T) {
want []string
}{
{
name: "valid pattern - with keyword notion",
name: "valid legacy pattern - with keyword notion",
input: fmt.Sprintf("%s token = '%s'", keyword, validPattern),
want: []string{validPattern},
},
{
name: "invalid pattern",
name: "invalid legacy pattern",
input: fmt.Sprintf("%s = '%s'", keyword, invalidPattern),
want: []string{},
},
{
name: "valid new pattern - with ntn_ prefix",
input: fmt.Sprintf("notion api key: %s", validPatternV2),
want: []string{validPatternV2},
},
{
name: "invalid new pattern - wrong timestamp length",
input: fmt.Sprintf("notion = '%s'", invalidPatternV2),
want: []string{},
},
}

for _, test := range tests {
Expand Down
Loading