trojansource
v1.0.0
Published
Scan Git repositories for Unicode characters used in Trojan Source attacks.
Maintainers
Readme
trojansource
trojansource scans Git-tracked source files for invisible Unicode formatting characters that can
be used in Trojan Source attacks. It reports BiDi embedding,
override, and isolate controls, directional marks, and selected invisible characters. Visible
Unicode text, including Swedish text and emoji, remains allowed.
Install and use
Run it without installation:
npx trojansourceOr install it in a project:
pnpm add -D trojansource
pnpm exec trojansource --allThe npm CLI dispatches to a precompiled Go binary for the current operating system and CPU architecture. It supports Linux, macOS, and Windows on x64 and ARM64.
The default --all mode scans tracked and untracked, non-ignored files. Use --staged to scan
only staged additions, copies, modifications, and renames:
pnpm exec trojansource --stagedThe command exits with status 1 when it finds an unsafe character and 2 for invalid arguments.
Allowlisting files
To permit a file that intentionally contains one of these characters, add its repository-relative
path to unicode-security-allowlist.json in the repository root:
{
"files": ["fixtures/intentional-bidi.txt"]
}Allowlisting skips the complete file. Prefer removing the character where possible.
Go CLI and library
The repository also provides a native Go implementation with no external dependencies:
go install github.com/linus-jansson/trojansource/cmd/trojansource@latest
trojansource --stagedUse github.com/linus-jansson/trojansource as a Go library to call ScanContent or
ScanRepository. Its CLI has the same options, output, allowlist format, and exit codes as the
npm CLI. ScanContent returns findings without accessing the file system, and ScanRepository
accepts an Options value with CWD, Mode, and AllowlistPath fields.
