-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Sinatra leaks sensitive information from any exception with an http_status
attribute
#1518
Comments
Add an error handler to your app to modify the response body. error Stripe::InvalidRequestError do
"boom"
end |
Looking at this, it seems the exception message will be printed to the body if it is http status 400 or 404. Still not good. See Line 1132 in 26fa5c8
I'm wondering why there isn't a |
@jkowens I also reprod it with 401 when I was diagnosing it. Didn't dig any deeper into the exact status codes affected, though. |
@mwpastore We'll work around it now that we know. But the problem is that I've never heard of this in ten years of using Sinatra. And we only discovered it because we happened to see an unhandled |
By extending Sinatra::Error, an error class can set the http status code on the response to a value other than 500. This commit fixes issues sinatra#1204 and sinatra#1518 where an error raised by a third party library that responded to http_status could set the status on the response. Any error outside of Sinatra errors will now always return a 500 status. This fixes an issue where an exception could leak sensitive data in the message to the browser. Errors that have http_status code 400 or 404 use the message as the body of the response. This is why it is imperative that these errors extend Sinatra::Error so that this is an explicit decision.
It looks like Sinatra has tried to set the |
This is an API design issue, not a bug. By reporting this issue, I could recognize the problem on the API design. At least, we can take a following action:
|
I don't think that mentioning |
@garybernhardt I don't say that mentioning in the document will solve this problem. I said that it's important to clarify the matter until the problem is solved in the future. |
@namusyaka Got it, thanks for clarifying and sorry for misunderstanding! |
Interesting issue 👍 |
By extending Sinatra::Error, an error class can set the http status code on the response to a value other than 500. This commit fixes issues sinatra#1204 and sinatra#1518 where an error raised by a third party library that responded to http_status could set the status on the response. Any error outside of Sinatra errors will now always return a 500 status. This fixes an issue where an exception could leak sensitive data in the message to the browser. Errors that have http_status code 400 or 404 use the message as the body of the response. This is why it is imperative that these errors extend Sinatra::Error so that this is an explicit decision.
By extending Sinatra::Error, an error class can set the http status code on the response to a value other than 500. This commit fixes issues sinatra#1204 and sinatra#1518 where an error raised by a third party library that responded to http_status could set the status on the response. Any error outside of Sinatra errors will now always return a 500 status. This fixes an issue where an exception could leak sensitive data in the message to the browser. Errors that have http_status code 400 or 404 use the message as the body of the response. This is why it is imperative that these errors extend Sinatra::Error so that this is an explicit decision.
By extending Sinatra::Error, an error class can set the http status code on the response to a value other than 500. This commit fixes issues sinatra#1204 and sinatra#1518 where an error raised by a third party library that responded to http_status could set the status on the response. Any error outside of Sinatra errors will now always return a 500 status. This fixes an issue where an exception could leak sensitive data in the message to the browser. Errors that have http_status code 400 or 404 use the message as the body of the response. This is why it is imperative that these errors extend Sinatra::Error so that this is an explicit decision.
By extending Sinatra::Error, an error class can set the http status code on the response to a value other than 500. This commit fixes issues sinatra#1204 and sinatra#1518 where an error raised by a third party library that responded to http_status could set the status on the response. Any error outside of Sinatra errors will now always return a 500 status. This fixes an issue where an exception could leak sensitive data in the message to the browser. Errors that have http_status code 400 or 404 use the message as the body of the response. This is why it is imperative that these errors extend Sinatra::Error so that this is an explicit decision.
By extending Sinatra::Error, an error class can set the http status code on the response to a value other than 500. This commit fixes issues #1204 and #1518 where an error raised by a third party library that responded to http_status could set the status on the response. Any error outside of Sinatra errors will now always return a 500 status. This fixes an issue where an exception could leak sensitive data in the message to the browser. Errors that have http_status code 400 or 404 use the message as the body of the response. This is why it is imperative that these errors extend Sinatra::Error so that this is an explicit decision.
Closed by #1519. Will be released in v3.0. |
By extending Sinatra::Error, an error class can set the http status code on the response to a value other than 500. This commit fixes issues #1204 and #1518 where an error raised by a third party library that responded to http_status could set the status on the response. Any error outside of Sinatra errors will now always return a 500 status. This fixes an issue where an exception could leak sensitive data in the message to the browser. Errors that have http_status code 400 or 404 use the message as the body of the response. This is why it is imperative that these errors extend Sinatra::Error so that this is an explicit decision.
This is fundamentally the same issue as #1204. However, I think I have a clearer explanation of what's happening, including an easily-reproduced example. I also think the bug is a serious security problem and want to make that clear.
First, Stripe's errors have an
http_status
attribute. This attribute represents the status code returned by Stripe's servers. For example, here you can seeStripe::InvalidRequestError
taking anhttp_status
argument, which is 400 when the error is actually raised.In our application, we were seeing this error raised for correct reasons (i.e., we had an actual error). But Sinatra will treat any exception with an
http_status
attribute as a Sinatra-level error that should be translated into that HTTP status code.Note that the Sinatra code above does not respond to any configuration option. As far as I can tell, this problem exists regardless of how Sinatra is configured.
By these two code snippets' powers combined:
http_status
attribute and incorrectly thinks that this exception is actually a Sinatra exception.You can reproduce this yourself by installing the "stripe" and "sinatra" gems and running this single-file Sinatra app. Go to
localhost:4567/error_test
and you'll see the "sensitive information from stripe" string leaked to the end user.The text was updated successfully, but these errors were encountered: