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

Github Oauth2 verification #1584

Merged
merged 6 commits into from
Aug 2, 2023
Merged

Conversation

bill-rich
Copy link
Collaborator

No description provided.

@bill-rich bill-rich requested a review from a team as a code owner July 31, 2023 23:23
@@ -48,13 +56,49 @@ type userRes struct {
// Keywords are used for efficiently pre-filtering chunks.
// Use identifiers in the secret preferably, or the provider name.
func (s Scanner) Keywords() []string {
return []string{"ghp_", "gho_", "ghu_", "ghs_", "ghr_", "github_pat_"}
return []string{"ghp_", "gho_", "ghu_", "ghs_", "ghr_", "github_pat_", "github"}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

github matches means a lot of matches. Something like github_client would cut that down, but could miss creds. I erred on the side of not missing anything, but looking for other opinions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm with you, I think erring on the side of not missing anything makes sense. And to clarify a little bit here, the github keyword would be associated with oauth creds right? Would it make sense to use detectors.PrefixRegex for the oauth regexes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call. Switched.

Copy link
Collaborator

@mcastorina mcastorina left a comment

Choose a reason for hiding this comment

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

Do you think this should be a completely separate detector?

Comment on lines 79 to 82
s1 := detectors.Result{
DetectorType: detectorspb.DetectorType_Github,
Raw: []byte(idMatch[1]),
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If my understanding is correct, we should also have a RawV2: []byte(idMatch[i] + secretMatch[1]).

Copy link
Contributor

Choose a reason for hiding this comment

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

@bill-rich
Copy link
Collaborator Author

Do you think this should be a completely separate detector?

I could see either way on this one. I went with adding it to the existing detector to avoid confusion on github cred types, but I could see being more specific being useful also.

@bill-rich bill-rich requested a review from a team as a code owner August 1, 2023 22:35
var _ detectors.Versioner = (*Scanner)(nil)
var _ detectors.EndpointCustomizer = (*Scanner)(nil)

func (Scanner) Version() int { return 2 }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this needs to be versioned (yet) since it's the only GitHubOauth2 detector.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call. Definitely not v2 at least

Comment on lines +57 to +58
Raw: []byte(idMatch[1]),
RawV2: []byte(idMatch[1] + secretMatch[1]),
Copy link
Contributor

Choose a reason for hiding this comment

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

You can make Raw: []byte(idMatch[1] + secretMatch[1]) and filling omit RawV2
The only reason why RawV2 exists is because we did not capture all of the components of some credentials the first time in the Raw field.

cc @mcastorina for your understanding as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Won't that cause confusion in OSS where the raw value is shown?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, you're right, I didn't consider that aspect. Keep it how it is then.

Comment on lines 18 to 20
var _ detectors.EndpointCustomizer = (*Scanner)(nil)

func (Scanner) DefaultEndpoint() string { return "https://api.github.com" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit (non-blocking): It doesn't look like we're using this endpoint customizer either. I think that can be added in another PR though.

@bill-rich bill-rich merged commit 0c7ed19 into main Aug 2, 2023
8 of 9 checks passed
@bill-rich bill-rich deleted the csm-160_github_oauth2_verification branch August 2, 2023 18:16
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