Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
anti-trojan-source
Advanced tools
Detect trojan source attacks that employ unicode bidi attacks to inject malicious code
Detect trojan source attacks that employ unicode bidi attacks to inject malicious code
Detects cases of trojan source attacks that employ unicode bidi attacks to inject malicious code
If you're using ESLint:
detect-bidi-characters
in eslint-plugin-security and if you're already using that security plugin then it is advised to turn on that rule.The following publication on the topic of unicode characters attacks, dubbed Trojan Source: Invisible Vulnerabilities, has caused a lot of concern from potential supply chain attacks where adversaries are able to inject malicious code into the source code of a project, slipping by unseen in the code review process.
For more information on the topic, you're welcome to read on the official website trojansource.codes and the following source code repository which contains the source code of the publication.
Table of Contents
anti-trojan-source
is an npm package that supports detecting files that contain bidirectional unicode characters in them, per the research.
The following command will detect all files that contain bidirectional unicode characters in them based on the file matching pattern that was provided to it:
npx anti-trojan-source --files='src/**/*.js'
If it doesn't find anything it will return with a 0 exit code and print to stdout:
[✓] No case of trojan source detected
npx anti-trojan-source '/src/index.js' '/src/helper.js'
If it found any matching bidi unicode characters, it will return with an exit code of 1 and print to stderr:
[x] Detected cases of trojan source in the following files:
|
- /src/index.js
- /src/helper.js
If you just run npx anti-trojan-source
and pipe in a file contents, it will detect the bidi unicode characters in that file:
cat /src/index.js | npx anti-trojan-source
Refer to the ESLint Plugin for this CLI and the README on that repository which clearly explains how to set it up: eslint-plugin-anti-trojan-source.
To use it as a library and pass it file contents to detect:
import { hasTrojanSource } from 'anti-trojan-source'
const isDangerous = hasTrojanSource({
sourceText: 'if (accessLevel != "user // Check if admin ") {'
})
hasTrojanSource
returns a boolean.
To add this tool to your project as a pre-commit
hook, try this sample configuration in .pre-commit-config.yaml
:
repos:
- repo: https://github.com/lirantal/anti-trojan-source
rev: v1.3.3 # choose the release you want
hooks:
- id: anti-trojan-source
Please consult CONTRIBUTING for guidelines on contributing to this project.
anti-trojan-source © Liran Tal, Released under the Apache-2.0 License.
FAQs
Detect trojan source attacks that employ unicode bidi attacks to inject malicious code
The npm package anti-trojan-source receives a total of 17,934 weekly downloads. As such, anti-trojan-source popularity was classified as popular.
We found that anti-trojan-source demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.