back to home

elementsinteractive / twyn

Security tool against dependency typosquatting attacks

55 stars
5 forks
3 issues
PythonDockerfileJust

AI Architecture Analysis

This repository is indexed by RepoMind. By analyzing elementsinteractive/twyn in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.

Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.

Source files are only loaded when you start an analysis to optimize performance.

Embed this Badge

Showcase RepoMind's analysis directly in your repository's README.

[![Analyzed by RepoMind](https://img.shields.io/badge/Analyzed%20by-RepoMind-4F46E5?style=for-the-badge)](https://repomind.in/repo/elementsinteractive/twyn)
Preview:Analyzed by RepoMind

Repository Overview (README excerpt)

Crawler view

Twyn Table of Contents • Overview • Quickstart • Using as a cli tool • Installation • Docker • CLI Options Reference • Run • JSON Format • Using as a library • Logging level • Configuration • Allowlist • Dependency files • Check dependencies introduced through the CLI • Selector method • Configuration file • Cache Overview is a security tool that compares the name of your dependencies against a set of the most popular ones, in order to determine if there is any similarity between them, preventing you from using a potentially illegitimate one. In short, protects you against typosquatting attacks. It works as follows: • Either choose to scan the dependencies in a dependencies file you specify ( ) or some dependencies introduced through the CLI ( ). If no option was provided, it will try to find a dependencies file in your working path. It will try to parse all the supported dependency files that it finds. To know which files are supported head to the Dependency files section. • If the name of your package name matches with the name of one of the most well known packages, the package is accepted. • If the name of your package is similar to the name of one of the most used packages, will prompt an error. • If your package name is not in the list of the most known ones and is not similar enough to any of those to be considered misspelled, the package is accepted. assumes that you're using either a not so popular package (therefore it can't verify its legitimacy) or a package created by yourself, therefore unknown for the rest. Quickstart Using twyn as a CLI tool Installation is available on PyPi repository, you can install it by running Docker provides a Docker image, which can be found here. Use it like so: CLI Options Reference | Option / Argument | Type / Values | Description | |--------------------------|----------------------------------------------------|-----------------------------------------------------------------------------------------------| | | (path) | Path to configuration file ( or by default). | | | (path) | Dependency file to analyze. Supported: , , , etc. | | | (multiple allowed) | Dependency to analyze directly. Can be specified multiple times. | | | , , | Method for selecting possible typosquats. | | | , , | Package ecosystem for analysis. | | | flag | Enable info-level logging. | | | flag | Enable debug-level logging. | | | flag | Disable use of trusted packages cache. Always fetch from the source. | | | flag | Do not show the progress bar while processing packages. | | | flag | Display results in JSON format. Implies . | | , | flag | Scan directories recursively for dependency files. | Run **Usage Example:** or get help with JSON format If you want your output in JSON format, you can run with the following flag: This will output: If was run by manually giving it dependencies (with ), the source will be . In any other case (when dependencies are parsed from a file), the source will be the path to the dependencies file. One entry will be created for every source. Using Twyn as a library Installation also supports being used as 3rd party library for you project. To install it, run: Example usage in your code: Logging level By default, logging is disabled when running as a 3rd party library. To override this behaviour, you can: Configuration Allowlist It can happen that a legitimate package known by the user raises an error because it is too similar to one of the most trusted ones. Imagine that you are using internally a package that you developed called . You can then add this packages to the , so it will not be reported as a typo: To remove it simply: Dependency files To specify a dependency file through the command line run: The following dependency file formats are supported: • • ( =1.5) • • (v1, v2, v3) • (v1, v2) • (v9) • • , , , (v1, v2, v3) Check dependencies introduced through the CLI You can also check a dependency by entering it through the command line: It does accept multiple dependencies at a time: When this option is selected, no dependency file is checked. Selector method You can choose between different operational modes. These will determine which dependencies from the trusted set the analyzed dependency can be a typosquat of. • : Default option. It is the most exhaustive mode. It will check your package names against all the trusted ones without any assumption. • : It will assume a typo on the first letter of the dependency is possible, but improbable if letters are farther apart in the keyboard. Specifically, it will compare the analyzed dependency against dependencies whose first letter is one step away in an keyboard layout. • : It will assume a typo on the first letter is very improbable, and won't compare the analyzed dependency against dependencies with a different first letter. > [!NOTE] > Selecting an option is a matter of preference: is the slowest, but will have more false positives and less false negatives; while is the fastest, but it will have less false positives and more false negatives. To select a specific operational mode through the CLI use the following command Configuration file You can save your configurations in a file, so you don't need to specify them everytime you run in your terminal. By default, it will try to find a file in your working directory when it's trying to load your configurations. If it does not find it, it will fallback to . However, you can specify a config file as follows: All the configurations available through the command line are also supported in the config file. The file format for each reference is as follows: Cache By default, will cache the list of trusted packages to a cache file, within the directory that will be automatically created. You can disable the cache by adding the following flag: In which case it will download again the list of trusted packages, withou saving them to the cache file. Cache file is valid for 30 days, after that period it will…