-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Stripe Payment Intent Detector #4138
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
Stripe Payment Intent Detector #4138
Conversation
d86d855
to
5c6e35c
Compare
ce5a490
to
7166ebf
Compare
// 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{"pi_", "_secret_", "sk_live_", "rk_live_", "pk_live_"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shahzadhaider1 the keywords pi_
and _secret_
, seem like they might occur quite frequently across many files and could result in a high number of false positives. The existing stripe detector only uses k_live_
, I'm wondering if that would help make it more specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing stripe detector only uses k_live_, I'm wondering if that would help make it more specific.
pi_
or _secret_
are the only ones relevant to this specific detector. 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Richard also mentioned, pi_
and _secret_
keywords are relevant to this detector, so it wouldn't make sense to get rid of these keywords. Please let us know what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rgmz @shahzadhaider1 since both substrings pi_
and _secret_
are part of the secret, I would suggest using only _secret_
, since including both will theoretically yield more false matches, and pi_
looks like it may be more common out of the two, e.g. it would match inputs with that contain api_
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. We have only _secret_
keyword now
0516be7
to
f7d6e1f
Compare
publishableKeys := extractMatches(publishableKeyPat, dataStr) | ||
|
||
for clientSecret := range clientSecrets { | ||
result := createResult(clientSecret, false, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we pass verification as false, will the result only include client secrets without the secret key or publishable key? If so, the result would be largely meaningless in my opinion, since a client secret without either of those isn't useful on its own. We should create result only if we find either secret key or publishable key along with client secret. Than if verification fails we can mark it as unverified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we pass verification as false, will the result only include client secrets without the secret key or publishable key?
The result will always include only client secrets as the requirement for this detector is to detect client secrets in the Stripe Payment Intent objects. For detecting Stripe secret keys, we have another detector in place.
We should create result only if we find either secret key or publishable key along with client secret. Than if verification fails we can mark it as unverified.
I understand that client secret without a key is not very useful but since the requirement is to detect the client secrets and doing this will mean that if a data source contains only client secrets and no keys, we will never be able to detect the client secrets. Are you sure we want that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to be a blocker here. Just leaving my thoughts as a comment. If others feel the same as you do, feel free to move forward with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your feedback. I really appreciate it.
Let's see what other teammates suggest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @kashifkhan0771 that a client secret on its own does not seem to be meaningful unless a secret or publishable key is also detected, as you cannot use it or verify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kashifkhan0771 @nabeelalam I have updated the implementation based on your suggestion. I have also updated the PR description with latest implementation details. Please re-review and let me know what you think.
1a90845
to
32a6a7c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
5a5b61d
to
1a7e53c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few non-blocking comments. The code looks clean to me!
15c43d5
to
5eea834
Compare
case http.StatusOK: | ||
return true, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the response contains the valid client_secret
of a requested payment intent. Verification should be based on comparison of what is detected and what client_secret
is in response. Does it make sense ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done - the implementation now reads the response body and verifies the detected client secret by comparing it with the value returned from the API, rather than relying solely on the API status code.
}{ | ||
{ | ||
name: "client secret with secret key", | ||
input: "stripepaymentintent_token = '" + validClientSecret + "' and stripe_key = '" + validSecretKey + "'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we copy input variables values here directly? this is to improve the code readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done - I have removed all variables and used strings here directly.
518d82e
to
7af3f2b
Compare
df5712f
to
9e51e97
Compare
9e51e97
to
6ee6227
Compare
6ee6227
to
be42605
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making all the updates @shahzadhaider1 !
…s against all keys
be42605
to
21d6e08
Compare
Description:
This PR introduces support for detecting Stripe PaymentIntent client secrets with comprehensive key-based verification.
Summary of Changes:
pi_*_secret_*
format).Key Implementation Details:
Verification Status:
Result Structure:
Testing:
Example Scenarios:
Checklist:
make test-community
)?make lint
this requires golangci-lint)?