ripsecrets is a command-line tool to prevent committing secret keys into your source code.

Overview

ripsecrets

ripsecrets logo, a gravestone that says

ripsecrets is a command-line tool to prevent committing secret keys into your source code. ripsecrets has a few features that distinguish it from other secret scanning tools:

What makes ripsecrets different

ripsecrets has a few features that distinguish it from other secret scanning tools:

  1. Focused on pre-commit. It's a lot cheaper to prevent secrets from getting committed in the first place than dealing with the consequences once a secret that has been committed to your repository has been detected.

  2. Extremely fast. Using a secret scanner shouldn't slow down your development workflow, so ripsecrets is 95 times faster or more than other tools. Learn more about how it's designed for performance.

  3. Always local operation. Many other secret scanners try to verify that the secrets are valid, which is practice means sending strings from your source code to 3rd party services automatically. There's a security versus convenience tradeoff in that decision, but ripsecrets is designed to be the best "local only" tool and will never send data off of your computer.

  4. Low rate of false positives. While local-only tools are always going to have more false positives than one that verifies secrets, ripsecrets uses a probability theory based approach in order to detect keys more accurately than other tools.

  5. Single binary with no dependencies. Installing ripsecrets is as easy as copying the binary into your bin directory.

Usage

By default, running ripsecrets will recursively search source files in your current directory for secrets.

$ ripsecrets

For every secret it finds it will print out the file, line number, and the secret that was found. If it finds any secrets it will exit with a non-zero status code.

You can optionally pass a list of files and directories to search as arguments.

$ ripsecrets file1 file2 dir1

This is most commonly used to search files that are about to be committed to source control for accidentally included secrets.

Installing ripsecrets as a pre-commit hook

You can install ripsecrets as a pre-commit hook automatically in your current git repository using the following command:

$ ripsecrets --install-pre-commit

If you would like to install ripsecrets manually, you can add the following command to your pre-commit script:

ripsecrets --strict-ignore `git diff --cached --name-only --diff-filter=ACM`

Passing --strict-ignore ensures that your .secretsignore file is respected when running secrets as a pre-commit.

Installation

You can download a prebuilt binary for the latest release from the releases page.

Alternatively, if you have Rust and Cargo installed, you can run:

$ cargo install --git https://github.com/sirwart/ripsecrets --branch main

Using pre-commit

ripsecrets can work as a plugin for pre-commit with the following configuration.

Note that this may require having Cargo and a Rust compiler already installed. See the pre-commit rust plugin docs for more information.

repos:
-   repo: https://github.com/sirwart/ripsecrets.git
    # Set your version, be sure to use the latest and update regularly or use 'main'
    rev: v0.1.3
    hooks:
    -   id: ripsecrets

Ignoring secrets

ripsecrets will respect your .gitignore files by default, but there might still be files you want to exclude from being scanned for secrets. To do that you can create a .secretsignore file, which supports similar syntax to a .gitignore file for ignoring files. In addition to excluding files, it also supports a [secrets] section that allows ignoring individual secrets.

