“Trojan Source” hides flaws in source code from humans
Organizations urged to take action to combat the new threat that could result in SolarWinds-style attacks


Security researchers have revealed a flaw in compilers that could add vulnerabilities to open source projects. Dubbed Trojan Source, the researchers said the attack was potent within the context of software supply chains, such as this year’s SolarWinds attacks.
“If an adversary successfully commits targeted vulnerabilities into open-source code by deceiving human reviewers, downstream software will likely inherit the vulnerability,” said researchers.
Researchers said the attack exploits subtleties in text-encoding standards, such as Unicode, to produce source code with logically encoded tokens that are in a different order from how they are displayed, leading to vulnerabilities.
“These visually reordered tokens can be used to display logic that, while semantically correct, diverges from the logic presented by the logical ordering of source code tokens,” said researchers.
They added that compilers and interpreters adhere to the logical ordering of source code, not the visual order.
Hackers can use multiple techniques to exploit the visual reordering of source code tokens, according to researchers.
The first technique is called “Early Returns.” This causes a function to short circuit by executing a return statement that visually appears to be within a comment.
Get the ITPro daily newsletter
Sign up today and you will receive a free copy of our Future Focus 2025 report - the leading guidance on AI, cybersecurity and other IT challenges as per 700+ senior executives
The second is “Commenting-Out.” This causes a comment to visually appear as code, which in turn is not executed.
RELATED RESOURCE
The truth about cyber security training
Stop ticking boxes. Start delivering real change.
Lastly, there are “Stretched Strings.” These cause portions of string literals to visually appear as code, which has the same effect as commenting-out and causes string comparisons to fail.
There is also a variant that uses homoglyphs, which are characters that appear nearly identical to letters.
“An attacker can define such homoglyph functions in an upstream package imported into the global namespace of the target, which they then call from the victim code,” said researchers.
This attack variant is tracked as CVE-2021-42694.
Researchers said to defend against such attacks, compilers, interpreters, and build pipelines supporting Unicode should throw errors or warnings for unterminated bidirectional control characters in comments or string literals, and for identifiers with mixed-script confusable characters.
“Language specifications should formally disallow unterminated bidirectional control characters in comments and string literals,” they added. “Code editors and repository frontends should make bidirectional control characters and mixed-script confusable characters perceptible with visual symbols or warnings.”
Rene Millman is a freelance writer and broadcaster who covers cybersecurity, AI, IoT, and the cloud. He also works as a contributing analyst at GigaOm and has previously worked as an analyst for Gartner covering the infrastructure market. He has made numerous television appearances to give his views and expertise on technology trends and companies that affect and shape our lives. You can follow Rene Millman on Twitter.
-
The Race Is On for Higher Ed to Adapt: Equity in Hyflex Learning
By ITPro
-
Google faces 'first of its kind' class action for search ads overcharging in UK
News Google faces a "first of its kind" £5 billion lawsuit in the UK over accusations it has a monopoly in digital advertising that allows it to overcharge customers.
By Nicole Kobie
-
CronRat Magecart malware uses 31st February date to remain undetected
News The malware allows for server-side payment skimming that bypasses browser security
By Rene Millman
-
Mekotio trojan continues to spread despite its operators’ arrests
News Hackers have used it in 100 more attacks since arrests
By Rene Millman
-
What is Emotet?
In-depth A deep dive into one of the most infamous and prolific strains of malware
By Praharsha Anand
-
Fake AnyDesk Google ads deliver malware
News Malware pushed through Google search results
By Rene Millman
-
Hackers use open source Microsoft dev platform to deliver trojans
News Microsoft's Build Engine is being used to deploy Remcos password-stealing malware
By Rene Millman
-
Android users told to be on high alert after Cerberus banking Trojan leaks to the dark web
News The source code for the authenticator-breaking malware is available for free on underground forums
By Sabina Weston
-
Qbot malware surges into the top-ten most common business threats
News An evolved form of the banking Trojan was distributed by number one-ranking Emotet in a campaign that hit 5% of businesses globally
By Keumars Afifi-Sabet
-
BlackRock banking Trojan targets Android apps
News Trojan steals login credentials and credit card information and has targeted more than 300 apps
By Sarah Brennan