Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: distinguish between exact and regex matches #7

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

martinohmann
Copy link
Member

This change proposes to split out the regex matching functionality into a dedicated matchRegex rule. The rationale behind this change is that, by having match support both exact and regex matching it can lead to very surprising behaviour that is not obvious to the user.

An example: with the presence of regex matching, match: foo would match foo, but it also would match foobar and barfoo. This means that it would match more trust anchors than anticipated, and that in turn can be a security issue.

To achieve true exact matching, one would need to use match: ^foo$, but that's really verbose and easy to forget.

By making match just perform plain exact string matching and have matchRegex for use cases that require more complicated matching behaviour via regular expressions the footgun above can be avoided.

This change proposes to split out the regex matching functionality into
a dedicated `matchRegex` rule. The rationale behind this change is that,
by having `match` support both exact and regex matching it can lead to
very surprising behaviour that is not obvious to the user.

An example: with the presence of regex matching, `match: foo` would
match `foo`, **but it also would match** `foobar` and `barfoo`. This
means that it would match more trust anchors than anticipated, and that
in turn can be a security issue.

To achieve true exact matching, one would need to use `match: ^foo$`,
but that's really verbose and easy to forget.

By making `match` just perform plain exact string matching and have
`matchRegex` for use cases that require more complicated matching
behaviour via regular expressions the footgun above can be avoided.
@martinohmann martinohmann marked this pull request as ready for review November 15, 2024 14:48
@martinohmann martinohmann requested a review from a team as a code owner November 15, 2024 14:48
Copy link
Contributor

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ ACTION actionlint 2 0 0.03s
✅ DOCKERFILE hadolint 1 0 0.09s
✅ GO golangci-lint yes no 21.21s
✅ GO revive 3 0 13.13s
✅ JSON jsonlint 1 0 0.58s
✅ JSON prettier 1 0 2.24s
✅ JSON v8r 1 0 1.97s
✅ MARKDOWN markdownlint 2 0 1.55s
✅ MARKDOWN markdown-link-check 2 0 2.04s
✅ MARKDOWN markdown-table-formatter 2 0 0.54s
✅ REPOSITORY checkov yes no 12.22s
✅ REPOSITORY gitleaks yes no 0.15s
✅ REPOSITORY git_diff yes no 0.02s
✅ REPOSITORY grype yes no 17.63s
✅ REPOSITORY secretlint yes no 0.66s
✅ REPOSITORY trivy yes no 8.22s
✅ REPOSITORY trivy-sbom yes no 1.51s
✅ REPOSITORY trufflehog yes no 3.81s
✅ YAML prettier 7 0 0.99s
✅ YAML v8r 7 0 10.02s
✅ YAML yamllint 7 0 1.62s

See detailed report in MegaLinter reports

MegaLinter is graciously provided by OX Security

@martinohmann martinohmann merged commit 291d8a8 into main Nov 18, 2024
2 checks passed
@martinohmann martinohmann deleted the mohmann/match-exact-regex branch November 18, 2024 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants