Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Feature/config verification #2311

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

zricethezav
Copy link
Collaborator

@zricethezav zricethezav commented Jan 18, 2024

Description:

Gives users the ability to perform custom detector verification without having to spin up a verification server. With this feature TruffleHog makes the requests straight to the provider server much like a regular built-in detector.

ex config:

# config.yaml
detectors:
  - name: airtable detector
    keywords:
      - airtable
    regex:
      appRes: (app[a-zA-Z0-9_-]{14})
      keyPat: \b(key[a-zA-Z0-9_-]{14})\b
    verify:
      - endpoint: "https://api.airtable.com/v0/{$appRes}/Projects"
        directVerify: true
        unsafe: true
        httpMethod: "GET"
        headers:
          - "Authorization: Bearer {$keyPat}"
          - "x-api-key: {$appRes}"
        successRanges:
          - "2xx"
          - "300"
          - "301"
        successBodyContains:
          - "success"

  - name: artsy detector
    keywords:
      - artsy
    regex:
      keyPat: (?i)(?:artsy)(?:.|[\n\r]){0,40}\b([0-9a-zA-Z]{32})\b
      idPat: (?i)(?:artsy)(?:.|[\n\r]){0,40}\b([0-9a-zA-Z]{20})\b
    verify:
      - endpoint: "https://api.artsy.net/api/tokens/xapp_token?client_id={$idPat}&client_secret={$keyPat}"
        directVerify: true
        unsafe: true
        httpMethod: "POST"
        successRanges:
          - "2xx"
        successBodyContains:
          - "expires_at"

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@zricethezav zricethezav requested a review from a team as a code owner January 18, 2024 19:07
@zricethezav zricethezav marked this pull request as draft January 18, 2024 19:09
@dustin-decker
Copy link
Contributor

I think we'll need a way to reference test secrets for this and to be able to run tests easily.

Also, if we port any existing detectors we will need a way to specify raw and rawv2 field mapping to the regexes. That part would only be needed for porting detectors, not for new ones.

@zricethezav
Copy link
Collaborator Author

Also, if we port any existing detectors we will need a way to specify raw and rawv2 field mapping to the regexes. That part would only be needed for porting detectors, not for new ones.

We could add something like an internal entry that dictates how we want to handle raw and rawv2. We could include options to use specific capture groups if the regexes have more than one capture group (not sure if any of are detectors do, but just an idea)

  - name: artsy detector
    keywords:
      - artsy
    regex:
      keyPat: (?i)(?:artsy)(?:.|[\n\r]){0,40}\b([0-9a-zA-Z]{32})\b
      idPat: (?i)(?:artsy)(?:.|[\n\r]){0,40}\b([0-9a-zA-Z]{20})\b
    verify:
      - endpoint: "https://api.artsy.net/api/tokens/xapp_token?client_id={$idPat}&client_secret={$keyPat}"
        directVerify: true
        unsafe: true
        httpMethod: "POST"
        successRanges:
          - "2xx"
        successBodyContains:
          - "expires_at"
    internal:
         raw: {$idPat}:{$keyPat}
         rawv2: {$idPat}

@mcastorina
Copy link
Collaborator

mcastorina commented Mar 15, 2024

I really like this idea! What do you think about using an existing templating engine instead of string replacement? I ask because there are weird edge-cases other libraries have already solved (like.. {$double{$nested}shenanigans}). mustache could be an option.

@rosecodym
Copy link
Collaborator

I also strongly support at least investigating the use of an existing template engine.

Also, does your draft handle verification indeterminacy yet?

@zricethezav
Copy link
Collaborator Author

What do you think about using an existing templating engine instead of string replacement?

I have a preference for keeping things simple until the need arises for an external library. Do you have an example of an edge case?

Also, does your draft handle verification indeterminacy yet?

No. As stated in the description this draft is for enhancing the existing custom config. It is not meant to be a replacement for the existing detectors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants