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 rayon for concurrency. The library was written to achieve high performance and python bindings.

Built With

Performance

CPU

Library Time Peak Memory
PyRepScan 4s 501,708 kb
gitleaks 507s 823,016 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 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.7.3

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.7.3
File
pyrepscan-0.7.3-cp39-none-win_amd64.whl CPython 3.9 none Windows x86-64 Details
pyrepscan-0.7.3-cp39-cp39-manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
pyrepscan-0.7.3-cp39-cp39-macosx_10_7_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.7+ x86-64 Details
pyrepscan-0.7.3-cp38-none-win_amd64.whl CPython 3.8 none Windows x86-64 Details
pyrepscan-0.7.3-cp38-cp38-manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
pyrepscan-0.7.3-cp38-cp38-macosx_10_7_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.7+ x86-64 Details
pyrepscan-0.7.3-cp37-none-win_amd64.whl CPython 3.7 none Windows x86-64 Details
pyrepscan-0.7.3-cp37-cp37m-manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details
pyrepscan-0.7.3-cp37-cp37m-macosx_10_7_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.7+ x86-64 Details
pyrepscan-0.7.3-cp36-none-win_amd64.whl CPython 3.6 none Windows x86-64 Details
pyrepscan-0.7.3-cp36-cp36m-manylinux2014_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64 Details
pyrepscan-0.7.3-cp36-cp36m-macosx_10_7_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.7+ x86-64 Details

Total release size: 10.5 MB

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

Download URL pyrepscan-0.7.3-cp39-none-win_amd64.whl
Size 1.0 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
78f5bc26cba2a0899590441e50939ee9a1d174bfde260cf981d94f0ea4894fae
BLAKE2b-256 checksum
How to use checksums
fc5b8b83f74bf8537a9c1b5feab251daf3f29688f06eb9f31b4fef364120b64e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.8.3

Release files / pyrepscan-0.7.3-cp39-cp39-manylinux2014_x86_64.whl

Download URL pyrepscan-0.7.3-cp39-cp39-manylinux2014_x86_64.whl
Size 845.2 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
2c67429350672c94b5e8439c464c6e9c5cf193b22eb26f6bb9f482602f053632
BLAKE2b-256 checksum
How to use checksums
863207aade292bb3808431e0c415ab48e5540f56923c8448ede47f8b063b72f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.8.3

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

Download URL pyrepscan-0.7.3-cp39-cp39-macosx_10_7_x86_64.whl
Size 745.6 kB
Tags CPython 3.9 macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
e79703f4f0554cdb562405bd90f64bc8952ebadc63ced828843ad41b813bd4f9
BLAKE2b-256 checksum
How to use checksums
9d9ad585e945c4adea1a6fe4203b3b40ab4caae9aeca0cf22ce8a3f64df76943
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.8.3

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

Download URL pyrepscan-0.7.3-cp38-none-win_amd64.whl
Size 1.0 MB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
3e587da6c9826cc749cf2f06eaca11ec52ea835d023b187126bfe816c18c1265
BLAKE2b-256 checksum
How to use checksums
cdaf5816abcf6a8be704e6938ec680cf54f63cf7d920df448ee24dfaca97a849
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.8.3

Release files / pyrepscan-0.7.3-cp38-cp38-manylinux2014_x86_64.whl

Download URL pyrepscan-0.7.3-cp38-cp38-manylinux2014_x86_64.whl
Size 845.2 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
35a44ca6328b8c9e4ce017da5083ce874793cba34abf114a173a3d25768cdcab
BLAKE2b-256 checksum
How to use checksums
a29d296a04de4b0997a0ae507725c111fa6fb494ea2a5770b4836d6506831bbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.8.3

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

Download URL pyrepscan-0.7.3-cp38-cp38-macosx_10_7_x86_64.whl
Size 745.6 kB
Tags CPython 3.8 macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
14da2457e99d0d26f8cf174174942e41b2d14cc6394ee5aae46aa382424d1029
BLAKE2b-256 checksum
How to use checksums
8c10e584ff1947133663ef9c9ade43cfb2416b818c9671b72d46a743077c040c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.8.3

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

Download URL pyrepscan-0.7.3-cp37-none-win_amd64.whl
Size 1.0 MB
Tags CPython 3.7 Windows x86-64
SHA-256 checksum
How to use checksums
792e16991b18cbb0f2b49d8be3d0f6bbfee2a9bfd7544f39f815eb75002cb33a
BLAKE2b-256 checksum
How to use checksums
d9c89e1eff74c6e5e828c817a379aedbde01eda6bccc0598da18a194b67bac8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.8.3

Release files / pyrepscan-0.7.3-cp37-cp37m-manylinux2014_x86_64.whl

Download URL pyrepscan-0.7.3-cp37-cp37m-manylinux2014_x86_64.whl
Size 845.2 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
bc9363e48e6d1253db6e0e49aa321104a9f6f7bec5d1ebf5ea332eb402168afb
BLAKE2b-256 checksum
How to use checksums
cc0e52930fc1f26c0d71a4c2cf8c7cdd5fae05abbd4fb251be9a29d9157af2a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.8.3

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

Download URL pyrepscan-0.7.3-cp37-cp37m-macosx_10_7_x86_64.whl
Size 745.6 kB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
5cd6e3cbf60f8cd33ad4021602ab0c6e4974cadac6a6a6fd0814a49105c14b3a
BLAKE2b-256 checksum
How to use checksums
6154d40dede5cc9fb2327aecd147a4535f15491c3295f4973681e7e5db1b7fbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.8.3

Release files / pyrepscan-0.7.3-cp36-none-win_amd64.whl

Download URL pyrepscan-0.7.3-cp36-none-win_amd64.whl
Size 1.0 MB
Tags CPython 3.6 Windows x86-64
SHA-256 checksum
How to use checksums
a725ded7ff39ad42e06d08255634c246bef3ac2d302d0be55b0c673841174444
BLAKE2b-256 checksum
How to use checksums
f7b5777bba9c2f63c608455544ad310c57cc21d695091e520a1d2e89dcb0cb98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.8.3

Release files / pyrepscan-0.7.3-cp36-cp36m-manylinux2014_x86_64.whl

Download URL pyrepscan-0.7.3-cp36-cp36m-manylinux2014_x86_64.whl
Size 845.6 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
403f687202b3896fc1f22195a2dec83556f4cb6e4d3747666e6ef108c4a288ca
BLAKE2b-256 checksum
How to use checksums
e1b74ea10d05c84a07520e63c119b43f86c36c1aa75889a49769d73615ffb40b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.8.3

Release files / pyrepscan-0.7.3-cp36-cp36m-macosx_10_7_x86_64.whl

Download URL pyrepscan-0.7.3-cp36-cp36m-macosx_10_7_x86_64.whl
Size 745.9 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.7+ x86-64
SHA-256 checksum
How to use checksums
ad06bdbb63197bec22a80eb60146cfd9fc26fffde2df9a75b18842becd559ae2
BLAKE2b-256 checksum
How to use checksums
b903d846994fdb687f4a31e3bbd91e79ce9b63e5fce188790225fcbe1fc6c5ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.8.3

Release history Release notifications | RSS feed

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

This release

0.7.3 This release

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