SKY-D344 · Security in code
Trojan Source bidirectional Unicode
Unicode has invisible control characters that switch the direction in which text is shown, for right-to-left languages. "Trojan Source" uses them in code so that an editor or code review shows something different from what Python runs. SKY-D344 reports every line of a Python file that contains one of these controls: U+202A to U+202E and U+2066 to U+2069.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
Why it matters
A reviewer can read if access_level != "user": # Check if admin and approve it, while the real string is longer and never equals "user", so every user passes the admin check. The trick hides a backdoor in a pull request that looks harmless.
What Skylos flags
def can_delete(account): access_level = account.role if access_level != "user # Check if admin ": return True return FalseWhat Skylos leaves alone
GREETINGS = { "en": "Welcome back", "he": "ברוך שובך", "ar": "مرحبا بعودتك",} def greeting(language): return GREETINGS.get(language, GREETINGS["en"])Why Skylos leaves it alone
Hebrew and Arabic letters are shown right to left by the text itself; they are not direction controls. Skylos only looks for the nine control characters that can reorder the rest of a line.
How Skylos decides
- Reads the raw text of each Python file (
.py,.pyi,.pyw) before parsing, test files included. - Looks for the bidirectional embedding, override and isolate controls: U+202A to U+202E and U+2066 to U+2069. Marks such as U+200E and U+200F are not on the list.
- Reports HIGH once per line that contains one, at the first such character, and records which code point it is.
- In other files (Markdown, YAML, prompts and so on) the same characters are reported by SKY-D260 instead.
How to fix it
Delete the control characters and check what the line really says. If you need right-to-left text in a string, write the letters directly, or use \u escapes so the controls are visible in the source.
def can_delete(account): access_level = account.roleRemoved: if access_level != "user # Check if admin ":Added: if access_level != "user": return True return FalseWhen it can be wrong
- A translation file that uses direction controls on purpose, to mix right-to-left and left-to-right words in one message, is reported. Writing those controls as
\u202e-style escapes keeps the meaning and avoids the finding.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Mark a reviewed line and say why. A bare
# noqadoes not hide HIGH security findings.Python LABEL = "..." # skylos: ignore[SKY-D344] intended RTL embeddingAccept the findings you already have with
skylos baseline ., then scan with--baselineso only new ones are listed.[tool.skylos] ignore = ["SKY-D344"]turns the rule off for the whole project.