Skip to content

Commit ffe8d87

Browse files
feat: change 2ms version to v5 and other small fixes (#364)
<!-- Thanks for contributing to 2ms by offering a pull request. --> Closes # **Proposed Changes** Updated version to v5. Updated README with a better explanation of entropy Changed jwt rule name to Jwt, now consistent with all other rules Added test for rule naming convention <!-- 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 fd2c16d commit ffe8d87

58 files changed

Lines changed: 205 additions & 177 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.2ms.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3018,4 +3018,14 @@ ignore-result:
30183018
- e6cb4b56f380f519250ef0bd150327710d49f220 # secret found in ruleids.go
30193019
- edb22f489a7846d8a39074541c92d27e3a88c123 # unit test from engine_test.go
30203020
- fe01911702da491dde97b22544ea2fd7027698a4 # unit test from engine_test.go
3021-
- 5ad4e2c9342c26b419d89ce606af840b222ddc29 # FP
3021+
- 5ad4e2c9342c26b419d89ce606af840b222ddc29 # FP
3022+
- 30fe0105a11a47e0827f1e24abcb68ba5d226000 # unit test from engine_test.go
3023+
- 5cef27dfd6ea6fab0b6aa0c3d6917c5bcdb54d8a # unit test from engine_test.go
3024+
- 62be1ddd8021f334f3a61daf8bfcc8324c0d3c62 # unit test from engine_test.go
3025+
- e8754bbeeb7c9b532bff5df09b18a44f4886e3e3 # unit test from engine_test.go
3026+
- 9b801040827c63c43e1412150afd1cc8da46b6e5 # unit test from engine_test.go
3027+
- 375f259080819eeaf745f3dc52fc27a6fe1321ff # unit test from engine_test.go
3028+
- 5c764e8a91fe4cc22c0080c32dd3ccba4ad63e20 # unit test from engine_test.go
3029+
- 71c523a79d530ca7b0aa5038c1d1425f26c9bde1 # unit test from engine_test.go
3030+
- a439ca168c536084477f2ae6379b4b480e3c696d # unit test from engine_test.go
3031+
- b3ba72354ad0d897ef3205ae6e3c51236da12489 # unit test from engine_test.go

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,14 @@ Other fields are optional and can be seen in the example bellow of a file with a
354354
```yaml
355355
- ruleId: 01ab7659-d25a-4a1c-9f98-dee9d0cf2e70 # REQUIRED: unique id, must match default rule id to override that default rule. Rule ids can be used as values in --rule and --ignore-rule flags
356356
ruleName: Custom-Api-Key # should be human-readable name. If left empty for new rule, ruleName will take the value of ruleId. If left empty for override, default rule name will be considered. Rule names can be used as values in --rule and --ignore-rule flags
357-
description: Custom rule
358-
regex: (?i)\b\w*secret\w*\b\s*:?=\s*["']?([A-Za-z0-9/_+=-]{8,150})["']? # REQUIRED: golang regular expression used to find secrets. If capture group is present in regex, it used to find the secret, otherwise whole regex is used. which group is considered the secret can be defined with secretGroup
357+
description: Custom rule
358+
regex: (?i)\b\w*secret\w*\b\s*:?=\s*["']?([A-Za-z0-9/_+=-]{8,150})["']? # REQUIRED: golang regular expression used to find secrets. For regexes, if enclosed in "", make sure to escape backslashes (\\, \\b, etc.). If capture group is present in regex, it's used to find the secret, otherwise whole regex is used. Which group is considered the secret can be defined with secretGroup
359359
keywords: # Keywords are used for pre-regex check filtering. Rules that contain keywords will perform a quick string compare check to make sure the keyword(s) are in the content being scanned.
360360
- access
361361
- api
362-
entropy: 3.5 # shannon entropy, measures how random a string is. The value will be higher the more random a string is. Default rules that use entropy have values between 2.0 and 4.5. Leave empty to consider matches regardless of entropy
362+
entropy: 3.5 # minimum shannon entropy, which measures how random a string is. The more unique characters a string has, the higher the entropy. The value of entropy will tend to become log2(unique chars), so long as all unique are equally present in the string ('abcd' string has entropy of log2(4)=2, but so does 'aabbccdd'). To test entropy values, use https://textcompare.io/shannon-entropy-calculator. Default rules that use entropy have values between 2.0 and 4.5, though these minimums can sometimes be 1-2 lower than the entropy of a true positive. Leave entropy empty to consider matches regardless of entropy
363363
secretGroup: 1 # defines which capture group of regex match is considered the secret. Is also used as the group that will have its entropy checked if `entropy` is set. Can be left empty, in which case the first capture group to match will be considered the secret
364-
path: (?i)\.(?:tf|hcl)$ # regex to limit the rule to specific file paths. For example, only .tf and .hcl files
364+
path: "(?i)\\.(?:tf|hcl)$" # regex to limit the rule to specific file paths, for example, only .tf and .hcl files. For regexes, if enclosed in "", make sure to escape backslashes (\\, \\b, etc.)
365365
severity: High # severity, can only be one of [Critical, High, Medium, Low, Info]
366366
tags: # identifiers for the rule, tags can be used as values of --rule and --ignore-rule flags
367367
- api-key
@@ -371,8 +371,8 @@ Other fields are optional and can be seen in the example bellow of a file with a
371371
deprecated: false # if true, the rule will not be used in the scan, regardless of --rule flag
372372
allowLists: # allowed values to ignore if matched
373373
- description: Allowlist for Custom Rule
374-
matchCondition: OR # determines whether all criteria in the allowList must match. Can be AND or OR. Defaults to OR if not specified
375-
regexTarget: match - # determines whether the regexes in allowList are tested against the rule.Regex match or the full line being scanned. Can be 'match' or 'line'. Defaults to 'match' if not specified
374+
matchCondition: OR # Can be AND or OR. determines whether all criteria in the allowList must match. Defaults to OR if not specified
375+
regexTarget: match - # Can be match or line. Determines whether the regexes in allowList are tested against the rule.Regex match or the full line being scanned. Defaults to "match" if not specified
376376
regexes: # allowed regex patterns
377377
- (?i)(?:access(?:ibility|or)|access[_.-]?id|random[_.-]?access|api[_.-]?(?:id|name|version)|rapid|capital|[a-z0-9-]*?api[a-z0-9-]*?:jar:|author|X-MS-Exchange-Organization-Auth|Authentication-Results|(?:credentials?[_.-]?id|withCredentials)|(?:25[0-5]|2[0-4]\d|1?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}|(?:bucket|foreign|hot|idx|natural|primary|pub(?:lic)?|schema|sequence)[_.-]?key|(?:turkey)|key[_.-]?(?:alias|board|code|frame|id|length|mesh|name|pair|press(?:ed)?|ring|selector|signature|size|stone|storetype|word|up|down|left|right)|KeyVault(?:[A-Za-z]*?(?:Administrator|Reader|Contributor|Owner|Operator|User|Officer))\s*[:=]\s*['"]?[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}['"]?|key[_.-]?vault[_.-]?(?:id|name)|keyVaultToStoreSecrets|key(?:store|tab)[_.-]?(?:file|path)|issuerkeyhash|(?-i:[DdMm]onkey|[DM]ONKEY)|keying|(?:secret)[_.-]?(?:length|name|size)|UserSecretsId|(?:csrf)[_.-]?token|(?:io\.jsonwebtoken[
378378
\t]?:[

benches/process_items_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import (
1212
"sync"
1313
"testing"
1414

15-
"github.com/checkmarx/2ms/v4/engine"
16-
"github.com/checkmarx/2ms/v4/internal/workerpool"
17-
"github.com/checkmarx/2ms/v4/lib/reporting"
18-
"github.com/checkmarx/2ms/v4/lib/secrets"
19-
"github.com/checkmarx/2ms/v4/plugins"
15+
"github.com/checkmarx/2ms/v5/engine"
16+
"github.com/checkmarx/2ms/v5/internal/workerpool"
17+
"github.com/checkmarx/2ms/v5/lib/reporting"
18+
"github.com/checkmarx/2ms/v5/lib/secrets"
19+
"github.com/checkmarx/2ms/v5/plugins"
2020
"github.com/rs/zerolog"
2121
)
2222

cmd/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"regexp"
99
"strings"
1010

11-
"github.com/checkmarx/2ms/v4/engine/rules/ruledefine"
12-
"github.com/checkmarx/2ms/v4/lib/utils"
11+
"github.com/checkmarx/2ms/v5/engine/rules/ruledefine"
12+
"github.com/checkmarx/2ms/v5/lib/utils"
1313
"github.com/rs/zerolog"
1414
"github.com/rs/zerolog/log"
1515
"github.com/spf13/cobra"

cmd/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"path/filepath"
77
"testing"
88

9-
"github.com/checkmarx/2ms/v4/engine/rules/ruledefine"
9+
"github.com/checkmarx/2ms/v5/engine/rules/ruledefine"
1010
"github.com/rs/zerolog"
1111
"github.com/rs/zerolog/log"
1212
"github.com/spf13/cobra"

cmd/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/checkmarx/2ms/v4/engine"
8-
"github.com/checkmarx/2ms/v4/lib/config"
9-
"github.com/checkmarx/2ms/v4/plugins"
7+
"github.com/checkmarx/2ms/v5/engine"
8+
"github.com/checkmarx/2ms/v5/lib/config"
9+
"github.com/checkmarx/2ms/v5/plugins"
1010
"github.com/rs/zerolog"
1111
"github.com/rs/zerolog/log"
1212
"github.com/spf13/cobra"

cmd/main_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"testing"
77
"time"
88

9-
"github.com/checkmarx/2ms/v4/engine"
10-
"github.com/checkmarx/2ms/v4/engine/rules/ruledefine"
11-
"github.com/checkmarx/2ms/v4/internal/resources"
9+
"github.com/checkmarx/2ms/v5/engine"
10+
"github.com/checkmarx/2ms/v5/engine/rules/ruledefine"
11+
"github.com/checkmarx/2ms/v5/internal/resources"
1212
"github.com/spf13/cobra"
1313
"github.com/stretchr/testify/assert"
1414
)

cmd/plugins_mock_test.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/list-of-rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Here is a complete list of all the rules that are currently implemented.
115115
| Intra42-Client-Secret | Found a Intra42 client secret, which could lead to unauthorized access to the 42School API and sensitive data. | client-secret | |
116116
| Jfrog-Api-Key | Found a JFrog API Key, posing a risk of unauthorized access to software artifact repositories and build pipelines. | api-key | |
117117
| Jfrog-Identity-Token | Discovered a JFrog Identity Token, potentially compromising access to JFrog services and sensitive software artifacts. | access-token | |
118-
| jwt | Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data. | access-token | |
118+
| Jwt | Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data. | access-token | |
119119
| Jwt-Base64 | Detected a Base64-encoded JSON Web Token, posing a risk of exposing encoded authentication and data exchange information. | access-token | |
120120
| Kraken-Access-Token | Identified a Kraken Access Token, potentially compromising cryptocurrency trading accounts and financial security. | access-token | |
121121
| Kubernetes-Secret-Yaml | Possible Kubernetes Secret detected, posing a risk of leaking credentials/tokens from your deployments | secret-key | |

engine/detect/utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"path/filepath"
77
"strings"
88

9-
"github.com/checkmarx/2ms/v4/engine/constants"
9+
"github.com/checkmarx/2ms/v5/engine/constants"
1010
"github.com/zricethezav/gitleaks/v8/cmd/scm"
1111
"github.com/zricethezav/gitleaks/v8/logging"
1212
"github.com/zricethezav/gitleaks/v8/report"
@@ -115,6 +115,7 @@ func createScmLink(remote *sources.RemoteInfo, finding *report.Finding) string {
115115
// Another way to think about what this is doing is calculating the number of bits
116116
// needed to on average encode the data. So, the higher the entropy, the more random the data, the
117117
// more bits needed to encode that data.
118+
// For a quick calculator, see https://textcompare.io/shannon-entropy-calculator
118119
func shannonEntropy(data string) (entropy float64) {
119120
if data == "" {
120121
return 0

0 commit comments

Comments
 (0)