Skip to content

Commit e2fafb4

Browse files
fix: reverting special character support for generic rule (#380)
<!-- Thanks for contributing to 2ms by offering a pull request. --> Closes # **Proposed Changes** <!-- Please describe the big picture of your changes here. If it fixes a bug or resolves a feature request, be sure to link to that issue. --> **Checklist** - [ ] I covered my changes with tests. - [ ] I Updated the documentation that is affected by my changes: - [ ] Change in the CLI arguments - [ ] Change in the configuration file I submit this contribution under the Apache-2.0 license.
1 parent 183c8bf commit e2fafb4

5 files changed

Lines changed: 7 additions & 20 deletions

File tree

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# and "Missing User Instruction" since 2ms container is stopped after scan
44

55
# Builder image
6-
FROM checkmarx/go:1.25.7-r0-b270bc965b34b4@sha256:b270bc965b34b4ffec624413bc1f1830c58c0abb142580ca76d42116b3b06764 AS builder
6+
FROM checkmarx/go:1.26.1-r0-ce13f12ff5c411@sha256:ce13f12ff5c4114de1df95b2442911adab6c5a3ee580945176213f78c94ca0c6 AS builder
77

88
WORKDIR /app
99

@@ -20,7 +20,7 @@ COPY . .
2020
RUN GOOS=linux GOARCH=amd64 go build -buildvcs=false -ldflags="-s -w" -a -o /app/2ms .
2121

2222
# Runtime image
23-
FROM checkmarx/git:2.53.0-r0-dadf19ec31d471@sha256:dadf19ec31d4711eeace2763e89511693b36ba0ea5c9e12a763978b4b29ddba0
23+
FROM checkmarx/git:2.53.0-r0-550d658abf13b0@sha256:550d658abf13b060746bcc629daaa6eaf6ee66364e5b5fa6216eb92f5e4d0f97
2424

2525
WORKDIR /app
2626

engine/rules/ruledefine/generic_credential.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var genericCredentialRegex = generateSemiGenericRegexIncludingXml([]string{
1616
"passw(?:or)?d",
1717
"secret",
1818
"token",
19-
}, `[\w.=\-~?!:@]{10,150}|[a-z0-9][a-z0-9+/]{11,}={0,3}`, true).String()
19+
}, `[\w.=-]{10,150}|[a-z0-9][a-z0-9+/]{11,}={0,3}`, true).String()
2020

2121
func GenericCredential() *Rule {
2222
return &Rule{
@@ -42,7 +42,7 @@ func GenericCredential() *Rule {
4242
// NOTE: this is a goofy hack to get around the fact there golang's regex engine does not support positive lookaheads.
4343
// Ideally we would want to ensure the secret contains both numbers and alphabetical characters, not just alphabetical characters.
4444
Regexes: []string{
45-
regexp.MustCompile(`^[a-zA-Z_.-]+:?$`).String(),
45+
regexp.MustCompile(`^[a-zA-Z_.-]+$`).String(),
4646
},
4747
},
4848
{
@@ -60,7 +60,7 @@ func GenericCredential() *Rule {
6060
`|rapid|capital` + // common words containing "api"
6161
`|[a-z0-9-]*?api[a-z0-9-]*?:jar:` + // Maven META-INF dependencies that contain "api" in the name.
6262
// Auth
63-
`|\bauthor\b` +
63+
`|author` +
6464
`|X-MS-Exchange-Organization-Auth` + // email header
6565
`|Authentication-Results` + // email header
6666
// Credentials
@@ -94,10 +94,6 @@ func GenericCredential() *Rule {
9494
// Empty variables capturing the next line (e.g., .env files)
9595
`|(?-i:(?:[A-Z_]+=\n[A-Z_]+=|[a-z_]+=\n[a-z_]+=)(?:\n|\z))` +
9696
`|(?-i:(?:[A-Z.]+=\n[A-Z.]+=|[a-z.]+=\n[a-z.]+=)(?:\n|\z))` +
97-
// Code constant references (e.g. AnnotationWithConstants::INTEGER).
98-
`|(?-i:\w+::[A-Z][A-Z0-9_]*)` +
99-
// Any secret in valid date/datetime format (e.g. ISO 8601: 2018-04-22T10:28:49.876Z) — not a credential
100-
`|\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?` +
10197
`)`).String(),
10298
},
10399
StopWords: append(DefaultStopWords,

engine/rules/ruledefine/generic_credential_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ func TestGenericCredential(t *testing.T) {
8585
" utils.GetEnvOrDefault(\"api_token\", \"dafa7817-e246-48f3-91a7-e87653d587b8\")",
8686
// xml cases
8787
"<key>API_KEY</key>\n<string>AIzaSyATDL7Wz3Ze6BU31Yv3fVVth30Skyib29g</string>",
88-
"Authorization.ClientSecret: e55wsdasfsgs-sdsdas_2sdasjVM~ggadASaADASsad",
89-
"Authorization.ClientSecret: e55wsdasfsgs-sds::das_2sdasjVM~ggad?ASaAD!ASs@ad",
9088
},
9189
falsePositives: []string{
9290
"issuerKeyHash=npmXsmT2_C1iJZ-SD7RuL8exZ=6ucd",
@@ -98,13 +96,6 @@ func TestGenericCredential(t *testing.T) {
9896
"<key>GOOGLE_APP_ID</key>\n<string>1:407966239993:ios:0d7534f14f8cfe19</string>",
9997
"\"a_b_key\": \"x-someval-127.0.0.1\",",
10098
"KeyVaultSecretsUser: '62168719-64c5-453d-b4ef-b51d8b1ad44d'",
101-
"maxAPIResponseBytes: tc.maxAPIBytes , maxTotalScanBytes: tc.maxTotalBytes,",
102-
"SOME_KEY = AnnotationWithConstants::INTEGER",
103-
"SOME_KEY = AnnotationWithConstants::TANTO_FAZ",
104-
"AuthnInstant=2018-04-22T10:28:49.876Z",
105-
"AuthnInstant=2018-04-22T10:28:49Z",
106-
"AuthnInstant=2018-04-22T10:28:49+00:00",
107-
"PasswordStorage::SECTION_DELIMITER",
10899
},
109100
},
110101
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/checkmarx/2ms/v5
22

3-
go 1.25.7
3+
go 1.26.1
44

55
replace (
66
golang.org/x/oauth2 => golang.org/x/oauth2 v0.30.0

internal/workerpool/pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type Option func(*Config)
6060

6161
// New creates a new worker pool with the specified number of workers
6262
func New(name string, opts ...Option) Pool {
63-
ctx, cancel := context.WithCancel(context.Background())
63+
ctx, cancel := context.WithCancel(context.Background()) //nolint:gosec // G118: cancel is stored in config and called in Stop()
6464
config := &Config{
6565
workers: defaultWorkers,
6666
queueSize: defaultWorkers * 10,

0 commit comments

Comments
 (0)