ZeroHour
Help Net Securitypublished ()ingested @zeljkazorz

Trojan Source bugs may lead to extensive supply-chain attacks on source code

Vulnerabilities mentionedAll →

CVEVulnerabilityCVSSEPSSFlagsAffectedExposurePublished
CVE-2021-42574
+1 in the same advisory: …42694
An issue was discovered in the Bidirectional Algorithm in the Unicode Specification through 14.0.

An issue was discovered in the Bidirectional Algorithm in the Unicode Specification through 14.0. It permits the visual reordering of characters via control sequences, which can be used to craft source code that renders different logic than the logical ordering of tokens ingested by compilers and interpreters. Adversaries can leverage this to encode source code for compilers accepting Unicode such that targeted vulnerabilities are introduced invisibly to human reviewers. NOTE: the Unicode Consortium offers the following alternative approach to presenting this concern. An issue is noted in the nature of international text that can affect applications that implement support for The Unicode Standard and the Unicode Bidirectional Algorithm (all versions). Due to text display behavior when text includes left-to-right and right-to-left characters, the visual order of tokens may be different from their logical order. Additionally, control characters needed to fully support the requirements of bidirectional text can further obfuscate the logical order of tokens. Unless mitigated, an adversary could craft source code such that the ordering of tokens perceived by human reviewers does not match what will be processed by a compiler/interpreter/etc. The Unicode Consortium has documented this class of vulnerability in its document, Unicode Technical Report #36, Unicode Security Considerations. The Unicode Consortium also provides guidance on mitigations for this class of issues in Unicode Technical Standard #39, Unicode Security Mechanisms, and in Unicode Standard Annex #31, Unicode Identifier and Pattern Syntax. Also, the BIDI specification allows applications to tailor the implementation in ways that can mitigate misleading visual reordering in program text; see HL4 in Unicode Standard Annex #9, Unicode Bidirectional Algorithm.

NVD description · AI analysis pending
8.313% PoC ×4
  • unicode unicode
  • unicode fedora
  • unicode starwind virtual san
Full article688 words · extracted from helpnetsecurity.com · click to collapse

Cambridge University researchers have detailed a new way targeted vulnerabilities can be introduced into source code while making them invisible to human code reviewers, allowing for extensive supply-chain attacks.

supply-chain attacks source code

“We have discovered ways of manipulating the encoding of source code files so that human viewers and compilers see different logic. One particularly pernicious method uses Unicode directionality override characters to display code as an anagram of its true logic,” professor Ross Anderson explained.

The Trojan Source bugs and attacks patterns

Anderson and fellow researcher (and PhD student) Nicholas Boucher have revealed two attack patterns, collectively dubbed Trojan Source attacks.

CVE-2021-42574 is a vulnerability in the bidirectional algorithm in the Unicode Specification. Attackers can use Unicode control characters to reorder tokens in source code at the encoding level, and effectively allow them to craft code that is see one way by compilers and another way by human reviewers. The researchers dubbed this the Bidi attack, and fear that it could lead to widespread supply-chain attacks on source code.

CVE-2021-42694 is an exploitable issue in the character definitions of the Unicode Specification. Attackers can use homoglyphs to produce source code identifiers (e.g., function names) that are visually identical to a target identifier.

“This adversarial function then performs some malicious action, then optionally calls the original function it is impersonating. When defined in upstream dependencies such as open source software, these adversarial functions can be imported into downstream software and invoked without visual indication of malicious code,” the researchers noted. They dubbed this the homoglyph attack.

More technical details can be found in their paper.

Fixing the problem

The researchers created POCs and verified that the Trojan Source attacks work in C, C++, C#, JavaScript, Java, Rust, Go, and Python. They believe other programming languages that support internationalized text in comments and string literals may be vulnerable as well.

They also proposed a number of defense measures that should be implemented in compilers, interpreters, and build pipelines supporting Unicode; language specifications; and code (text) editors and repository front-ends.

They disclosed their findings (under embargo) to a variety of organizations and companies that can work on building these defenses.

“We are of the view that the long-term solution to the problem will be deployed in compilers. We note that almost all compilers already defend against one related attack, which involves creating adversarial function names using zero-width space characters, while three generate errors in response to another, which exploits homoglyphs in function names,” they shared.

“About half of the compiler maintainers we contacted during the disclosure period are working on patches or have committed to do so. As the others are dragging their feet, it is prudent to deploy other controls in the meantime where this is quick and cheap, or relevant and needful. Three firms that maintain code repositories are also deploying defences. We recommend that governments and firms that rely on critical software should identify their suppliers’ posture, exert pressure on them to implement adequate defences, and ensure that any gaps are covered by controls elsewhere in their toolchain.”

Organizations that have already implemented fixes and are working on detections in their supply chain include the Rust team, GitHub, RedHat, and Atlassian (multiple products are affected).

Anderson and Boucher said that after scanning as much of the open source ecosystem as they could for signs of Trojan Source attacks in the wild, they mostly found false positives.

“However, we did find some evidence of techniques similar to Trojan Source attacks being exploited. In one instance, a static code analysis tool for smart contracts, Slither, contained scanning for right-to-left override characters,” they noted.

“We also discovered multiple instances of JavaScript obfuscation that used Bidi characters to assist in obscuring code. This is not necessarily malicious, but is still an interesting use of directionality overrides. Finally, we found multiple implementations of exploit generators for directionality override in filename extensions.”

In the wake of the release of this research, Péter Szilágyi, team lead at Ethereum, pointed out that he discovered the (Bidi) issue five years ago and reported it to the team developing the Go programming language.

Text extracted automatically; images, tables and formatting may be missing. Original: https://www.helpnetsecurity.com/2021/11/02/supply-chain-attacks-source-code/