-
Notifications
You must be signed in to change notification settings - Fork 461
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
Properly override API version if it's set in the request #814
Conversation
@remi-stripe Doh, I think ephemeral keys overriding the version is actually by design right? func (c Client) New(params *stripe.EphemeralKeyParams) (*stripe.EphemeralKey, error) {
if params.StripeVersion == nil || len(stripe.StringValue(params.StripeVersion)) == 0 {
return nil, fmt.Errorf("params.StripeVersion must be specified")
}
if params.Headers == nil {
params.Headers = make(http.Header)
}
params.Headers.Add("Stripe-Version", stripe.StringValue(params.StripeVersion))
ephemeralKey := &stripe.EphemeralKey{}
err := c.B.Call(http.MethodPost, "/v1/ephemeral_keys", c.Key, params, ephemeralKey)
return ephemeralKey, err
} IIRC, the idea here was that ephemeral keys require an explicit version in order to get a more explicit compatibility guarantee for a client out in the field like an iOS app that may have a long app store review cycle to get it even updated. I was going to suggest the same fix that it looks like you came up with in #811 — not super optimal because it means we're not really testing anything interesting, but at least gets everything passing. |
@brandur-stripe The issue is that the code today does not work at all while my fix does. This is due to the code using |
@remi-stripe Doesn't it still produce the wrong result though? The |
@brandur-stripe It does not get added first. I got confused by this too! The code you shared does not add the header to the request, it adds the header to the params:
Then in
Then, at the end of
This would add the version from the |
Ah, shoot, I see! I misread that — you're totally right. In that case, I think using I'd even optimistically release this one without a major version bump just because the previous code was broken and ephemeral keys probably have relatively low use, but I'll leave that up to you. |
Yeah I was hesitating, but since the other PR is a breaking change, it's just easier to do both at once and fix the behaviour. Since I'm not really familiar with Go myself, are you sure this is really safe to do and the right fix? |
I think it's strictly better than what we had before. (For Ruby/Rack I think it's the last one received which means that this might've actually worked when sent to Stripe, but I'd have to run some tests to be sure of that.) Changing to The only problem I can potentially think of is that someone could exploit this to override the default API version that stripe-go is tied to by just arbitrarily making sure to set |
thanks a lot for the detailed explanation, this makes perfect sense. |
Released as 58.0.0. |
While testing the
strict-version-check
flag, I discovered that we were incorrectly overriding the version forced in the request creating ephemeral keys.This fixes the issue by calling
Set
instead ofAdd
. I've confirmed it works, but I'm not sure this is the right approach here.Marking as a breaking change since Ephemeral Keys would suddenly be created with the correct API version, which is what people would likely want, but still a dangerous change. There's also another major version going out anyway.
r? @brandur-stripe
cc @stripe/api-libraries