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

[fix] - Dropbox detector #3406

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

[fix] - Dropbox detector #3406

wants to merge 8 commits into from

Conversation

ahrav
Copy link
Collaborator

@ahrav ahrav commented Oct 14, 2024

Description:

This PR fixes the Dropbox detector. The original regex was incorrect, and I confirmed that we never successfully verified a Dropbox token, which aligns with the regex issue.

I also added a test token since one wasn't included before.

I think I did this correctly given then new detector format. 🤞

Checklist:

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

@ahrav ahrav requested review from a team October 14, 2024 17:35
@ahrav ahrav marked this pull request as ready for review October 14, 2024 17:43

// Ensure the Scanner satisfies the interface at compile time.
var _ detectors.Detector = (*Scanner)(nil)

var (
keyPat = regexp.MustCompile(`\b(sl\.[A-Za-z0-9\-\_]{130,140})\b`)
defaultClient = common.SaneHttpClient()
keyPat = regexp.MustCompile(`sl\.u\.[0-9a-zA-Z_-]+`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all the tokens as long as in the test? It's probably worth putting a minimum range here.

E.g., there's no point in trying for sl.u.a

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, that makes sense. The 5 that I generated were all 1309 characters long.

Copy link
Contributor

Choose a reason for hiding this comment

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

The 5 that I generated were all 1309 characters long.

Idk if they're all consistently 1,000+ characters. Even {250,} would likely be sufficient.

Copy link
Contributor

@abmussani abmussani left a comment

Choose a reason for hiding this comment

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

Thanks @ahrav for taking this up. Your changes looks good to me. I tried to generate the access token for an app. The token generated for my account does not seems to be started with sl.u. and the length is 143 characters. I generated multiple times and seeing the same pattern. Could be possible that I am looking at wrong place.

Screenshot 2024-10-15 at 9 39 18 AM

@ahrav
Copy link
Collaborator Author

ahrav commented Oct 15, 2024

Thanks @ahrav for taking this up. Your changes looks good to me. I tried to generate the access token for an app. The token generated for my account does not seems to be started with sl.u. and the length is 143 characters. I generated multiple times and seeing the same pattern. Could be possible that I am looking at wrong place.

Screenshot 2024-10-15 at 9 39 18 AM

Sorry for the confusion! This PR is for Dropbox, while yours adds a new Box detector.😂 They are similar, but Box is aimed at larger teams, while Dropbox is more for individuals. I don’t think they’re related.😅

@ahrav
Copy link
Collaborator Author

ahrav commented Oct 15, 2024

Thanks @ahrav for taking this up. Your changes looks good to me. I tried to generate the access token for an app. The token generated for my account does not seems to be started with sl.u. and the length is 143 characters. I generated multiple times and seeing the same pattern. Could be possible that I am looking at wrong place.

Screenshot 2024-10-15 at 9 39 18 AM

Sorry for the confusion! This PR is for Dropbox, while yours adds a new Box detector.😂 They are similar, but Box is aimed at larger teams, while Dropbox is more for individuals. I don’t think they’re related.😅

I was reviewing your PR and got confused too. While creating a token, I noticed it was too big and realized these are two separate services. Since I had the token, I tested our existing Dropbox detector and saw it was broken, so I decided to fix it. Sorry for not making that clearer earlier.

@ahrav
Copy link
Collaborator Author

ahrav commented Oct 15, 2024

@abmussani dosregard my last comment. You are also referring to Dropbox 🤦 I'll take a second look at thid when I'm back at my laptop. I think you are correct, there might be two different tokens here...


// Ensure the Scanner satisfies the interface at compile time.
var _ detectors.Detector = (*Scanner)(nil)

var (
keyPat = regexp.MustCompile(`\b(sl\.[A-Za-z0-9\-\_]{130,140})\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 pattern matches older tokens. I've found several examples where the tail was 150. Perhaps both the new and old are necessary?

The new is sl.u., the old (?) is sl.B.

\b(sl\.B[A-Za-z0-9\-\_]{129,200})\b

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, that seems to track. I'll update a little later today. Thank you both ❤️

Copy link
Contributor

Choose a reason for hiding this comment

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

There's no period after the B.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are two types of tokens: an API explorer token, which is longer, and a regular access token, which is shorter. Should I create separate regex patterns for each or use separate detectors? I’m thinking separate detectors.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are the endpoints and verification logic the same? You could create separate detectors but reuse the same logic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I updated the PR to include both credentials in the test but left everything else unchanged. The endpoint seems to work for both, with the only difference being the token. 😅 Yea, okay i'll do that. 👍

@ahrav ahrav requested a review from abmussani October 15, 2024 17:55
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