Skip to main content

Logo

A Git Repository Secrets Scanner written in Rust

license Python Build PyPi

Table of Contents

About The Project

PyRepScan is a python library written in Rust. The library uses git2-rs for repository parsing and traversing, regex for regex pattern matching and crossbeam for concurrency. The library was written to achieve high performance and python bindings.

Built With

Performance

CPU

Library Time Peak Memory
PyRepScan 8.74s 1,149,152 kb
gitleaks 1118s 1,146,300 kb

Installation

pip3 install PyRepScan

Documentation

class GitRepositoryScanner:
    def __init__(
      self,
    ) -> None

This class holds all the added rules for fast reuse.

def add_content_rule(
    self,
    name: str,
    pattern: str,
    whitelist_patterns: typing.List[str],
    blacklist_patterns: typing.List[str],
) -> None

The add_content_rule function adds a new rule to an internal list of rules that could be reused multiple times against different repositories. The same name can be used multiple times and would lead to results which can hold the same name. Content rule means that the regex pattern would be tested against the content of the files.

  • name - The name of the rule so it can be identified.
  • pattern - The regex pattern (Rust Regex syntax) to match against the content of the commited files.
  • whitelist_patterns - A list of regex patterns (Rust Regex syntax) to match against the content of the committed file to filter in results. Only one of the patterns should be matched to pass through the result. There is an OR relation between the patterns.
  • blacklist_patterns - A list of regex patterns (Rust Regex syntax) to match against the content of the committed file to filter out results. Only one of the patterns should be matched to omit the result. There is an OR relation between the patterns.
def add_file_path_rule(
    self,
    name: str,
    pattern: str,
) -> None

The add_file_path_rule function adds a new rule to an internal list of rules that could be reused multiple times against different repositories. The same name can be used multiple times and would lead to results which can hold the same name. File name rule means that the regex pattern would be tested against the file paths.

  • name - The name of the rule so it can be identified.
  • pattern - The regex pattern (Rust Regex syntax) to match against the file paths of the commited files.
def add_file_extension_to_skip(
    self,
    file_extension: str,
) -> None

The add_file_extension_to_skip function adds a new file extension to the filtering phase to reduce the amount of inspected files and to increase the performance of the scan.

  • file_extension - A file extension, without a leading dot, to filter out from the scan.
def add_file_path_to_skip(
    self,
    file_path: str,
) -> None

The add_file_path_to_skip function adds a new file path pattern to the filtering phase to reduce the amount of inspected files and to increase the performance of the scan. Every file path that would include the file_path substring would be left out of the scanned files.

  • file_path - If the inspected file path would include this substring, it won't be scanned. This parameter is a free text.
def scan(
    self,
    repository_path: str,
    branch_glob_pattern: typing.Optional[str],
    from_timestamp: typing.Optional[int],
) -> typing.List[typing.Dict[str, str]]

The scan function is the main function in the library. Calling this function would trigger a new scan that would return a list of matches. The scan function is a multithreaded operation, that would utilize all the available core in the system. The results would not include the file content but only the regex matching group. To retrieve the full file content one should take the results['oid'] and to call get_file_content function.

  • repository_path - The git repository folder path.
  • branch_glob_pattern - A glob pattern to filter branches for the scan. If None is sent, defaults to *.
  • from_timestamp - A UTC timestamp (Int) that only commits that were created after this timestamp would be included in the scan. If None is sent, defaults to 0.

A sample result would look like this:

{
    'rule_name': 'First Rule',
    'author_email': 'author@email.email',
    'author_name': 'Author Name',
    'commit_id': '1111111111111111111111111111111111111111',
    'commit_message': 'The commit message',
    'commit_time': '2020-01-01T00:00:00e',
    'file_path': 'full/file/path',
    'file_oid': '47d2739ba2c34690248c8f91b84bb54e8936899a',
    'match': 'The matched group',
}
def scan_from_url(
    self,
    url: str,
    repository_path: str,
    branch_glob_pattern: typing.Optional[str],
    from_timestamp: typing.Optional[int],
) -> typing.List[typing.Dict[str, str]]

The same as scan function but also clones a repository from a given URL into the provided repository path.

  • url - URL of a git repository.
  • repository_path - The path to clone the repository to
  • branch_glob_pattern - A glob pattern to filter branches for the scan. If None is sent, defaults to *.
  • from_timestamp - A UTC timestamp (Int) that only commits that were created after this timestamp would be included in the scan. If None is sent, defaults to 0.
def get_file_content(
    self,
    repository_path: str,
    file_oid: str,
) -> bytes

The get_file_content function exists to retrieve the content of a file that was previously matched. The full file content is omitted from the results to reduce the results list size and to deliver better performance.

  • repository_path - The git repository folder path.
  • file_oid - A string representing the file oid. This parameter exists in the results dictionary returned by the scan function.

Usage

import pyrepscan

grs = pyrepscan.GitRepositoryScanner()

