Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Secrets in UTF-16-Encoded Files are not always detected due to data chunk changes made in the UTF-8 extractSubstrings() function.
In engine.go, TH loops each decoder, passing the Chunk Data in for processing. The UTF-8 decoder runs first. If the data chunk is invalid UTF-8, the UTF-8 decoder will execute the function extractSubstrings(). The result of that function is applied to the Chunk's Data field, which is then passed into all subsequent decoders. Part of that function alters the data structure of valid UTF-16 data, making detecting some secrets impossible.
Here's an example to test out:
Originally, I thought the problem was we did not address the UTF-16 Byte Order Marks (BOM) #FEFF and #FFFE. However, the existing logic takes care of those in the
utf16ToUTF8
function inutf16.go
. I added two test cases to prove that.The only change needed is creating a copy of the chunk prior to processing each decoder.
If that change is too expensive, I have 2 other ideas:
extractSubstrings
out from the UTF-8 decoder and invoke it directlyengine.go
prior to runningFindDetectorMatches
during a failedUTF-8
decode.FindDetectorMatches
.