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

Update Mailgun detector #2679

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rgmz
Copy link
Contributor

@rgmz rgmz commented Apr 6, 2024

Description:

This PR implements the following changes to the Mailgun detector:

  1. Adds key- as a keyword, as it's a unique prefix of one token type

  2. Deduplicates matches in a chunk's data

  3. Updates the detector to use tri-state verification

  4. Adds the domain response as extradata

    βœ… Found verified result πŸ·πŸ”‘
    Detector Type: Mailgun
    Decoder Type: PLAIN
    Raw result: key-3ax6xnjp29jd6fds4gc37jsgvjxtedl0
    Domains: adfewasfdagafdasfdafdf.com (unverified,custom), samples.mailgun.org (ate:active,sandbox)
    Commit: 8b4342e2eb4f56deb646d3c56001c904712deb34
    Email: John Mailgun <john@mailgunhq.com>
    ...
    
  5. Fixes what appears to be a bug in the verification logic

    This line of code does not seem to do what it the comment claims.

    // If resMatch has "key" prefix, use it as the username for basic auth.
    if strings.HasPrefix(resMatch, "key-") {
    req.SetBasicAuth("api", resMatch)
    } else {
    req.Header.Add("Authorization", fmt.Sprintf("Basic %s", resMatch))
    }

    Mailgun seems to require basic auth for all token tokens. The way this logic is written means that key- tokens will be properly verified, but other types like "Hex" won't be unless they happen to be base64-encoded and 72 characters (so they match the "Original MailGun Token" regex).

    e.g., this is a a base-64 encoded hex key that only gets detected because it happens to match the "Original" pattern.

        Authorization:
        - Basic YXBpOmQwMTViNWNkYjlhNTgzNjg1ZDhkM2ZiMWJlYzBmMjBkLTA3YmM3YjA1LWRhNDgxNmEx
    

    If it was instead found in plain-text like below, it would be skipped.

    mailgun_key = 'd915b5cdb9a583685d8f3fb1bec0f20f-07bc7b05-fa4816a1'
    

    I'm partially convinced that the "Original MailGun Token" is just the hex token base64-encoded.

Checklist:

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

@rgmz rgmz marked this pull request as ready for review April 6, 2024 15:34
@rgmz rgmz force-pushed the feat/mailgun-extradata branch 4 times, most recently from b5ada5b to 42a8340 Compare April 12, 2024 11:20
@rgmz rgmz force-pushed the feat/mailgun-extradata branch 3 times, most recently from e5ca5fc to a256f43 Compare May 22, 2024 20:02
@rgmz rgmz force-pushed the feat/mailgun-extradata branch 2 times, most recently from 0761b6d to 805dcf5 Compare May 24, 2024 21:37
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.

None yet

1 participant