Because `segment.adjustMatchIndex(matchIndex)` was above
`segment.lineEndIndex(currentRaw, matchIndex[1]-matchIndex[0])` there
were cases where it would cause an out of bounds error.
This change resolves the issue by just assuming the whole segment is a
opaque chunk of text and starts at the boundaries of the segment instead
so that the order doesn't matter as much.
The other option would have been to reorder the assignments and add
tests to account for that case, but I figured this option is less likely
to have gotchas when working with different encoding formats at the
potential expense of getting an extra line or two if an encoding format
in the future ever allows multiple lines of encoded content to be
considered a single segment.
* feat: add support for Azure DevOps platform in SCM detection and link generation
* feat: add support for visualstudio.com in Azure DevOps platform detection
* feat: consolidate Azure DevOps platform detection for dev.azure.com and visualstudio.com
* I do an entropy check earlier than the others and add the info to the trace
Maybe I'm wrong, but it seems to me that if the regex allowlist is large, it's easier to first check for entropy, since we won't have to go through all these regexes. Plus, we need to check entropy anyway.
Additionally, when using -l trace, there was no information that the find was missed precisely because of entropy. Now it will be shown
* adding info into trace about entropy
* Fixed name of variables
---------
Co-authored-by: Almaz Vakhitov <a.vakhitov@vk.team>
* Support base64 decoding during scans
rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED
* Add failing tests for the case when the match starts outside the decoded value
* Align locations for overlapping, encoded matches
rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED
* Add --max-decode-depth flag and update README help output
rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED
* Move keywords off of fragment
rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED
* Fix comment typo
rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED
* Refactor how keywords are used in detect
rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED
* Clarify comments and rename method to match
rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED
* Improve performance
rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED
* Fix issues after rebase
Only adjust matchIndex to fix the following line issue when not working
with encoded segments since they handle adjusting the index themselves.
rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED
* Update detect/decoder.go
Don't escape characters that don't need escaping
Co-authored-by: Richard Gomez <32133502+rgmz@users.noreply.github.com>
* Update flag help text
rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED
* Add meta data tags from decoding
rh-pre-commit.version: 2.3.1
rh-pre-commit.check-secrets: ENABLED
---------
Co-authored-by: Richard Gomez <32133502+rgmz@users.noreply.github.com>
We should use `(*regexp.Regexp).MatchString` instead of
`(*regexp.Regexp).Match([]byte(...))` when matching string to avoid
unnecessary `[]byte` conversions and reduce allocations.
Example benchmark:
var pathRegex = regexp.MustCompile(".*.yaml")
func BenchmarkMatch(b *testing.B) {
for i := 0; i < b.N; i++ {
if match := pathRegex.Match([]byte("./config/deploy.yaml")); !match {
b.Fail()
}
}
}
func BenchmarkMatchString(b *testing.B) {
for i := 0; i < b.N; i++ {
if match := pathRegex.MatchString("./config/deploy.yaml"); !match {
b.Fail()
}
}
}
goos: linux
goarch: amd64
pkg: github.com/zricethezav/gitleaks/v8/detect
cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics
BenchmarkMatch-16 2167712 657.9 ns/op 24 B/op 1 allocs/op
BenchmarkMatchString-16 3275372 324.8 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/zricethezav/gitleaks/v8/detect 3.436s
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>