Skip to main content

SKY-D344 · Security in code

Trojan Source bidirectional Unicode

High

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

app/permissions.py · PythonReported on line 3
def can_delete(account):    access_level = account.role    if access_level != "user‮ ⁦# Check if admin⁩ ⁦":        return True    return False

What Skylos leaves alone

app/greetings.py · Python
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

  1. Reads the raw text of each Python file (.py, .pyi, .pyw) before parsing, test files included.
  2. 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.
  3. Reports HIGH once per line that contains one, at the first such character, and records which code point it is.
  4. 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.

app/permissions.py · Python · the fix, against the flagged file
def can_delete(account):    access_level = account.roleRemoved:     if access_level != "user‮ ⁦# Check if admin⁩ ⁦":Added:     if access_level != "user":        return True    return False

When 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 # noqa does not hide HIGH security findings.

    Python
    LABEL = "..."  # skylos: ignore[SKY-D344] intended RTL embedding
  • Accept the findings you already have with skylos baseline ., then scan with --baseline so only new ones are listed.

  • [tool.skylos] ignore = ["SKY-D344"] turns the rule off for the whole project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.