Skip to content

Commit 1eea748

Browse files
committed
lint: add linter for unicode directional formatting characters
This PR adds a linter to disallow the use of directional formatting characters to help prevent them being used to get malicious code past code review. Ideally our code-review tool would highlight such characters for us since such characters might routinely appear in binary artifacts. See also: - https://www.trojansource.codes/ - https://blog.rust-lang.org/2021/11/01/cve-2021-42574.html - golang/go#20209 Release note: None
1 parent da7b0c8 commit 1eea748

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

pkg/testutils/lint/lint_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,54 @@ func TestLint(t *testing.T) {
633633
}
634634
})
635635

636+
t.Run("TestDisallowedCharacterSequences", func(t *testing.T) {
637+
t.Parallel()
638+
disallowedCharacterSequences := []string{
639+
"\u202A", // LEFT-TO-RIGHT-EMBEDDING
640+
"\u202B", // RIGHT-TO-LEFT-EMBEDDING
641+
"\u202C", // POP-DIRECTIONAL-FORMATTING
642+
"\u202D", // LEFT-TO-RIGHT-OVERRIDE
643+
"\u202E", // RIGHT-TO-LEFT-OVERRIDE
644+
"\u2066", // LEFT-TO-RIGHT-ISOLATE
645+
"\u2067", // RIGHT-TO-LEFT-ISOLATE
646+
"\u2068", // FIRST-STRONG-ISOLATE
647+
"\u2069", // POP-DIRECTIONAL-ISOLATE
648+
}
649+
pattern := strings.Join(disallowedCharacterSequences, "|")
650+
cmd, stderr, filter, err := dirCmd(
651+
crdb.Dir,
652+
"git",
653+
"grep",
654+
"-nE",
655+
pattern,
656+
"--",
657+
":!*.woff2",
658+
":!*.png",
659+
":!*.tgz",
660+
":!pkg/ccl/importccl/testdata/avro/stock-10000.bjson",
661+
":!pkg/ccl/importccl/testdata/avro/stock-10000.ocf",
662+
)
663+
if err != nil {
664+
t.Fatal(err)
665+
}
666+
667+
if err := cmd.Start(); err != nil {
668+
t.Fatal(err)
669+
}
670+
671+
if err := stream.ForEach(filter, func(s string) {
672+
t.Errorf("\n%s <- forbidden use of disallowed character sequence.", s)
673+
}); err != nil {
674+
t.Error(err)
675+
}
676+
677+
if err := cmd.Wait(); err != nil {
678+
if out := stderr.String(); len(out) > 0 {
679+
t.Fatalf("err=%s, stderr=%s", err, out)
680+
}
681+
}
682+
})
683+
636684
t.Run("TestInternalErrorCodes", func(t *testing.T) {
637685
t.Parallel()
638686
cmd, stderr, filter, err := dirCmd(

0 commit comments

Comments
 (0)