# How Invisible Unicode Characters Can Hide Malicious Go Code in Test Files

DevFeed: [How Invisible Unicode Characters Can Hide Malicious Go Code in Test Files](<https://devfeed.tech/articles/jia-tanning-go-code-53015.md>)

Original publisher: [Read original article](<https://www.arp242.net/jia-tan-go.html>)

Author: Martin Tournoij

Published: 2024-10-28T00:00:00Z

Content type: article

Language: en

Sources: [arp242.net](<https://devfeed.tech/sources/arp242-net.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [backdoor](<https://devfeed.tech/topics/backdoor.md>), [Security](<https://devfeed.tech/topics/security.md>), [passwords](<https://devfeed.tech/topics/passwords.md>)

Tags: [backdoor](<https://devfeed.tech/tags/backdoor.md>), [github](<https://devfeed.tech/tags/github.md>), [gitlab](<https://devfeed.tech/tags/gitlab.md>), [go](<https://devfeed.tech/tags/go.md>), [go-test](<https://devfeed.tech/tags/go-test.md>), [security](<https://devfeed.tech/tags/security.md>), [testing](<https://devfeed.tech/tags/testing.md>), [vscode](<https://devfeed.tech/tags/vscode.md>)

## AI overview

This article explains how invisible Unicode variation selectors, homoglyphs, and zero-width characters can make a Go filename appear to end in _test.go without actually doing so. Such a file may be compiled into regular builds, allowing seemingly harmless test-related code to weaken password security or introduce a backdoor.

## Source excerpt

The Go compiler skips files ending with _test.go during normal compilation. They are compiled with go test command (together will all other .go files), which also inserts some chutney to run the test functions. The standard way to do testing is to have a foo.go and foo_test.go file next to each other. If you have a file that appears to end with _test.go but doesn't actually end with _test.go, then it will get compiled for a regular build. For example: a_test\uFE0E.go U+FE0E is a variation selector. These are typically very invisible. Or more traditional homoglyph trickery: b_t\u0435\u0455t.go" Those Cyrillic letters appear virtually identical on my machine: b_tеѕt.go / b_test.go, or as monospace: b_tеѕt.go / b_test.go. This can also be done with zero-width space, zero-width joiner, and perhaps a few other codepoints, but variation selectors tend to be the "most invisible" of them. This is pretty sneaky, something like this: // user.go var bcryptCost = bcrypt.DefaultCost func hashPassword(pwd []byte) []byte { pwd, _ := bcrypt.GenerateFromPassword(pwd, bcryptCost) return pwd } // user_test.go func init() { // The special "init" function gets run on import. // Lower bcrypt cost in tests, because otherwise any test will take // well over a second as it's so slow. bcryptCost = bcrypt.MinCost } Is perfectly valid, but with a doctored "non-test" user_test.go it will now lower the security of all passwords, and effectively inserts a backdoor. There are many variants one can think of: code that looks innocent and would probably pass many reviews, but will backdoor the codebase by weakening the security, or adds in "test users", "test keys", "default passwords", and things like that. Who is carefully auditing tests for security in the first place? I've audited a bunch of packages over the years, but I've never paid much attention to the test files. Most tools don't display this: Vim, VSCode, macOS finder, Windows Explorer, /bin/ls, GitHub, GitLab, etc. - they all just display