# Adds a specific rule, can be called multiple times or none
grs.add_content_rule(
    name='First Rule',
    pattern=r'(-----BEGIN PRIVATE KEY-----)',
    whitelist_patterns=[],
    blacklist_patterns=[],
)
grs.add_file_path_rule(
    name='Second Rule',
    pattern=r'.+\.pem',
)
grs.add_file_path_rule(
    name='Third Rule',
    pattern=r'(prod|dev|stage).+key',
)

# Add file extensions to ignore during the search
grs.add_file_extension_to_skip(
    file_extension='bin',
)
grs.add_file_extension_to_skip(
    file_extension='jpg',
)

# Add file paths to ignore during the search. Free text is allowed
grs.add_file_path_to_skip(
    file_path='site-packages',
)
grs.add_file_path_to_skip(
    file_path='node_modules',
)

# Scans a repository
results = grs.scan(
    repository_path='/repository/path',
    branch_glob_pattern='*',
)

# Results is a list of dicts. Each dict is in the following format:
{
    'rule_name': 'First Rule',
    'author_email': 'author@email.email',
    'author_name': 'Author Name',
    'commit_id': '1111111111111111111111111111111111111111',
    'commit_message': 'The commit message',
    'commit_time': '2020-01-01T00:00:00e',
    'file_path': 'full/file/path',
    'file_oid': '47d2739ba2c34690248c8f91b84bb54e8936899a',
    'match': 'The matched group',
}

# Fetch the file_oid full content
file_content = grs.get_file_content(
    repository_path='/repository/path',
    file_oid='47d2739ba2c34690248c8f91b84bb54e8936899a',
)

# file_content
b'binary data'

# Creating a RulesManager directly
rules_manager = pyrepscan.RulesManager()

# For testing purposes, check your regexes pattern using check_pattern function
rules_manager.check_pattern(
    content='some content1 to check, another content2 in the same line\nanother content3 in another line\n',
    pattern=r'(content\d)',
)

# Results are the list of captured matches
[
    'content1',
    'content2',
    'content3',
]

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Gal Ben David - gal@intsights.com

Project Link: https://github.com/intsights/PyRepScan

Metadata

Release files for pyrepscan 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pyrepscan 0.11.0
File
pyrepscan-0.11.0-cp311-none-win_amd64.whl CPython 3.11 none Windows x86-64 Details
pyrepscan-0.11.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
pyrepscan-0.11.0-cp311-cp311-macosx_10_7_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.7+ x86-64 Details
pyrepscan-0.11.0-cp310-none-win_amd64.whl CPython 3.10 none Windows x86-64 Details
pyrepscan-0.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
pyrepscan-0.11.0-cp310-cp310-macosx_10_7_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.7+ x86-64 Details
pyrepscan-0.11.0-cp39-none-win_amd64.whl CPython 3.9 none Windows x86-64 Details
pyrepscan-0.11.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
pyrepscan-0.11.0-cp39-cp39-macosx_10_7_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.7+ x86-64 Details
pyrepscan-0.11.0-cp38-none-win_amd64.whl CPython 3.8 none Windows x86-64 Details
pyrepscan-0.11.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
pyrepscan-0.11.0-cp38-cp38-macosx_10_7_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.7+ x86-64 Details
pyrepscan-0.11.0-cp37-none-win_amd64.whl CPython 3.7 none Windows x86-64 Details
pyrepscan-0.11.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details
pyrepscan-0.11.0-cp37-cp37m-macosx_10_7_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.7+ x86-64 Details

Total release size: 25.0 MB

Release files / pyrepscan-0.11.0-cp311-none-win_amd64.whl

Download URL pyrepscan-0.11.0-cp311-none-win_amd64.whl
Size 1.1 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
e2dc32becbee0caa27ccf64f512d72760cf2486f4f5e6306fd672b95b41bcccf
BLAKE2b-256 checksum
How to use checksums
dd82c999fe8f4607709e22e99c6acbe26ad8f4752478ef8f6694f63e491ee5cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyrepscan-0.11.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.2 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c3ca55b064f87cc225a15f940939b274530ac4832ded087d2f1b7f6c004d9a33
BLAKE2b-256 checksum
How to use checksums
7220f8a49c0a2235fe097d0f9f1b5c3fb5f00c0b7b6ea7de959a142d0c7d97d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp311-cp311-macosx_10_7_x86_64.whl

Download URL pyrepscan-0.11.0-cp311-cp311-macosx_10_7_x86_64.whl
Size 1.7 MB
Tags CPython 3.11 macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
d3d9a72abdeefae60820beed9f8ad26123a9459fda4015c136e49ce57d3b7811
BLAKE2b-256 checksum
How to use checksums
bdb7a5cfa6757ef103b0fd4f7eb58c39ab4e751642e4179a11ea9b2dfaa8d9a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp310-none-win_amd64.whl

