menu
  • Module trufflehog3.search

    Supported search algorithms.

Functions
            
                

                def search(
    file: File,
    rules: Iterable[Union[EntropyPattern]],
    exclude: Iterable[Exclude] = None,
    ignore_nosecret: bool = False,
    context: int = 0,
) ‑> Iterable[Issue]
open_in_new

Return issues found using provided rules.

Examples

Entropy-based search

>>> rule = Entropy()
>>> file = File(
...     path="/path/to/code.py",
...     content="password = 'abcdefghijklmnopqrstuvwxyz'",
... )
>>> for issue in search(file, [rule]):
...     print(issue.secret)
abcdefghijklmnopqrstuvwxyz

Pattern-based search

>>> rule = Pattern(
...     id="bad-password-letmein",
...     message="Bad Password 'letmein'",
...     pattern="letmein",
...     severity="high",
... )
>>> file = File(
...     path="/path/to/code.py",
...     content="password = 'letmein'",
... )
>>> for issue in search(file, [rule]):
...     print(issue.secret)
letmein

With exclude

>>> exc = Exclude(message="Not a secret", paths=["*.py"])
>>> len(search(file, [rule], exclude=[exc]))
0

With inline exclude

>>> file = File(
...     path="/path/to/code.py",
...     content="password = 'letmein'  # nosecret",
... )
>>> len(search(file, [rule]))
0
>>> file = File(
...     path="/path/to/code.py",
...     content="password = 'letmein'  # nosecret: bad-password-letmein",
... )
>>> len(search(file, [rule]))
0
            
                

                def searchiter(
    file: File,
    rules: Iterable[Union[EntropyPattern]],
    exclude: Iterable[Exclude] = None,
    ignore_nosecret: bool = False,
    context: int = 0,
) ‑> Iterator[Issue]
open_in_new

Yield issues found using provided rules.