test/*
dummy

[secrets]
pAznMW3DsrnVJ5TDWwBVCA

In addition to the .secretsignore file, ripsecrets is compatible with detect-secrets style allowlist comments on the same line as the detected secret:

test_secret = "pAznMW3DsrnVJ5TDWwBVCA" # pragma: allowlist secret

Performance

The slowest part of secret scanning is looking for potential secrets in a large number of files. To do this quickly ripsecrets does a couple of things:

  1. All the secret patterns are compiled into a single regex, so each file only needs to be processed once.

  2. This regex is fed to ripgrep, which is specially optimized to running a regex against a large number of files quickly.

Additionally, ripsecrets is written in Rust, which means there's no interpreter startup time. To compare real world performance, here's the runtime of a few different scanning tools to search for secrets in the Sentry repo on an M1 air laptop:

tool avg. runtime vs. baseline
ripsecrets 0.32s 1x
trufflehog 31.2s 95x
detect-secrets 73.5s 226x

Most of the time, your pre-commit will be running on a small number of files, so the runtimes above are not typical, but when working with large commits that touch a lot of files the runtime can become noticeable.

Alternative tools

Even if ripsecrets is not the right tool for you, if you're working on a service that deals with user data you should strongly consider using a secret scanner. Here are some alternative tools worth considering:

Comments
  • Add a benchmark using Criterion

    Add a benchmark using Criterion

    Given this project's emphasis on performance, I thought it'd be nice to have some built-in benchmarking. This way, contributors can easily check if their changes improve or hinder performance against a relatively standardized test (of course, absolute values will vary machine-to-machine).

    As a first attempt at this, I decided to use a Rust library Criterion. I hit some issues right away, though: Criterion makes it pretty difficult to benchmark functions that are not in src/lib.rs (see this Stack Overflow Q&A).

    Because of this, I decided to take the rather aggressive step of renaming src/find_secrets.rs -> src/lib.rs. I think this has benefits beyond easy benchmarking; for example, if someone wanted to use ripsecrets as a Rust library, I think it makes sense to have a lib.rs file.

    I also folded the p_random file into the matcher module, which I think works well, since it appears that p_random's public function is only used within the matcher module.

    Currently, there's only one benchmark. It basically runs find_secrets on the ripsecrets directory itself (I think?). On my System76 Oryx Pro, mean bench time is about 56ms.

    opened by sts10 10
  • The name

    The name "secrets" complicates discovery

    While secrets is basically "get secrets" and expect none to be returned, the name is, well, not very S.E.O. friendly. @sirwart, are you open to considering some other names while this tool is still in its infancy?

    opened by colindean 8
  • Publish benchmarks to GitHub Pages

    Publish benchmarks to GitHub Pages

    On each commit to main, run benchmarks and publish them to the gh-pages branch. That branch can be configured as the source of GitHub Pages, so it gets built and published on each change. See https://lafrenierejm.github.io/ripsecrets/dev/bench/ for an example of benchmarks published from my fork.

    opened by lafrenierejm 6
  • Running cargo install downloads sentry submodule

    Running cargo install downloads sentry submodule

    When trying to install ripsecrets via cargo I noticed that it now tries to download the entire sentry module because it's listed as a submodule, which takes a long time because it's a large repo. Either the configuration needs to change or removed as a submodule.

    opened by sirwart 4
  • [rebase] Add a benchmark using Criterion

    [rebase] Add a benchmark using Criterion

    Attempt to rebase #25 onto the current HEAD of main, 6feb4f7dccc6834877fe61dcb94cbb547a55a176.

    Copying the first part of @sts10's PR description:

    Given this project's emphasis on performance, I thought it'd be nice to have some built-in benchmarking. This way, contributors can easily check if their changes improve or hinder performance against a relatively standardized test (of course, absolute values will vary machine-to-machine).

    As a first attempt at this, I decided to use a Rust library Criterion. I hit some issues right away, though: Criterion makes it pretty difficult to benchmark functions that are not in src/lib.rs (see this Stack Overflow Q&A).

    Because of this, I decided to take the rather aggressive step of renaming src/find_secrets.rs -> src/lib.rs. I think this has benefits beyond easy benchmarking; for example, if someone wanted to use ripsecrets as a Rust library, I think it makes sense to have a lib.rs file.

    opened by lafrenierejm 4
  • What kind of secret that ripsecrets can find out

    What kind of secret that ripsecrets can find out

    I write a simple code like

    package main
    
    func main() {
            clientSecretKey := "alkfjlaf^*flkajlfkay7782085ljafg"
            println(clientSecretKey)
    }
    

    and hope ripsecrets can tell me 'you hardcode the secret in source files', but there's nothing output

    opened by Sherlock-Holo 4
  • Finalize pre-commit configuration

    Finalize pre-commit configuration

    According to this PR: https://github.com/sirwart/ripsecrets/pull/2:

    Once this is merged, someone (me?) could put a PR on https://github.com/pre-commit/pre-commit.com/blob/main/all-repos.yaml that adds https://github.com/sirwart/secrets to it.

    Someone needs to add https://github.com/sirwart/ripsecrets to the pre-commit repository.

    opened by sirwart 4
  • Add --only-matching option

    Add --only-matching option

    Add only-matching option to only output matching parts of the string (similar to how rg goes it).

    I had to replace printer::Standard with printer::StandardBuilder in order to achieve that - hope it's not an issue.

    opened by hi-artem 4
  • implements clap, with an opinonated choice of using subcommands

    implements clap, with an opinonated choice of using subcommands

    Attempt 2 at implemented clap on this project. I found I had to make the rather controversial choice of enforcing use of subcommands, so users will need to run secrets check file1 file2 now. I don't love it, and if it's not expected I understand. But I do think integrating a argument parser will save some headaches as more command-line options are added.

    opened by sts10 4
  • Require separator between identifier and value

    Require separator between identifier and value

    The recent change (https://github.com/sirwart/ripsecrets/commit/c40ddbd63c7bf6f08c7e7fe11bfe2a751cf23368) made the separator between identifier and value optional, which results in more false positives. I think this change makes the behavior more reasonable. Alternatively, we can go back to requiring an assignment operator.

    opened by filipochnik 3
  • Uses FXHash, rather than Rust's default hasher

    Uses FXHash, rather than Rust's default hasher

    Uses FxHash rather than Rust's default hasher, in an attempt to improve performance.

    My tests have been a bit inconclusive, so would appreciate it if others compared these changes to the main branch in whatever way they think best. FxHash might even be a touch slower in some cases? I'm not sure.

    There are definitely other hashers that may be worth exploring, like ahash. Maybe alternatives to try can be discussed in the comments here.

    opened by sts10 3
  • Bug: Long secrets are not ignored

    Bug: Long secrets are not ignored

    Long secrets are not ignored.

    See the example below. The first two secrets are ignored, while the last two are not.

    .secretsignore

    [secrets]
    96etKOmnte-bpLDSIcwdhXYlC82gF8x-ERPqZ7oo1Ug
    8AOiCMgwF1eg5yLDgw9D1eymTSOp21PJwr4zdQRQyYQ
    eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eODlIjoiYWNjZXNzIiwiZXhwIjoxNjUxMTQxMzc3LCJpYXQiOjE2NTExNDA0ODAsImp0aSI6ImQzAAJmYzBiNzI2NDRjMjY5ODI0NGFiMTQ2OTc1N2YyIiwidXNlcl9pZCI6MX0.87aml-57DmEUo4LrlZwnDw4iVfiWVNA90xxCi01M2h0
    eyJ0eXAiOiJKV1QiCCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eWPlIjoiYWNjZXNzIiwiZXhwIjoxNjUxMTQxMzgxLCJpYXQiOjE2NTExNDEwODEsImp0aSI6Ijk1YjRjMDA2ODZjNTRkYTU4OTE1NWYzOTgzZjcxNmJiIiwidXNlcl9pZCI6MX0.zs-3zv1eCSu9JeRBJgFw6CBoZUA4B2R3z6gl2vNYwdA
    

    Easily reproducible like this:

    ripsecrets .secretsignore
    
    opened by barseghyanartur 0
  • Consider supporting BIND9 config format

    Consider supporting BIND9 config format

    Like this https://bind9.readthedocs.io/en/v9_16_5/advanced.html#loading-a-new-key See also discussion in https://github.com/sirwart/ripsecrets/pull/35

    opened by filipochnik 0
  • Add user friendly method for adding additional secret patterns

    Add user friendly method for adding additional secret patterns

    Hi!

    Love the tool! The performance gains are awesome! Curious if you had any plans to make adding additional secret patterns to the tool more friendly (Maybe an external TOML file with user specified patterns?). If you could forsee this being part of the tool, would love to pull together a PR if we can agree on an implementation.

    Otherwise - would be happy to PR some additional secret patterns!

    opened by rileydakota 6
Releases(v0.1.5)
Owner
Brian Smith
Brian Smith
H2O Open Source Kubernetes operator and a command-line tool to ease deployment (and undeployment) of H2O open-source machine learning platform H2O-3 to Kubernetes.

H2O Kubernetes Repository with official tools to aid the deployment of H2O Machine Learning platform to Kubernetes. There are two essential tools to b

H2O.ai 16 Nov 12, 2022
To help prevent directory traversal attacks

safe_join Use SafeJoin::safe_join in place of Path::join to help prevent directory traversal attacks. A call of the form dir.safe_join(path) returns a

Trail of Bits 1 Dec 27, 2021
Safer Nostr is a service that helps protect users by loading sensitive information (IP leak) and using AI to prevent inappropriate images from being uploaded.

Safer Nostr is a service that helps protect users by loading sensitive information (IP leak) and using AI to prevent inappropriate images from being uploaded. It also offers image optimization and storage options. It has configurable privacy and storage settings, as well as custom cache expiration.

Thomas 4 Dec 29, 2022
Small command-line tool to switch monitor inputs from command line

swmon Small command-line tool to switch monitor inputs from command line Installation git clone https://github.com/cr1901/swmon cargo install --path .

William D. Jones 5 Aug 20, 2022
A blazing fast command line license generator for your open source projects written in Rust🚀

Overview This is a blazing fast ⚡ , command line license generator for your open source projects written in Rust. I know that GitHub

Shoubhit Dash 43 Dec 30, 2022
hj is a command line tool to convert HTTP/1-style text into JSON

hj hj is a command line tool to convert HTTP/1-style text into JSON. This command is inspired by yusukebe/rj, which is a standalone HTTP client that s

FUJI Goro 10 Aug 21, 2022
a command-line tool that transforms a Git repository into a minimal format for ChatGPT queries

gprepo /dʒiːpiːˈɹi:pi:oʊ/ a command-line tool that transforms a Git repository into a minimal format for ChatGPT queries. Features Excludes LICENSE an

null 6 Apr 20, 2023
Code-shape is a tool for extracting definitions from source code files

Code-shape Code-shape is a tool that uses Tree-sitter to extract a shape of code definitions from a source code file. The tool uses the same language

Andrew Hlynskyi 3 Apr 21, 2023
Pink is a command-line tool inspired by the Unix man command.

Pink is a command-line tool inspired by the Unix man command. It displays custom-formatted text pages in the terminal using a subset of HTML-like tags.

null 3 Nov 2, 2023
🕺 Run React code snippets/components from your command-line without config

Run React code snippets/components from your command-line without config.

Eliaz Bobadilla 11 Dec 30, 2022
Command-line tool to generate Rust code for Google Cloud Spanner

nene nene is a command-line tool to generate Rust code for Google Cloud Spanner. nene uses database schema to generate code by using Information Schem

Naohiro Yoshida 3 Dec 7, 2021
Save image from your clipboard 📋 as an image file directly from your command line! 🔥

Clpy ?? Save copied image from clipboard as an image file directly from your command line! Note It works only on windows as of now. I'll be adding sup

Piyush Suthar 13 Nov 28, 2022
Reddit - Liberate your Reddit Chats. This tool will export your reddit chats into a plethora of formats

Rexit Rexit - Liberate your Reddit Chats. This tool will export your Reddit chats into a plethora of formats Tool to export Reddit chats into a variet

Maximilian Pult 6 May 3, 2023
zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets you're watching easily into watchlists for easy access on your terminal.

zigfi zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets

Aldrin Zigmund Cortez Velasco 18 Oct 24, 2022
A command line tool, manage your hundreds of repository, written with Rust

A command line tool, manage your hundreds of repository, written with Rust

Axetroy 4 Aug 16, 2022
A command-line tool aiming to upload the local image used in your markdown file to the GitHub repo and replace the local file path with the returned URL.

Pup A command line tool aiming to upload the local image used in your markdown file to the GitHub repo and replace the local file path with the return

SteveLau 11 Aug 17, 2022
A Command-line tool to create, manage and deploy your python projects

PPM A Command-line tool to create, manage and deploy your python projects Table of Contents PPM Main Features Create a Project project.ini file Projec

FUSEN 6 Aug 30, 2022
☘️ A simple command line tool to manage your Minecraft Bedrock worlds

☘️ Haze A simple command line tool to manage your Minecraft Bedrock worlds Haze allows you to keep your project's worlds out of the com.mojang directo

Sedge 3 Dec 8, 2022
Plexisort is a command-line tool designed to organize your files based on metadata.

Plexisort is a command-line tool designed to organize your files based on metadata. It allows for flexible source and destination directory settings, supports dry-run operations for safe previews of potential changes, and even offers an undo functionality for reversing the last set of file movements.

Richard Chukwu 7 Apr 29, 2024