Download URL pyrepscan-0.11.0-cp310-none-win_amd64.whl
Size 1.1 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
21d9784ba5249b4956b2f58d52632e4456daa118f859c80c1ce01bd6a513b60b
BLAKE2b-256 checksum
How to use checksums
f1461210175ac66b63dcdbd8ecf0a53e1845d843cebfed5da98ea6cc76327852
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyrepscan-0.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.2 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
0acb16338c24273ed3bc55fb7a2bacdf2d3111b6b4aa816e05985a4770b34463
BLAKE2b-256 checksum
How to use checksums
b4b94501f319be9cbd0eab02820d5b4aa095723d9bba61745298bc459f76cb55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp310-cp310-macosx_10_7_x86_64.whl

Download URL pyrepscan-0.11.0-cp310-cp310-macosx_10_7_x86_64.whl
Size 1.7 MB
Tags CPython 3.10 macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
4acb8bf8b9fcb002a6fac95ed734131874cf4b605ab1bf81ad00a9774cd493b1
BLAKE2b-256 checksum
How to use checksums
d23e3e0671b336eecaa1dccdb7db8b1dd5e93a33bc0358c01798ee6e31251cfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp39-none-win_amd64.whl

Download URL pyrepscan-0.11.0-cp39-none-win_amd64.whl
Size 1.1 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
efb810ee961e15d5fbe11e3195286b0efa7c4214617346d615acf5561534f87b
BLAKE2b-256 checksum
How to use checksums
8a5141ff3dfd1967cb606c1a56d2e85904dc78f1ce86d95bb50b8531af6a536a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyrepscan-0.11.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.2 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c2fc1667e11446e35881359a3f4a2065e39c9d76d2ee61a418c73d80331faf07
BLAKE2b-256 checksum
How to use checksums
3e628fa10f660208d03599d59891fd217dc4e33454cff1f79e3e561c266981c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp39-cp39-macosx_10_7_x86_64.whl

Download URL pyrepscan-0.11.0-cp39-cp39-macosx_10_7_x86_64.whl
Size 1.7 MB
Tags CPython 3.9 macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
050d8e49175cdb0d4da2554cdcc2992326440bf4bd6320194df0faeff0b78ced
BLAKE2b-256 checksum
How to use checksums
2f2f94ac22a6aad728af3f3d703cfbdb9d0247549a1f59664af05d4c12d696e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp38-none-win_amd64.whl

Download URL pyrepscan-0.11.0-cp38-none-win_amd64.whl
Size 1.1 MB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
1a6dae98d07298833c8ca482cd9dc28ab92a6e1dd9072d806bef6fc33e3200b5
BLAKE2b-256 checksum
How to use checksums
a1f1331faccda982176d4fd0fe48feb1741cd8114d00b7440453f99d655e0518
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyrepscan-0.11.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.2 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
2ffbcee5aca2b4b87045c7e36adc646d9b6a76cf14d3457c3e6ee8a62c35d4f4
BLAKE2b-256 checksum
How to use checksums
b405baccb2ee0b36f1c40918eea2d546039752e0f4696cc7caa127111b315b0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp38-cp38-macosx_10_7_x86_64.whl

Download URL pyrepscan-0.11.0-cp38-cp38-macosx_10_7_x86_64.whl
Size 1.7 MB
Tags CPython 3.8 macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
a0001cf2682197279873b33fb3a0e078d113ee7312de8d70471875991c9c993c
BLAKE2b-256 checksum
How to use checksums
9dc5f38b403f9137c95cefc18697355afb25268b90cc11c76afa4872519bced6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp37-none-win_amd64.whl

Download URL pyrepscan-0.11.0-cp37-none-win_amd64.whl
Size 1.1 MB
Tags CPython 3.7 Windows x86-64
SHA-256 checksum
How to use checksums
3ca36f0c120e5c94c07f3cdc78229675787c9ff1f5212ee5ec4e5b9f07399de9
BLAKE2b-256 checksum
How to use checksums
4cc6d166a86fa8d3ef5478da46e36d7de0d3dc25611dec580914e54e71baa1da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyrepscan-0.11.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.2 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
835ae77a0e159926e9c89eeb7bae80bb44c4217cd9668ab3ff384c872e69f21d
BLAKE2b-256 checksum
How to use checksums
f4b631849eae0ab8f517ada318607846cdd3a6838d4bc11e40f75b6e9145a431
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release files / pyrepscan-0.11.0-cp37-cp37m-macosx_10_7_x86_64.whl

Download URL pyrepscan-0.11.0-cp37-cp37m-macosx_10_7_x86_64.whl
Size 1.7 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
8d918f665e1bab42cec3216fab7434b046ff3923500888d737b07389c9a049e6
BLAKE2b-256 checksum
How to use checksums
49b5a82a11b15b64f48b52331deeebdf74207395423d5642c1e91769e78de42d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.12.20

Release history Release notifications | RSS feed

This release

0.11.0 This release

15 release files

0.9.6

9 release files

0.9.5

6 release files

0.9.4

7 release files

0.9.3

6 release files

0.9.2

12 release files

0.9.1

12 release files

0.9.0

12 release files

0.8.0

12 release files

0.7.4

12 release files

0.7.2

12 release files

0.7.1

9 release files

0.7.0

9 release files

0.6.1

1 release file

0.6.0

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

9 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page