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

"Invalid hash" when trying to upload a file #742

Closed
mikker opened this issue Feb 11, 2019 · 8 comments
Closed

"Invalid hash" when trying to upload a file #742

mikker opened this issue Feb 11, 2019 · 8 comments
Assignees
Labels

Comments

@mikker
Copy link

mikker commented Feb 11, 2019

I get these 400 Invalid request errors when trying to upload files. Haven't touched a thing since it was working a few days ago.

Rails 5.2.2.

[8] pry(main)> Stripe::File.create(purpose: 'identity_document', file: File.new('spec/fixtures/success.png'))
INFO Request to Stripe API api_version=2018-11-08 method=post num_retries=0 path=/v1/files
DEBU Request details body="purpose=identity_document&file=FILE%3Asuccess.png"
INFO Response from Stripe API api_version=2018-11-08 elapsed=4.50567 method=post path=/v1/files request_id=req_9Wb6rWuni6BANm status=400
DEBU Response details body="{  \"error\": {    \"message\": \"Invalid hash\",    \"param\": \"file\",    \"type\": \"invalid_request_error\"  }}" request_id=req_9Wb6rWuni6BANm
DEBU Dashboard link for request request_id=req_9Wb6rWuni6BANm url="https://dashboard.stripe.com/test/logs/req_9Wb6rWuni6BANm"
ERRO Stripe API error status=400 error_message="Invalid hash" error_param=file error_type=invalid_request_error request_id=req_9Wb6rWuni6BANm
Stripe::InvalidRequestError: Invalid hash
from /Users/mikker/.gem/ruby/2.6.1/gems/stripe-4.8.0/lib/stripe/stripe_client.rb:361:in `handle_error_response'
Caused by Faraday::ClientError: the server responded with status 400
from /Users/mikker/.gem/ruby/2.6.1/gems/faraday-0.15.4/lib/faraday/response/raise_error.rb:13:in `on_complete'
@ob-stripe
Copy link
Contributor

Hi @mikker, thanks for the report. It looks like file uploading is broken in the latest version :/ If you downgrade the stripe gem to 4.7.1, file uploads should work once again.

We'll release a fix soon. Sorry for the inconvenience!

@mikker
Copy link
Author

mikker commented Feb 11, 2019

Looks like you are right. A rogue spring process had me confused at first but indeed downgrading fixes the problem. (Why didn't the specs catch this? Just curious – they look reasonable)

No worries 👍

@ob-stripe
Copy link
Contributor

With stripe 4.8.0, the file contents are replaced by "FILE:success.png" (the intention was that this would only happen in logs). We use stripe-mock in our test suite, and unfortunately it doesn't validate file contents, so the tests didn't catch the issue.

@ob-stripe
Copy link
Contributor

@brandur-stripe This was a regression caused by #741. As far as I can tell this happens because we call params_encoder.encode(body) when creating the request log context, which modifies the body hash and replaces the Faraday::UploadIO instance with the loggable string before body is passed to Faraday in conn.run_request.

The simplest way to fix this would be to drop replace_faraday_io altogether, but maybe you can come up with something nicer?

@mikker
Copy link
Author

mikker commented Feb 11, 2019

Sounds like something I could've done myself. Thanks for the swift response.

brandur-stripe pushed a commit that referenced this issue Feb 11, 2019
In #741 I tried to do something too clever by replacing instances of
`Faraday::UploadIO` found in parameters with a human-readable string to
improve `STRIPE_LOG` logging output.

I thought I'd tested it at the time, but apparently not (or not well
enough), and this change caused the regression detailed in #742.

My findings about how Faraday encodes multipart were apparently wrong
and it does use these parameters, so here we remove the step where we
try to nicen them for logging. The logs look a little worse, but it's
not that big of a deal.

I've tested this patch against the API and confirmed that it addresses
the problem.

Fixes #742.
@brandur-stripe
Copy link
Contributor

Yikes, sorry about the trouble here @mikker! I tested the change at the time and it seemed to be working, but I was only testing against stripe-mock, and it was apparently producing a different result than the API.

Added a fix in #743 and we'll release ASAP.

@brandur-stripe
Copy link
Contributor

Released a fix in 4.8.1.

@mikker
Copy link
Author

mikker commented Feb 11, 2019

Don't worry! Glad to have it solved 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants