From 76c9e3175bc88e4520494f160cc90c1d6231fb82 Mon Sep 17 00:00:00 2001 From: Kieran Smith Date: Wed, 31 Jan 2024 19:21:53 +0000 Subject: [PATCH] Remove IAM identifiers for non-credential resources in the aws-access-token rule (#1307) * Remove IAM identifiers for non-credential resources Only detects: AWS STS service bearer token Context-specific credential Access key Temporary (AWS STS) access key IDs use this prefix, but are unique only in combination with the secret access key and the session token. * Update gitleaks.toml * Update testdata * Update tests --- cmd/generate/config/rules/aws.go | 10 +++------- config/config_test.go | 8 ++++---- config/gitleaks.toml | 4 ++-- testdata/config/allow_aws_re.toml | 2 +- testdata/config/allow_commit.toml | 2 +- testdata/config/allow_global_aws_re.toml | 2 +- testdata/config/allow_path.toml | 2 +- testdata/config/extend_1.toml | 2 +- testdata/config/simple.toml | 2 +- testdata/expected/report/sarif_simple.sarif | 2 +- 10 files changed, 16 insertions(+), 20 deletions(-) diff --git a/cmd/generate/config/rules/aws.go b/cmd/generate/config/rules/aws.go index 8ca02106..1536861d 100644 --- a/cmd/generate/config/rules/aws.go +++ b/cmd/generate/config/rules/aws.go @@ -12,16 +12,12 @@ func AWS() *config.Rule { Description: "Identified a pattern that may indicate AWS credentials, risking unauthorized cloud resource access and data breaches on AWS platforms.", RuleID: "aws-access-token", Regex: regexp.MustCompile( - "(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}"), + "(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}"), Keywords: []string{ "AKIA", - "AGPA", - "AIDA", - "AROA", - "AIPA", - "ANPA", - "ANVA", "ASIA", + "ABIA", + "ACCA", }, } diff --git a/config/config_test.go b/config/config_test.go index 094c0b49..60d42e3c 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -23,7 +23,7 @@ func TestTranslate(t *testing.T) { cfg: Config{ Rules: map[string]Rule{"aws-access-key": { Description: "AWS Access Key", - Regex: regexp.MustCompile("(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}"), + Regex: regexp.MustCompile("(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}"), Tags: []string{"key", "AWS"}, Keywords: []string{}, RuleID: "aws-access-key", @@ -41,7 +41,7 @@ func TestTranslate(t *testing.T) { cfg: Config{ Rules: map[string]Rule{"aws-access-key": { Description: "AWS Access Key", - Regex: regexp.MustCompile("(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}"), + Regex: regexp.MustCompile("(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}"), Tags: []string{"key", "AWS"}, Keywords: []string{}, RuleID: "aws-access-key", @@ -57,7 +57,7 @@ func TestTranslate(t *testing.T) { cfg: Config{ Rules: map[string]Rule{"aws-access-key": { Description: "AWS Access Key", - Regex: regexp.MustCompile("(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}"), + Regex: regexp.MustCompile("(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}"), Tags: []string{"key", "AWS"}, Keywords: []string{}, RuleID: "aws-access-key", @@ -97,7 +97,7 @@ func TestTranslate(t *testing.T) { Rules: map[string]Rule{ "aws-access-key": { Description: "AWS Access Key", - Regex: regexp.MustCompile("(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}"), + Regex: regexp.MustCompile("(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}"), Tags: []string{"key", "AWS"}, Keywords: []string{}, RuleID: "aws-access-key", diff --git a/config/gitleaks.toml b/config/gitleaks.toml index 4ed9423a..4d8058a0 100644 --- a/config/gitleaks.toml +++ b/config/gitleaks.toml @@ -124,9 +124,9 @@ keywords = [ [[rules]] id = "aws-access-token" description = "Identified a pattern that may indicate AWS credentials, risking unauthorized cloud resource access and data breaches on AWS platforms." -regex = '''(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' +regex = '''(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}''' keywords = [ - "akia","agpa","aida","aroa","aipa","anpa","anva","asia", + "akia","asia","abia","acca", ] [[rules]] diff --git a/testdata/config/allow_aws_re.toml b/testdata/config/allow_aws_re.toml index 432ea585..d5afba9a 100644 --- a/testdata/config/allow_aws_re.toml +++ b/testdata/config/allow_aws_re.toml @@ -3,7 +3,7 @@ title = "simple config with allowlist for aws" [[rules]] description = "AWS Access Key" id = "aws-access-key" - regex = '''(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' + regex = '''(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}''' tags = ["key", "AWS"] [rules.allowlist] regexes = ['''AKIALALEMEL33243OLIA'''] diff --git a/testdata/config/allow_commit.toml b/testdata/config/allow_commit.toml index a35e070b..6b421121 100644 --- a/testdata/config/allow_commit.toml +++ b/testdata/config/allow_commit.toml @@ -3,7 +3,7 @@ title = "simple config with allowlist for a specific commit" [[rules]] description = "AWS Access Key" id = "aws-access-key" - regex = '''(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' + regex = '''(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}''' tags = ["key", "AWS"] [rules.allowlist] commits = ['''allowthiscommit'''] diff --git a/testdata/config/allow_global_aws_re.toml b/testdata/config/allow_global_aws_re.toml index 8c4e552e..f595ce61 100644 --- a/testdata/config/allow_global_aws_re.toml +++ b/testdata/config/allow_global_aws_re.toml @@ -1,7 +1,7 @@ [[rules]] description = "AWS Access Key" id = "aws-access-key" - regex = '''(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' + regex = '''(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}''' tags = ["key", "AWS"] [allowlist] diff --git a/testdata/config/allow_path.toml b/testdata/config/allow_path.toml index 20337e5a..ebdb0ffa 100644 --- a/testdata/config/allow_path.toml +++ b/testdata/config/allow_path.toml @@ -3,7 +3,7 @@ title = "simple config with allowlist for .go files" [[rules]] description = "AWS Access Key" id = "aws-access-key" - regex = '''(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' + regex = '''(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}''' tags = ["key", "AWS"] [rules.allowlist] paths = ['''.go'''] diff --git a/testdata/config/extend_1.toml b/testdata/config/extend_1.toml index d393ed53..6a275c48 100644 --- a/testdata/config/extend_1.toml +++ b/testdata/config/extend_1.toml @@ -6,5 +6,5 @@ path="../testdata/config/extend_2.toml" [[rules]] description = "AWS Access Key" id = "aws-access-key" - regex = '''(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' + regex = '''(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}''' tags = ["key", "AWS"] diff --git a/testdata/config/simple.toml b/testdata/config/simple.toml index 700c791a..44c7d138 100644 --- a/testdata/config/simple.toml +++ b/testdata/config/simple.toml @@ -4,7 +4,7 @@ title = "gitleaks config" [[rules]] description = "AWS Access Key" id = "aws-access-key" - regex = '''(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' + regex = '''(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}''' tags = ["key", "AWS"] [[rules]] diff --git a/testdata/expected/report/sarif_simple.sarif b/testdata/expected/report/sarif_simple.sarif index 18d67c21..d71cfe53 100644 --- a/testdata/expected/report/sarif_simple.sarif +++ b/testdata/expected/report/sarif_simple.sarif @@ -13,7 +13,7 @@ "id": "aws-access-key", "name": "AWS Access Key", "shortDescription": { - "text": "(?:A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}" + "text": "(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}" } }, {