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

feat [detector]: added hasura detector #3427

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sahil9001
Copy link
Contributor

@sahil9001 sahil9001 commented Oct 16, 2024

Description:

Relates to #3424
This PR introduces a new detector for Hasura GraphQL Engine admin secrets. Hasura is a popular open-source engine that provides instant GraphQL APIs over databases. Detecting exposed Hasura admin secrets is crucial for preventing unauthorized access to GraphQL APIs and underlying databases.

Tests:
Screenshot 2024-10-16 at 8 15 47 PM

Checklist:

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

@sahil9001 sahil9001 requested a review from a team as a code owner October 16, 2024 10:34
@sahil9001 sahil9001 changed the title [wip] detector feat: added hasura detector feat [detector]: added hasura detector Oct 16, 2024
@sahil9001
Copy link
Contributor Author

@rgmz This is ready for review, can you please check?

@ahrav
Copy link
Collaborator

ahrav commented Oct 16, 2024

Oh wow, I can't believe we didn't have a Hasura detector. This is great, thanks @sahil9001 ❤️

if len(match) != 2 {
continue
}
key := strings.TrimSpace(match[1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would base your implementation on the Alchemy example. This line len(match) != 2, strings.TrimSpace, etc. are old practices that aren't ideal. https://github.com/trufflesecurity/trufflehog/blob/main/pkg/detectors/alchemy/alchemy.go

I'd recommend using the steps linked in CONTRIBUTING.md, as it will generate a detector that has solid logic + integration and unit tests.
https://github.com/trufflesecurity/trufflehog/blob/main/CONTRIBUTING.md#adding-new-secret-detectors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did use that only, which gave me this logic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that doesn't make sense. The code in Alchemy is completely different from this, it was changed at least several months ago. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, my bad, I changed the logic from some other detector though, was just talking about the generation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon talking with Zach, I got to know that we are deprioritising adding a new detector code as it doesn't qualify for Hacktoberfest

continue
}
defer res.Body.Close()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify should be a separate function to mitigate issues with defer inside a for loop.
https://stackoverflow.com/questions/45617758/proper-way-to-release-resources-with-defer-in-a-loop

continue
}

if res.StatusCode >= 200 && res.StatusCode < 300 && len(response.Errors) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status code check should be specific. Ranges are error-prone.

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.

3 participants