feature: add rule for trojan source#1431
Conversation
| return nil, nil | ||
| } | ||
|
|
||
| content, err := os.ReadFile(fobj.Name()) |
There was a problem hiding this comment.
Does this perform well with large files?
I would use something like to make sure that we don't run out of memory and have performance issues:
file, err := os.Open("")
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
// Process line
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
|
Please can you rebase this pull request? Thanks |
fdaa16d to
9390ca4
Compare
|
Thanks for the review. I evaluated the memory efficiency with /usr/bin/time -v go run ./cmd/gosec/ --include=G116 ../kubernetes/...
I also rebased the commits. |
|
It seems that there are still some lint issues. PTAL thanks |
Change-Id: Ic1df6704ba5ab8b1834d7765abd49494a98835f8 Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
9390ca4 to
a94b325
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1431 +/- ##
==========================================
- Coverage 68.49% 64.54% -3.96%
==========================================
Files 75 78 +3
Lines 4384 4716 +332
==========================================
+ Hits 3003 3044 +41
- Misses 1233 1524 +291
Partials 148 148 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Sorry for the late response. |
|
I forgot to add the new rule to the README. Should I open a PR for that? |
Description
Add rule to detect Trojan Source attacks (CVE-2021-42574) using bidirectional Unicode control characters as G116.
The rule scans entire file content to detect dangerous bidirectional text control characters:
RLO (U+202E), LRI/RLI/FSI (U+2066/2067/2068), LRE/RLE (U+202A/202B), PDF (U+202C), LRO (U+202D), RLM/LRM (U+200F/200E)
References:
Fixes
Issue: #1429
Comment
testutils/g116_samples.gouses#nosecbecause G116 scans entire file content (not just AST nodes but also comments). The test file contains actual bidirectional Unicode characters to verify detection works correctly. Without#nosec, gosec would flag its own test samples when runningmake test.