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

fixed sentry auth token detector #3827

Merged

Conversation

kashifkhan0771
Copy link
Contributor

Description:

This Pull request fixes github issue #3575
Screenshot from 2025-01-01 14-05-59

Checklist:

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

@kashifkhan0771 kashifkhan0771 requested a review from a team as a code owner January 1, 2025 09:42
@kashifkhan0771 kashifkhan0771 linked an issue Jan 1, 2025 that may be closed by this pull request

return isVerified, err
// if response contain the forbiddenError message it means the token is active but does not have the right scope for this API call
if strings.Contains(fmt.Sprintf("%v", responseBody), forbiddenError) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case the token is Active and does not have the org:<> scope the API returns 403 with a specific error message. In case token is removed the API return 401

@@ -20,7 +20,7 @@ import (
func TestSentryToken_FromChunk(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors3")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

detectors3 vault limit is full

wantVerificationErr: true,
},
{
name: "found, good key but wrong scope",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed some tests which are not necessary.

@kashifkhan0771 kashifkhan0771 requested a review from a team as a code owner January 1, 2025 10:13
pkg/detectors/sentrytoken/sentrytoken.go Outdated Show resolved Hide resolved
pkg/detectors/sentrytoken/sentrytoken.go Outdated Show resolved Hide resolved
pkg/detectors/sentrytoken/sentrytoken.go Outdated Show resolved Hide resolved
pkg/detectors/sentrytoken/sentrytoken.go Outdated Show resolved Hide resolved
pkg/detectors/sentrytoken/sentrytoken.go Outdated Show resolved Hide resolved
@kashifkhan0771 kashifkhan0771 requested a review from rgmz January 2, 2025 06:38
@kashifkhan0771 kashifkhan0771 self-assigned this Jan 10, 2025

var (
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
keyPat = regexp.MustCompile(`\b(sntryu_[a-f0-9]{64})\b`)
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this is missing sntrys_ tokens mentioned in #3575.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is the Sentry ORG token pattern. Organization auth tokens have a limited set of scopes and lack access to many APIs. These tokens are primarily used for sentry-cli operations; you can find more details here. If needed, I’d recommend creating a separate detector specifically for ORG tokens.

Copy link
Contributor

Choose a reason for hiding this comment

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

Regardless, it was explicitly mentioned in #3575. Either the issue should be re-opened until it's added, or it should be updated with a rationale why only one was added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the docs: Organization Auth Tokens can be used in many places to interact with Sentry programatically. For example, they can be used for sentry-cli, bundler plugins or similar uses cases.

I will add this in issue comments as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

That doesn't really say why it isn't worth detecting, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can detect them but my point is how do we verify them? The organization auth token are used in sentry-cli for mainly two purposes:

  • Uploading source maps: The SolidStart guide shows an example of using an organization auth token to upload source maps using the sentrySolidStartVite plugin.
  • CI/CD environments: Organization auth tokens are recommended for use in CI/CD environments, as mentioned in the SolidStart guide.

Note: This information is provided by Sentry AI Docs

@kashifkhan0771 kashifkhan0771 merged commit 39d2453 into trufflesecurity:main Jan 20, 2025
13 checks passed
@kashifkhan0771 kashifkhan0771 deleted the fix/github-issue-3575 branch January 20, 2025 10:31
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.

Sentry Auth Token not detected
3 participants